Skip to content

Commit

Permalink
Added Locos reducer and saga tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dcyoung-dev committed Jan 18, 2024
1 parent 851dd01 commit 4c96217
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/__tests__/states/reducers/locos_reducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("Locos reducer", () => {
expect(locosState).toEqual({entities: {}})
})

it("adds a Loco on UPDATE_POWER_STATE", () => {
it("adds a Loco on ADD_OR_UPDATE_LOCO", () => {
const action = addOrUpdateLoco({cabId: 1, name: 'test'})
const locosState = rostersReducer(undefined, action)

Expand All @@ -50,7 +50,8 @@ describe("Locos reducer", () => {
expect(locosState).toEqual({entities: {1: expectedLoco}})
})

it("updates an existing Loco on UPDATE_POWER_STATE", () => {
// FIXME: Test updating FunctionButtons and Throttle using ADD_OR_UPDATE_LOCO
it("updates an existing Loco on ADD_OR_UPDATE_LOCO", () => {
const initialLoco: Loco = {
cabId: 1,
name: 'Initial Loco',
Expand Down
39 changes: 38 additions & 1 deletion src/__tests__/states/sagas/locos_saga.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {expectSaga} from "redux-saga-test-plan";
import commandSaga from "../../../states/actions";
import {addOrUpdateLoco, newLocoFormSubmit, userPopulateRoster} from "../../../states/actions/locos";
import {commandSend} from "../../../states/actions/commands";
import {commandSend, rosterItemCommandParsed} from "../../../states/actions/commands";
import {FunctionButtonKind, FunctionName, ParserStatus} from "@cloudthrottle/dcc-ex--commands";

describe("User adds a new Loco", () => {
describe("NEW_LOCO_FORM_SUBMIT", () => {
Expand All @@ -24,3 +25,39 @@ describe("User populates Locos from Roster", () => {
})
})
})

describe("Adding a Loco from parsed roster command", () => {
describe("ROSTER_ITEM_COMMAND_PARSED", () => {
it("puts ADD_OR_UPDATE_LOCO", () => {
return expectSaga(commandSaga)
.dispatch(rosterItemCommandParsed(
{
key: 'j',
parser: FunctionName.ROSTER_ITEM,
params: {
cabId: 70,
display: 'My Loco',
functionButtons: {
1: {
display: 'Ring',
kind: FunctionButtonKind.PRESS
}
}
},
status: ParserStatus.SUCCESS
}
))
.put(addOrUpdateLoco({
cabId: 70,
name: 'My Loco',
functionButtons: {
1: {
display: 'Ring',
kind: FunctionButtonKind.PRESS
}
}
})) // tested by locos reducer
.silentRun()
})
})
})

0 comments on commit 4c96217

Please sign in to comment.