fix: 优化任务详情与图片预览布局

This commit is contained in:
2026-08-18 16:41:55 +08:00
parent c34c4e1923
commit 1757ba5e36
3 changed files with 237 additions and 74 deletions
@@ -14,7 +14,7 @@ final class TravelAlbumDetailViewControllerTests: XCTestCase {
let api = TravelAlbumMockAPI()
let source = TravelAlbumAIJobSourceMaterial(
id: 691,
fileName: "IMG_8293.JPG",
fileName: "beauty_1757851944526_这个文件标题特别长用于验证布局不会挤压状态.jpg",
thumbnailURL: ""
)
let failedTarget = TravelAlbumAIJobTarget(
@@ -104,6 +104,42 @@ final class TravelAlbumDetailViewControllerTests: XCTestCase {
XCTAssertTrue(labels.contains("失败原因:AI服务处理超时,请重新修图"))
XCTAssertFalse(labels.contains("去相册处理"))
XCTAssertFalse(labels.contains { $0.contains("VENDOR_TIMEOUT") })
let contentCard = try XCTUnwrap(controller.view.findSubview {
$0.accessibilityIdentifier == "aiRetouchJob.detail.contentCard"
})
let refinedChip = try XCTUnwrap(controller.view.findSubview {
$0.accessibilityIdentifier == "aiRetouchJob.contentChip.refined"
})
let atmosphereChip = try XCTUnwrap(controller.view.findSubview {
$0.accessibilityIdentifier == "aiRetouchJob.contentChip.atmosphere"
})
let coverChip = try XCTUnwrap(controller.view.findSubview {
$0.accessibilityIdentifier == "aiRetouchJob.contentChip.cover"
})
XCTAssertEqual(refinedChip.backgroundColor?.travelAlbumTestHexRGB, 0xEAF3FF)
XCTAssertEqual(atmosphereChip.backgroundColor?.travelAlbumTestHexRGB, 0xFFF2DC)
XCTAssertEqual(coverChip.backgroundColor?.travelAlbumTestHexRGB, 0xF2ECFF)
XCTAssertNil(refinedChip.findSubview { $0 is UIImageView })
XCTAssertNil(atmosphereChip.findSubview { $0 is UIImageView })
XCTAssertNil(coverChip.findSubview { $0 is UIImageView })
XCTAssertGreaterThan(atmosphereChip.bounds.width, refinedChip.bounds.width)
let coverFrame = coverChip.convert(coverChip.bounds, to: contentCard)
XCTAssertLessThan(coverFrame.maxX, contentCard.bounds.maxX - 16)
let titleLabel = try XCTUnwrap(controller.view.findSubview {
$0.accessibilityIdentifier == "aiRetouchJob.target.3.title"
})
let templateLabel = try XCTUnwrap(controller.view.findSubview {
$0.accessibilityIdentifier == "aiRetouchJob.target.3.template"
})
let statusView = try XCTUnwrap(controller.view.findSubview {
$0.accessibilityIdentifier == "aiRetouchJob.target.3.status"
})
let titleFrame = titleLabel.convert(titleLabel.bounds, to: controller.view)
let templateFrame = templateLabel.convert(templateLabel.bounds, to: controller.view)
let statusFrame = statusView.convert(statusView.bounds, to: controller.view)
XCTAssertLessThanOrEqual(titleFrame.maxX, controller.view.bounds.maxX - 18)
XCTAssertGreaterThan(statusFrame.minY, templateFrame.maxY)
XCTAssertLessThanOrEqual(statusFrame.maxX, controller.view.bounds.maxX - 18)
let detailScreenshot = UIGraphicsImageRenderer(bounds: window.bounds).image { context in
window.layer.render(in: context.cgContext)
}
@@ -315,6 +351,56 @@ final class TravelAlbumDetailViewControllerTests: XCTestCase {
XCTAssertEqual(counterContainer.bounds.width - counterLabel.frame.maxX, 12, accuracy: 0.5)
}
func testPreviewAppliesRequestedInitialKindForCoverOnlyProject() throws {
let cover = TravelAlbumPreviewAsset(
id: "cover-897",
kind: .cover,
fileURL: "https://example.com/final.png",
coverURL: "https://example.com/final.png",
fileName: "AI封面",
fileSize: 0
)
let controller = TravelAlbumPhotoPreviewViewController(
projects: [TravelAlbumPreviewProject(originalMaterialId: 897, assets: [cover])],
totalCount: 1,
startProjectIndex: 0,
startKind: .cover,
allowsActions: false
)
controller.loadViewIfNeeded()
controller.view.frame = CGRect(x: 0, y: 0, width: 390, height: 844)
controller.view.layoutIfNeeded()
let highResolutionButton = try XCTUnwrap(
controller.view.findSubview {
$0.accessibilityIdentifier == "travelAlbum.previewHighResolutionButton"
} as? UIButton
)
let loadingIndicator = try XCTUnwrap(
controller.view.findSubview {
$0.accessibilityIdentifier == "travelAlbum.previewLoadingIndicator"
}
)
let activityIndicator = try XCTUnwrap(
loadingIndicator.findSubview { $0 is UIActivityIndicatorView } as? UIActivityIndicatorView
)
let fileSizeLabel = try XCTUnwrap(
controller.view.findSubview {
$0.accessibilityIdentifier == "travelAlbum.previewFileSizeLabel"
} as? UILabel
)
XCTAssertTrue(controller.view.allLabels().contains { $0.text == "AI封面" })
XCTAssertTrue(highResolutionButton.isEnabled)
XCTAssertTrue(fileSizeLabel.isHidden)
XCTAssertNil(fileSizeLabel.text)
XCTAssertEqual(fileSizeLabel.bounds.height, 0, accuracy: 0.5)
XCTAssertEqual(loadingIndicator.bounds.size, CGSize(width: 44, height: 44))
XCTAssertEqual(loadingIndicator.backgroundColor?.travelAlbumTestHexRGB, 0x27272A)
XCTAssertEqual(loadingIndicator.accessibilityLabel, "图片加载中")
XCTAssertEqual(activityIndicator.color.travelAlbumTestHexRGB, 0xFFFFFF)
}
func testPreviewSuccessfulDeletionShowsNextProjectAndPreventsDuplicateRequests() async throws {
let api = TravelAlbumMockAPI()
api.deleteMaterialDelayNanoseconds = 1_000_000