feat: 接通图片预览 AI 修图流程
This commit is contained in:
@@ -352,6 +352,141 @@ final class TravelAlbumDetailViewControllerTests: XCTestCase {
|
||||
XCTAssertEqual(cell.accessibilityValue, "未选择")
|
||||
}
|
||||
|
||||
func testPreviewAIRetouchUsesSelectedRetouchedTabWorkflowAndStaysPresented() async throws {
|
||||
UIView.setAnimationsEnabled(false)
|
||||
defer { UIView.setAnimationsEnabled(true) }
|
||||
let api = TravelAlbumMockAPI()
|
||||
api.aiRetouchTemplatesResponse = TravelAlbumAIRetouchTemplatesResponse(
|
||||
refinedTemplates: [TravelAlbumAIRetouchTemplate(id: 11, name: "清透", previewURL: "")],
|
||||
atmosphereTemplates: [TravelAlbumAIRetouchTemplate(id: 21, name: "暖阳", previewURL: "")]
|
||||
)
|
||||
let project = TravelAlbumPreviewProject(
|
||||
originalMaterialId: 7,
|
||||
aiRetouchBatchId: 70,
|
||||
assets: [
|
||||
TravelAlbumPreviewAsset(
|
||||
id: "original-7",
|
||||
kind: .original,
|
||||
fileURL: "",
|
||||
coverURL: "",
|
||||
fileName: "原图.jpg",
|
||||
fileSize: 0
|
||||
),
|
||||
TravelAlbumPreviewAsset(
|
||||
id: "retouched-7",
|
||||
kind: .retouched,
|
||||
fileURL: "",
|
||||
coverURL: "",
|
||||
fileName: "精修后.jpg",
|
||||
fileSize: 0
|
||||
),
|
||||
]
|
||||
)
|
||||
let controller = TravelAlbumPhotoPreviewViewController(
|
||||
projects: [project],
|
||||
totalCount: 1,
|
||||
startProjectIndex: 0,
|
||||
albumId: 8,
|
||||
scenicIdProvider: { 18 },
|
||||
aiRetouchAPI: api
|
||||
)
|
||||
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 390, height: 844))
|
||||
window.rootViewController = controller
|
||||
window.makeKeyAndVisible()
|
||||
defer { window.isHidden = true }
|
||||
controller.loadViewIfNeeded()
|
||||
controller.view.layoutIfNeeded()
|
||||
|
||||
let retouchedButton = try XCTUnwrap(
|
||||
controller.view.findSubview { ($0 as? UIButton)?.accessibilityLabel == "精修后" } as? UIButton
|
||||
)
|
||||
retouchedButton.sendActions(for: .touchUpInside)
|
||||
let aiButton = try XCTUnwrap(
|
||||
controller.view.findSubview { ($0 as? UIButton)?.accessibilityLabel == "AI修图" } as? UIButton
|
||||
)
|
||||
aiButton.sendActions(for: .touchUpInside)
|
||||
await waitUntil { controller.presentedViewController is TravelAlbumAIRetouchTemplateViewController }
|
||||
let sheet = try XCTUnwrap(controller.presentedViewController as? TravelAlbumAIRetouchTemplateViewController)
|
||||
sheet.loadViewIfNeeded()
|
||||
let confirmButton = try XCTUnwrap(
|
||||
sheet.view.findSubview {
|
||||
$0.accessibilityIdentifier == "travelAlbum.aiRetouchConfirmButton"
|
||||
} as? UIButton
|
||||
)
|
||||
await waitUntil { api.aiRetouchTemplateScenicIds.count == 1 && confirmButton.isEnabled }
|
||||
sheet.view.frame = CGRect(x: 0, y: 0, width: 390, height: 844)
|
||||
sheet.view.layoutIfNeeded()
|
||||
|
||||
let labels = sheet.view.allAccessibilityLabels()
|
||||
XCTAssertTrue(labels.contains("原图精修"))
|
||||
XCTAssertFalse(labels.contains { $0.contains("氛围感修图") })
|
||||
confirmButton.sendActions(for: .touchUpInside)
|
||||
await waitUntil { api.aiReretouchRequests.count == 1 }
|
||||
await waitUntil { controller.presentedViewController == nil }
|
||||
|
||||
XCTAssertEqual(api.aiReretouchRequests.first?.type, .refined)
|
||||
XCTAssertNil(controller.presentedViewController)
|
||||
XCTAssertTrue(window.rootViewController === controller)
|
||||
}
|
||||
|
||||
func testPreviewRefreshPreservesVariantAndFallsBackWhenVariantDisappears() async throws {
|
||||
let original = TravelAlbumPreviewAsset(
|
||||
id: "original-7",
|
||||
kind: .original,
|
||||
fileURL: "",
|
||||
coverURL: "",
|
||||
fileName: "原图.jpg",
|
||||
fileSize: 0
|
||||
)
|
||||
let retouched = TravelAlbumPreviewAsset(
|
||||
id: "retouched-7",
|
||||
kind: .retouched,
|
||||
fileURL: "",
|
||||
coverURL: "",
|
||||
fileName: "精修后.jpg",
|
||||
fileSize: 0
|
||||
)
|
||||
var reloadCount = 0
|
||||
let controller = TravelAlbumPhotoPreviewViewController(
|
||||
projects: [TravelAlbumPreviewProject(originalMaterialId: 7, assets: [original, retouched])],
|
||||
totalCount: 1,
|
||||
startProjectIndex: 0,
|
||||
reload: {
|
||||
reloadCount += 1
|
||||
let assets = reloadCount == 1 ? [original, retouched] : [original]
|
||||
return ([TravelAlbumPreviewProject(originalMaterialId: 7, assets: assets)], 1)
|
||||
}
|
||||
)
|
||||
controller.loadViewIfNeeded()
|
||||
controller.view.frame = CGRect(x: 0, y: 0, width: 390, height: 844)
|
||||
controller.view.layoutIfNeeded()
|
||||
let retouchedButton = try XCTUnwrap(
|
||||
controller.view.findSubview { ($0 as? UIButton)?.accessibilityLabel == "精修后" } as? UIButton
|
||||
)
|
||||
retouchedButton.sendActions(for: .touchUpInside)
|
||||
let refreshButton = try XCTUnwrap(
|
||||
controller.view.findSubview {
|
||||
$0.accessibilityIdentifier == "travelAlbum.previewRefreshButton"
|
||||
} as? UIButton
|
||||
)
|
||||
|
||||
refreshButton.sendActions(for: .touchUpInside)
|
||||
await waitUntil { reloadCount == 1 && refreshButton.isEnabled }
|
||||
XCTAssertTrue(
|
||||
controller.view.findSubview {
|
||||
($0 as? UIButton)?.accessibilityLabel == "精修后"
|
||||
&& $0.accessibilityTraits.contains(.selected)
|
||||
} != nil
|
||||
)
|
||||
|
||||
refreshButton.sendActions(for: .touchUpInside)
|
||||
await waitUntil { reloadCount == 2 && refreshButton.isEnabled }
|
||||
XCTAssertNil(
|
||||
controller.view.findSubview { ($0 as? UIButton)?.accessibilityLabel == "精修后" }
|
||||
)
|
||||
XCTAssertTrue(controller.view.allLabels().contains { $0.text == "原图.jpg" })
|
||||
}
|
||||
|
||||
func testMaterialCellShowsSemanticStatusBadgeWithoutOverlappingSelectionCheck() throws {
|
||||
let cases: [(TravelAlbumMaterial, String, UInt)] = [
|
||||
(TravelAlbumMaterial(isPurchased: true), "已购", 0x475569),
|
||||
|
||||
Reference in New Issue
Block a user