diff --git a/SwiftGoal/ViewModels/MatchesViewModel.swift b/SwiftGoal/ViewModels/MatchesViewModel.swift index b2a2906..7e185dd 100644 --- a/SwiftGoal/ViewModels/MatchesViewModel.swift +++ b/SwiftGoal/ViewModels/MatchesViewModel.swift @@ -18,7 +18,7 @@ public class MatchesViewModel { public let title: String public let contentChangesSignal: Signal public let isLoading: MutableProperty - let alertMessageSignal: Signal + public let alertMessageSignal: Signal // Actions public lazy var deleteAction: Action = { [unowned self] in diff --git a/SwiftGoalTests/MockStore.swift b/SwiftGoalTests/MockStore.swift index e3eec97..d266c31 100644 --- a/SwiftGoalTests/MockStore.swift +++ b/SwiftGoalTests/MockStore.swift @@ -12,7 +12,7 @@ import SwiftGoal class MockStore: Store { let players: [Player] - let matches: [Match] + var matches: [Match]? // nil is used to cause error var didFetchMatches = false var deletedMatch: Match? @@ -46,7 +46,12 @@ class MockStore: Store { override func fetchMatches() -> SignalProducer<[Match], NSError> { didFetchMatches = true - return SignalProducer(value: matches) + if let matches = self.matches { + return SignalProducer(value: matches) + } else { + let error = NSError(domain: "", code: 0, userInfo: nil) + return SignalProducer(error: error) + } } override func deleteMatch(match: Match) -> SignalProducer { diff --git a/SwiftGoalTests/ViewModels/MatchesViewModelSpec.swift b/SwiftGoalTests/ViewModels/MatchesViewModelSpec.swift index 59a5e40..4832976 100644 --- a/SwiftGoalTests/ViewModels/MatchesViewModelSpec.swift +++ b/SwiftGoalTests/ViewModels/MatchesViewModelSpec.swift @@ -113,8 +113,21 @@ class MatchesViewModelSpec: QuickSpec { } } + it("raises an alert when matches cannot be fetched") { + mockStore.matches = nil // will cause fetch error + + var didRaiseAlert = false + matchesViewModel.alertMessageSignal.observe(next: { alertMessage in + didRaiseAlert = true + }) + + matchesViewModel.active.put(true) + + expect(didRaiseAlert).to(beTrue()) + } + it("deletes the correct match when asked to") { - let match = mockStore.matches[1] + let match = mockStore.matches![1] let indexPath = NSIndexPath(forRow: 1, inSection: 0) var deletedSuccessfully = false