修复 OTG 列表删除照片后边拍边传仍会带回已删项的问题。
删除时同步清理管道任务并维护 excludedAssetIDs,避免 notify 将无本地文件的旧任务重新展示为仅文件名的待上传项。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -202,6 +202,37 @@ final class CameraTransferPipelineTests: XCTestCase {
|
||||
XCTAssertEqual(camera.shutdownCount, 0)
|
||||
}
|
||||
|
||||
/// 测试删除后管道不会在新片 notify 时再次带回已删 asset。
|
||||
func testRemovedAssetStaysExcludedWhenNewAssetArrives() async throws {
|
||||
let camera = MockCameraService()
|
||||
let pipeline = CameraTransferPipeline(cameraService: camera)
|
||||
let scope = makeScope("removed_asset")
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
pipeline.configure(uploadSink: nil, uploadEnabled: false, downloadScope: scope)
|
||||
attachPipeline(pipeline)
|
||||
|
||||
let oldURL = FileManager.default.temporaryDirectory.appendingPathComponent("OLD.JPG")
|
||||
let newURL = FileManager.default.temporaryDirectory.appendingPathComponent("NEW.JPG")
|
||||
try Data(repeating: 0x01, count: 8).write(to: oldURL)
|
||||
try Data(repeating: 0x02, count: 8).write(to: newURL)
|
||||
defer {
|
||||
try? FileManager.default.removeItem(at: oldURL)
|
||||
try? FileManager.default.removeItem(at: newURL)
|
||||
}
|
||||
|
||||
camera.onNewAsset?(CameraAsset(id: "ptp_old", filename: "OLD.JPG", fileSize: 8))
|
||||
try await Task.sleep(nanoseconds: 300_000_000)
|
||||
pipeline.removeAsset(assetID: "ptp_old")
|
||||
XCTAssertNil(pipeline.task(forAssetID: "ptp_old"))
|
||||
|
||||
camera.onNewAsset?(CameraAsset(id: "ptp_new", filename: "NEW.JPG", fileSize: 8))
|
||||
try await Task.sleep(nanoseconds: 300_000_000)
|
||||
|
||||
XCTAssertNil(pipeline.task(forAssetID: "ptp_old"))
|
||||
XCTAssertNotNil(pipeline.task(forAssetID: "ptp_new"))
|
||||
XCTAssertTrue(pipeline.excludedAssetIDs.contains("ptp_old"))
|
||||
}
|
||||
|
||||
private func attachPipeline(
|
||||
_ pipeline: CameraTransferPipeline,
|
||||
onTasksUpdated: @escaping ([CameraTransferTask]) -> Void = { _ in }
|
||||
|
||||
@ -46,6 +46,58 @@ final class WiredCameraTransferViewModelTests: XCTestCase {
|
||||
XCTAssertEqual(viewModel.photos.first?.fileName, "DSC_NEW.JPG")
|
||||
}
|
||||
|
||||
/// 测试删除待上传照片后,边拍边传新片不会把已删照片带回列表。
|
||||
func testDeletedPendingPhotoDoesNotReappearAfterLiveCapture() async throws {
|
||||
let camera = MockWiredCameraService()
|
||||
let context = WiredTransferContext(
|
||||
albumId: 7701,
|
||||
albumName: "删除回归测试",
|
||||
phone: "",
|
||||
orderNumber: ""
|
||||
)
|
||||
let viewModel = WiredCameraTransferViewModel(context: context, cameraService: camera)
|
||||
let account = AccountContext()
|
||||
account.applyLogin(profile: AccountProfile(userId: "101", displayName: "测试"))
|
||||
|
||||
await viewModel.start(
|
||||
api: MockTravelAlbumAPIForWiredTransfer(),
|
||||
ossService: WiredTransferMockOSSUploadService(),
|
||||
scenicID: 1,
|
||||
accountContext: account
|
||||
)
|
||||
|
||||
let oldURL = FileManager.default.temporaryDirectory.appendingPathComponent("OLD_DELETE.JPG")
|
||||
try Data(repeating: 0x11, count: 16).write(to: oldURL)
|
||||
defer { try? FileManager.default.removeItem(at: oldURL) }
|
||||
|
||||
camera.downloadURL = oldURL
|
||||
camera.onNewAsset?(CameraAsset(id: "ptp_delete_me", filename: "OLD_DELETE.JPG", fileSize: 16))
|
||||
try await Task.sleep(nanoseconds: 500_000_000)
|
||||
XCTAssertEqual(viewModel.photos.count, 1)
|
||||
|
||||
viewModel.deletePhoto(id: "ptp_delete_me")
|
||||
XCTAssertTrue(viewModel.photos.isEmpty)
|
||||
|
||||
viewModel.selectTransferMode(
|
||||
WiredCameraTransferViewModel.modeLiveCapture,
|
||||
api: MockTravelAlbumAPIForWiredTransfer(),
|
||||
ossService: WiredTransferMockOSSUploadService(),
|
||||
scenicID: 1
|
||||
)
|
||||
|
||||
let newURL = FileManager.default.temporaryDirectory.appendingPathComponent("NEW_LIVE.JPG")
|
||||
try Data(repeating: 0x22, count: 16).write(to: newURL)
|
||||
defer { try? FileManager.default.removeItem(at: newURL) }
|
||||
|
||||
camera.downloadURL = newURL
|
||||
camera.onNewAsset?(CameraAsset(id: "ptp_live_new", filename: "NEW_LIVE.JPG", fileSize: 16))
|
||||
try await Task.sleep(nanoseconds: 500_000_000)
|
||||
|
||||
XCTAssertEqual(viewModel.photos.count, 1)
|
||||
XCTAssertEqual(viewModel.photos.first?.id, "ptp_live_new")
|
||||
XCTAssertFalse(viewModel.photos.contains { $0.id == "ptp_delete_me" })
|
||||
}
|
||||
|
||||
/// 测试 start 被取消时 detach UI 回调,但不 shutdown 相机连接。
|
||||
func testStartCancellationDetachesWithoutShutdown() async {
|
||||
let camera = DisconnectTrackingWiredCameraService()
|
||||
|
||||
Reference in New Issue
Block a user