-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some tests for EditMatchViewModel
- Loading branch information
Martin Richter
committed
Aug 10, 2015
1 parent
ff0a132
commit 479415b
Showing
6 changed files
with
99 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// EditMatchViewModelSpec.swift | ||
// SwiftGoal | ||
// | ||
// Created by Martin Richter on 09/08/15. | ||
// Copyright (c) 2015 Martin Richter. All rights reserved. | ||
// | ||
|
||
import Quick | ||
import Nimble | ||
import ReactiveCocoa | ||
import SwiftGoal | ||
|
||
class EditMatchViewModelSpec: QuickSpec { | ||
override func spec() { | ||
describe("EditMatchViewModel") { | ||
var mockStore: MockStore! | ||
var viewModel: EditMatchViewModel! | ||
|
||
context("when initialized without an existing match") { | ||
beforeEach { | ||
mockStore = MockStore() | ||
viewModel = EditMatchViewModel(store: mockStore) | ||
} | ||
|
||
it("has the correct title") { | ||
expect(viewModel.title).to(equal("New Match")) | ||
} | ||
|
||
it("formats the home goals correctly") { | ||
viewModel.homeGoals.put(1) | ||
expect(viewModel.formattedHomeGoals.value).to(equal("1")) | ||
} | ||
|
||
it("formats the away goals correctly") { | ||
viewModel.awayGoals.put(1) | ||
expect(viewModel.formattedAwayGoals.value).to(equal("1")) | ||
} | ||
|
||
describe("validation") { | ||
it("fails initially") { | ||
expect(viewModel.inputIsValid.value).to(beFalse()) | ||
} | ||
|
||
it("fails when there are no home players") { | ||
let awayPlayersViewModel = viewModel.manageAwayPlayersViewModel() | ||
let awayPlayerIndexPath = NSIndexPath(forRow: 1, inSection: 0) | ||
awayPlayersViewModel.active.put(true) | ||
awayPlayersViewModel.selectPlayerAtIndexPath(awayPlayerIndexPath) | ||
|
||
expect(viewModel.inputIsValid.value).to(beFalse()) | ||
} | ||
|
||
it("fails when there are no away players") { | ||
let homePlayersViewModel = viewModel.manageHomePlayersViewModel() | ||
let homePlayerIndexPath = NSIndexPath(forRow: 0, inSection: 0) | ||
homePlayersViewModel.active.put(true) | ||
homePlayersViewModel.selectPlayerAtIndexPath(homePlayerIndexPath) | ||
|
||
expect(viewModel.inputIsValid.value).to(beFalse()) | ||
} | ||
|
||
it("passes when there are both home and away players") { | ||
let homePlayersViewModel = viewModel.manageHomePlayersViewModel() | ||
let homePlayerIndexPath = NSIndexPath(forRow: 0, inSection: 0) | ||
homePlayersViewModel.active.put(true) | ||
homePlayersViewModel.selectPlayerAtIndexPath(homePlayerIndexPath) | ||
|
||
let awayPlayersViewModel = viewModel.manageAwayPlayersViewModel() | ||
let awayPlayerIndexPath = NSIndexPath(forRow: 1, inSection: 0) | ||
awayPlayersViewModel.active.put(true) | ||
awayPlayersViewModel.selectPlayerAtIndexPath(awayPlayerIndexPath) | ||
|
||
expect(viewModel.inputIsValid.value).to(beTrue()) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |