fix: Resolve all audit issues from project readiness review
Blockers: - IYmtgTests: replace ScannerViewModel() (no-arg init removed) with CollectionViewModel() in testViewModelFiltering and testPortfolioCalculation - IYmtgTests: fix property access — scannedList, librarySearchText, filteredList, portfolioValue all live on CollectionViewModel, not ScannerViewModel; inject test data after async init settles Major: - ContentView: update .onChange(of:) to two-parameter closure syntax (iOS 17 deprecation) - ModelManager: add missing import FirebaseCore so FirebaseApp.app() resolves explicitly - CollectionViewModel.deleteCard: call CloudEngine.delete(card:) to remove Firebase entry when a card is deleted (prevents data accumulation) - CloudEngine: remove never-called batchUpdatePrices() — full backup already handled by backupAllToFirebase() Minor: - CardDetailView: move to Features/CardDetail/CardDetailView.swift; remove from ContentView.swift - Delete PersistenceActor.swift placeholder (superseded by PersistenceController.swift) - AppConfig.validate(): broaden placeholder-email guard to catch empty strings and common fake domains - ModelManager: document OTA restart requirement in code comment Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -107,43 +107,46 @@ final class IYmtgTests: XCTestCase {
|
||||
}
|
||||
|
||||
// MARK: - ViewModel Logic Tests
|
||||
|
||||
// CollectionViewModel owns filtering and portfolio logic; tests target it directly.
|
||||
|
||||
@MainActor
|
||||
func testViewModelFiltering() {
|
||||
let vm = ScannerViewModel()
|
||||
|
||||
let vm = CollectionViewModel()
|
||||
|
||||
let card1 = SavedCard(from: CardMetadata(id: UUID(), name: "Alpha", setCode: "A", collectorNumber: "1", hasFoilPrinting: false, hasSerializedPrinting: false, priceScanned: 100), imageName: "1", collection: "Master Collection", location: "Box")
|
||||
let card2 = SavedCard(from: CardMetadata(id: UUID(), name: "Beta", setCode: "B", collectorNumber: "2", hasFoilPrinting: false, hasSerializedPrinting: false, priceScanned: 200), imageName: "2", collection: "Master Collection", location: "Box")
|
||||
|
||||
vm.scannedList = [card1, card2]
|
||||
|
||||
// Test Search
|
||||
vm.librarySearchText = "Alpha"
|
||||
|
||||
// Wait for async recalc
|
||||
|
||||
// Inject test data after the async SwiftData init load has completed.
|
||||
let expectation = XCTestExpectation(description: "Filter updates")
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
XCTAssertEqual(vm.filteredList.count, 1)
|
||||
XCTAssertEqual(vm.filteredList.first?.name, "Alpha")
|
||||
expectation.fulfill()
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
||||
vm.scannedList = [card1, card2]
|
||||
vm.librarySearchText = "Alpha"
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
XCTAssertEqual(vm.filteredList.count, 1)
|
||||
XCTAssertEqual(vm.filteredList.first?.name, "Alpha")
|
||||
expectation.fulfill()
|
||||
}
|
||||
}
|
||||
|
||||
wait(for: [expectation], timeout: 1.0)
|
||||
|
||||
wait(for: [expectation], timeout: 2.0)
|
||||
}
|
||||
|
||||
|
||||
@MainActor
|
||||
func testPortfolioCalculation() {
|
||||
let vm = ScannerViewModel()
|
||||
let vm = CollectionViewModel()
|
||||
let card1 = SavedCard(from: CardMetadata(id: UUID(), name: "A", setCode: "A", collectorNumber: "1", hasFoilPrinting: false, hasSerializedPrinting: false, priceScanned: 50.0), imageName: "1", collection: "Master Collection", location: "Box")
|
||||
let card2 = SavedCard(from: CardMetadata(id: UUID(), name: "B", setCode: "B", collectorNumber: "2", hasFoilPrinting: false, hasSerializedPrinting: false, priceScanned: 150.0), imageName: "2", collection: "Master Collection", location: "Box")
|
||||
|
||||
vm.scannedList = [card1, card2]
|
||||
|
||||
|
||||
let expectation = XCTestExpectation(description: "Stats update")
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
XCTAssertEqual(vm.portfolioValue, 200.0)
|
||||
expectation.fulfill()
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
||||
vm.scannedList = [card1, card2]
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
XCTAssertEqual(vm.portfolioValue, 200.0)
|
||||
expectation.fulfill()
|
||||
}
|
||||
}
|
||||
wait(for: [expectation], timeout: 1.0)
|
||||
wait(for: [expectation], timeout: 2.0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user