-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a23a574
commit 851dd01
Showing
2 changed files
with
105 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import {rostersReducer} from "../../../states/reducers/locos_reducer"; | ||
import {addOrUpdateLoco} from "../../../states/actions/locos"; | ||
import {Loco, LocosState} from "../../../types"; | ||
import {userResetState} from "../../../states/actions/stores"; | ||
|
||
describe("Locos reducer", () => { | ||
it("has initial state", () => { | ||
const locosState = rostersReducer(undefined, {type: 'INIT'}) | ||
|
||
expect(locosState).toEqual({entities: {}}) | ||
}) | ||
|
||
it("resets all state on USER_RESET_STATE", () => { | ||
const action = userResetState() | ||
const initialLoco: Loco = { | ||
cabId: 1, | ||
name: 'Initial Loco', | ||
throttle: {direction: 1, speed: 0}, | ||
functionButtons: {}, | ||
sync: { | ||
rosterItemAt: null, | ||
rosterListAt: null | ||
}, | ||
id: "", | ||
} | ||
|
||
const initialState: LocosState = { | ||
entities: { | ||
1: initialLoco | ||
} | ||
} | ||
const locosState = rostersReducer(initialState, action) | ||
|
||
expect(locosState).toEqual({entities: {}}) | ||
}) | ||
|
||
it("adds a Loco on UPDATE_POWER_STATE", () => { | ||
const action = addOrUpdateLoco({cabId: 1, name: 'test'}) | ||
const locosState = rostersReducer(undefined, action) | ||
|
||
const expectedLoco = { | ||
cabId: 1, | ||
name: 'test', | ||
throttle: expect.any(Object), | ||
sync: expect.any(Object), | ||
functionButtons: expect.any(Object), | ||
id: expect.any(String), | ||
} | ||
|
||
expect(locosState).toEqual({entities: {1: expectedLoco}}) | ||
}) | ||
|
||
it("updates an existing Loco on UPDATE_POWER_STATE", () => { | ||
const initialLoco: Loco = { | ||
cabId: 1, | ||
name: 'Initial Loco', | ||
throttle: {direction: 1, speed: 0}, | ||
functionButtons: {}, | ||
sync: { | ||
rosterItemAt: null, | ||
rosterListAt: null | ||
}, | ||
id: "", | ||
} | ||
|
||
const initialState: LocosState = { | ||
entities: { | ||
1: initialLoco | ||
} | ||
} | ||
|
||
const updatedLoco = { | ||
cabId: 1, | ||
name: 'Updated Loco', | ||
} | ||
|
||
const action = addOrUpdateLoco(updatedLoco) | ||
const locosState = rostersReducer(initialState, action) | ||
|
||
const expectedLoco = { | ||
cabId: 1, | ||
name: 'Updated Loco', | ||
throttle: expect.any(Object), | ||
sync: expect.any(Object), | ||
functionButtons: expect.any(Object), | ||
id: expect.any(String), | ||
} | ||
|
||
expect(locosState).toEqual({entities: {1: expectedLoco}}) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,14 +1,26 @@ | ||
import {expectSaga} from "redux-saga-test-plan"; | ||
import commandSaga from "../../../states/actions"; | ||
import {addOrUpdateLoco, newLocoFormSubmit} from "../../../states/actions/locos"; | ||
import {addOrUpdateLoco, newLocoFormSubmit, userPopulateRoster} from "../../../states/actions/locos"; | ||
import {commandSend} from "../../../states/actions/commands"; | ||
|
||
describe("User adds a new Loco", () => { | ||
describe("NEW_LOCO_FORM_SUBMIT", () => { | ||
it("puts ADD_OR_UPDATE_LOCO", () => { | ||
return expectSaga(commandSaga) | ||
.dispatch(newLocoFormSubmit({cabId: 1, name: 'test'})) | ||
.put(addOrUpdateLoco({cabId: 1, name: 'test'})) | ||
.put(addOrUpdateLoco({cabId: 1, name: 'test'})) // tested by locos reducer | ||
.silentRun(); | ||
}); | ||
}); | ||
}) | ||
|
||
describe("User populates Locos from Roster", () => { | ||
describe("USER_POPULATE_ROSTER", () => { | ||
it("puts COMMAND_SEND <J>", () => { | ||
return expectSaga(commandSaga) | ||
.dispatch(userPopulateRoster()) | ||
.put(commandSend("<J>")) | ||
.silentRun() | ||
}) | ||
}) | ||
}) |