feat: 接通图片预览 AI 修图流程
This commit is contained in:
@@ -206,6 +206,41 @@ final class TravelAlbumDetailViewModelTests: XCTestCase {
|
||||
XCTAssertEqual(viewModel.purchasedPhotoCount, 0)
|
||||
}
|
||||
|
||||
func testPreviewReloadRefetchesAllLoadedPagesAndReplacesMaterialsById() async throws {
|
||||
let api = TravelAlbumMockAPI()
|
||||
api.materialListResponses = [
|
||||
TravelAlbumListResponse(
|
||||
total: 35,
|
||||
list: (1 ... 30).map { TravelAlbumMaterial(id: $0) }
|
||||
),
|
||||
TravelAlbumListResponse(
|
||||
total: 35,
|
||||
list: (31 ... 35).map { TravelAlbumMaterial(id: $0) }
|
||||
),
|
||||
TravelAlbumListResponse(
|
||||
total: 35,
|
||||
list: (1 ... 30).map {
|
||||
TravelAlbumMaterial(id: $0, aiRetouchBatchId: $0 == 7 ? 700 : 0)
|
||||
}
|
||||
),
|
||||
TravelAlbumListResponse(
|
||||
total: 35,
|
||||
list: (31 ... 35).map { TravelAlbumMaterial(id: $0) }
|
||||
),
|
||||
]
|
||||
let viewModel = TravelAlbumDetailViewModel(albumId: 2)
|
||||
await viewModel.loadMaterials(reset: true, api: api)
|
||||
await viewModel.loadMaterials(reset: false, api: api)
|
||||
|
||||
let response = try await viewModel.reloadLoadedMaterials(api: api)
|
||||
|
||||
XCTAssertEqual(response.total, 35)
|
||||
XCTAssertEqual(response.list.count, 35)
|
||||
XCTAssertEqual(response.list.first { $0.id == 7 }?.aiRetouchBatchId, 700)
|
||||
XCTAssertEqual(api.materialRequests.suffix(2).map(\.page), [1, 2])
|
||||
XCTAssertEqual(api.materialRequests.suffix(2).map(\.pageSize), [30, 30])
|
||||
}
|
||||
|
||||
func testDeleteAlbumCallsCallback() async {
|
||||
let api = TravelAlbumMockAPI()
|
||||
let viewModel = TravelAlbumDetailViewModel(albumId: 5)
|
||||
@@ -1053,6 +1088,8 @@ final class TravelAlbumMockAPI: TravelAlbumServing {
|
||||
var aiRetouchTemplatesError: Error?
|
||||
var submitAIRetouchError: Error?
|
||||
var submitAIRetouchDelayNanoseconds: UInt64 = 0
|
||||
var submitAIReretouchError: Error?
|
||||
var submitAIReretouchDelayNanoseconds: UInt64 = 0
|
||||
var deleteMaterialError: Error?
|
||||
var deleteMaterialDelayNanoseconds: UInt64 = 0
|
||||
|
||||
@@ -1065,6 +1102,7 @@ final class TravelAlbumMockAPI: TravelAlbumServing {
|
||||
private(set) var deletedMaterialIds: [Int] = []
|
||||
private(set) var aiRetouchTemplateScenicIds: [Int] = []
|
||||
private(set) var aiRetouchRequests: [TravelAlbumAIRetouchRequest] = []
|
||||
private(set) var aiReretouchRequests: [TravelAlbumAIReretouchRequest] = []
|
||||
|
||||
func availableOrders() async throws -> [TravelAlbumAvailableOrder] {
|
||||
availableOrdersCallCount += 1
|
||||
@@ -1148,4 +1186,12 @@ final class TravelAlbumMockAPI: TravelAlbumServing {
|
||||
}
|
||||
if let submitAIRetouchError { throw submitAIRetouchError }
|
||||
}
|
||||
|
||||
func submitAIReretouch(_ request: TravelAlbumAIReretouchRequest) async throws {
|
||||
aiReretouchRequests.append(request)
|
||||
if submitAIReretouchDelayNanoseconds > 0 {
|
||||
try await Task.sleep(nanoseconds: submitAIReretouchDelayNanoseconds)
|
||||
}
|
||||
if let submitAIReretouchError { throw submitAIReretouchError }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user