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]) } }