Fixes ~95 issues from deep audit across 12 categories in 82 files: - Crash prevention: double-resume in PhotoMetadataExtractor, force unwraps in DateRangePicker, array bounds checks in polls/achievements, ProGate hit-test bypass, Dictionary(uniqueKeysWithValues:) → uniquingKeysWith in 4 files - Silent failure elimination: all 34 try? sites replaced with do/try/catch + logging (SavedTrip, TripDetailView, CanonicalSyncService, BootstrapService, CanonicalModels, CKModels, SportsTimeApp, and more) - Performance: cached DateFormatters (7 files), O(1) team lookups via AppDataProvider, achievement definition dictionary, AnimatedBackground consolidated from 19 Tasks to 1, task cancellation in SharePreviewView - Concurrency: UIKit drawing → MainActor.run, background fetch timeout guard, @MainActor on ThemeManager/AppearanceManager, SyncLogger read/write race fix - Planning engine: game end time in travel feasibility, state-aware city normalization, exact city matching, DrivingConstraints parameter propagation - IAP: unknown subscription states → expired, unverified transaction logging, entitlements updated before paywall dismiss, restore visible to all users - Security: API key to Info.plist lookup, filename sanitization in PDF export, honest User-Agent, removed stale "Feels" analytics super properties - Navigation: consolidated competing navigationDestination, boolean → value-based - Testing: 8 sleep() → waitForExistence, duplicates extracted, Swift 6 compat - Service bugs: infinite retry cap, duplicate achievement prevention, TOCTOU vote fix, PollVote.odg → voterId rename, deterministic placeholder IDs, parallel MKDirections, Sendable-safe POI struct Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
72 lines
1.9 KiB
Swift
72 lines
1.9 KiB
Swift
import Testing
|
|
import Foundation
|
|
@testable import SportsTime
|
|
|
|
@Suite("PollVotingViewModel")
|
|
@MainActor
|
|
struct PollVotingViewModelTests {
|
|
|
|
@Test("initializeRankings defaults to original trip order")
|
|
func initializeRankings_defaultOrder() {
|
|
let viewModel = PollVotingViewModel()
|
|
|
|
viewModel.initializeRankings(tripCount: 5, existingVote: nil)
|
|
|
|
#expect(viewModel.rankings == [0, 1, 2, 3, 4])
|
|
}
|
|
|
|
@Test("initializeRankings uses existing vote order")
|
|
func initializeRankings_existingVoteOrder() {
|
|
let viewModel = PollVotingViewModel()
|
|
let existingVote = PollVote(
|
|
pollId: UUID(),
|
|
voterId: "user_123",
|
|
rankings: [2, 0, 3, 1]
|
|
)
|
|
|
|
viewModel.initializeRankings(tripCount: 4, existingVote: existingVote)
|
|
|
|
#expect(viewModel.rankings == [2, 0, 3, 1])
|
|
}
|
|
|
|
@Test("moveTripUp swaps with previous item")
|
|
func moveTripUp_swapsWithPrevious() {
|
|
let viewModel = PollVotingViewModel()
|
|
viewModel.rankings = [0, 1, 2, 3]
|
|
|
|
viewModel.moveTripUp(at: 2)
|
|
|
|
#expect(viewModel.rankings == [0, 2, 1, 3])
|
|
}
|
|
|
|
@Test("moveTripDown swaps with next item")
|
|
func moveTripDown_swapsWithNext() {
|
|
let viewModel = PollVotingViewModel()
|
|
viewModel.rankings = [0, 1, 2, 3]
|
|
|
|
viewModel.moveTripDown(at: 1)
|
|
|
|
#expect(viewModel.rankings == [0, 2, 1, 3])
|
|
}
|
|
|
|
@Test("moveTripUp is no-op at first index")
|
|
func moveTripUp_firstIndexNoOp() {
|
|
let viewModel = PollVotingViewModel()
|
|
viewModel.rankings = [0, 1, 2]
|
|
|
|
viewModel.moveTripUp(at: 0)
|
|
|
|
#expect(viewModel.rankings == [0, 1, 2])
|
|
}
|
|
|
|
@Test("moveTripDown is no-op at last index")
|
|
func moveTripDown_lastIndexNoOp() {
|
|
let viewModel = PollVotingViewModel()
|
|
viewModel.rankings = [0, 1, 2]
|
|
|
|
viewModel.moveTripDown(at: 2)
|
|
|
|
#expect(viewModel.rankings == [0, 1, 2])
|
|
}
|
|
}
|