-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
4 changed files
with
94 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
export const adminActionEnums = { | ||
GET_SUMMARY_TRAINING_REQUEST_COMPLETED: 'GET_SUMMARY_TRAINING_REQUEST_COMPLETED', | ||
GET_SUMMARY_TRAINING_REQUEST_COMPLETED: 'GET_SUMMARY_TRAINING_REQUEST_COMPLETED', | ||
GET_TRAINING_REQUEST_COMPLETED: 'GET_TRAINING_REQUEST_COMPLETED', | ||
} |
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,27 @@ | ||
import { Action } from 'redux'; | ||
import { TrainingEntity } from '../model/training'; | ||
import { adminActionEnums} from '../common/actionEnums/admin'; | ||
|
||
|
||
export class AdminTrainingState { | ||
editTraining : TrainingEntity; | ||
|
||
public constructor() { | ||
this.editTraining = new TrainingEntity(); | ||
} | ||
} | ||
|
||
export const adminTrainingReducer = (state : AdminTrainingState = new AdminTrainingState(), action) => { | ||
switch(action.type) { | ||
case adminActionEnums.GET_TRAINING_REQUEST_COMPLETED: | ||
return handleGetTrainingRequestCompleted(state, action.payload); | ||
} | ||
|
||
return state; | ||
} | ||
|
||
const handleGetTrainingRequestCompleted = | ||
(state : AdminTrainingState, payload : TrainingEntity) => { | ||
const newState = Object.assign({}, state, {editTraining: payload}); | ||
return newState; | ||
} |
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,62 @@ | ||
import { expect } from 'chai'; | ||
import * as deepFreeze from 'deep-freeze'; | ||
import {} from 'mocha' | ||
import {} from 'core-js' | ||
import { adminTrainingReducer, AdminTrainingState } from '../adminTraining'; | ||
import { TrainingEntity } from '../../model/training' | ||
import { Student } from '../../model/student' | ||
import { Trainer } from '../../model/trainer' | ||
import {adminActionEnums} from '../../common/actionEnums/admin' | ||
|
||
|
||
describe('adminTrainingReducer', () => { | ||
it("is defined", () => { | ||
// Arrange | ||
// Act | ||
// Assert | ||
expect(adminTrainingReducer).not.be.undefined; | ||
}); | ||
|
||
it("should return same state when passing an action that is not expected", () => { | ||
// Arrange | ||
const originalState : AdminTrainingState = new AdminTrainingState(); | ||
|
||
const action = { | ||
type: 'NOT_EXPECTED_ACTION' | ||
} | ||
|
||
// Act | ||
const newState = adminTrainingReducer(originalState, action); | ||
|
||
// Assert | ||
expect(newState).to.be.equal(originalState); | ||
|
||
}); | ||
|
||
it("should return a new state including edit training when passing a GET_TRAINING_REQUEST_COMPLETED", () => { | ||
// Arrange | ||
const originalState : AdminTrainingState = new AdminTrainingState(); | ||
const id: number = 32; | ||
const expectedTraining : TrainingEntity = { | ||
id: 32, | ||
name: 'React/Redux', | ||
isActive: true, | ||
start: new Date(1,1,2017), | ||
end: new Date(31,1,2017), | ||
students: new Array<Student>(), | ||
trainers: new Array<Trainer>() | ||
}; | ||
const actionResult = { | ||
type: adminActionEnums.GET_TRAINING_REQUEST_COMPLETED, | ||
payload: expectedTraining | ||
} | ||
|
||
// Act | ||
const newState = adminTrainingReducer(originalState, actionResult); | ||
|
||
// Assert | ||
expect(newState).not.to.be.equal(originalState); | ||
expect(newState.editTraining).to.be.eql(expectedTraining); | ||
|
||
}); | ||
}); |