-
Notifications
You must be signed in to change notification settings - Fork 12
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
37c4089
commit 5ee3d24
Showing
4 changed files
with
406 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/components/ModalActions/__snapshots__/index.test.jsx.snap
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,50 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<ModalActions /> can render primary and secondary with confirm 1`] = ` | ||
<div | ||
className="mt-2" | ||
> | ||
<ActionButton | ||
key="outline-primary" | ||
variant="outline-primary" | ||
/> | ||
<ConfirmDialog | ||
key="confirm-primary" | ||
/> | ||
<ActionButton | ||
key="primary" | ||
variant="primary" | ||
/> | ||
<ConfirmDialog | ||
key="confirm-primary" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`<ModalActions /> can render primary and secondary without confirm 1`] = ` | ||
<div | ||
className="mt-2" | ||
> | ||
<ActionButton | ||
key="outline-primary" | ||
variant="outline-primary" | ||
/> | ||
<ActionButton | ||
key="primary" | ||
variant="primary" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`<ModalActions /> render empty when no actions 1`] = ` | ||
<div | ||
className="mt-2" | ||
/> | ||
`; | ||
|
||
exports[`<ModalActions /> render skeleton when page data is loading 1`] = ` | ||
<Skeleton | ||
className="mt-2" | ||
wrapper={[Function]} | ||
/> | ||
`; |
132 changes: 132 additions & 0 deletions
132
src/components/ModalActions/hooks/useFinishedStateActions.test.js
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,132 @@ | ||
import { useGlobalState, useTrainingStepIsCompleted } from 'hooks/app'; | ||
import { | ||
useHasSubmitted, | ||
useSubmittedAssessment, | ||
} from 'hooks/assessment'; | ||
import { useViewStep } from 'hooks/routing'; | ||
import { | ||
useStartStepAction, | ||
useLoadNextAction, | ||
useCloseModalAction, | ||
} from 'hooks/actions'; | ||
import { stepNames, stepStates } from 'constants/index'; | ||
|
||
import useFinishedStateActions from './useFinishedStateActions'; | ||
|
||
jest.mock('hooks/app', () => ({ | ||
useGlobalState: jest.fn(), | ||
useTrainingStepIsCompleted: jest.fn(), | ||
})); | ||
jest.mock('hooks/assessment', () => ({ | ||
useHasSubmitted: jest.fn(), | ||
useSubmittedAssessment: jest.fn(), | ||
})); | ||
jest.mock('hooks/routing', () => ({ | ||
useViewStep: jest.fn(), | ||
})); | ||
jest.mock('hooks/actions', () => ({ | ||
useStartStepAction: jest.fn(), | ||
useLoadNextAction: jest.fn(), | ||
useCloseModalAction: jest.fn(), | ||
})); | ||
|
||
describe('useFinishedStateActions', () => { | ||
const mockStartStepAction = jest.fn(); | ||
const mockLoadNextAction = jest.fn(); | ||
const mockCloseModalAction = jest.fn(); | ||
|
||
useGlobalState.mockReturnValue({}); | ||
useTrainingStepIsCompleted.mockReturnValue(false); | ||
useHasSubmitted.mockReturnValue(false); | ||
useSubmittedAssessment.mockReturnValue(false); | ||
useViewStep.mockReturnValue('abitrarilyViewStepName'); | ||
|
||
useStartStepAction.mockReturnValue(mockStartStepAction); | ||
useLoadNextAction.mockReturnValue(mockLoadNextAction); | ||
useCloseModalAction.mockReturnValue(mockCloseModalAction); | ||
|
||
describe('when has submitted', () => { | ||
it('return null when has not submitted', () => { | ||
expect(useFinishedStateActions()).toBe(null); | ||
}); | ||
|
||
it('return null when has not submitted and is in training but not completed', () => { | ||
useViewStep.mockReturnValue(stepNames.studentTraining); | ||
expect(useFinishedStateActions()).toBe(null); | ||
}); | ||
|
||
it('return start action as primary when has submitted and is in done step', () => { | ||
useHasSubmitted.mockReturnValue(true); | ||
useSubmittedAssessment.mockReturnValue(true); | ||
useGlobalState.mockReturnValue({ activeStepName: stepNames.done }); | ||
|
||
expect(useFinishedStateActions()).toEqual({ primary: mockStartStepAction }); | ||
}); | ||
}); | ||
|
||
describe('when assessment submitted', () => { | ||
useHasSubmitted.mockReturnValue(true); | ||
useSubmittedAssessment.mockReturnValue(true); | ||
|
||
it('return start action as primary when step is done', () => { | ||
useGlobalState.mockReturnValue({ activeStepName: stepNames.done }); | ||
|
||
expect(useFinishedStateActions()).toEqual({ primary: mockStartStepAction }); | ||
}); | ||
|
||
it('return exit action as primary action when step is staff', () => { | ||
useGlobalState.mockReturnValue({ activeStepName: stepNames.staff }); | ||
|
||
expect(useFinishedStateActions()).toEqual({ primary: mockCloseModalAction }); | ||
}); | ||
|
||
it('return start and exit actions when view step is submission', () => { | ||
useGlobalState.mockReturnValue({ activeStepName: stepNames.submission }); | ||
useViewStep.mockReturnValue(stepNames.submission); | ||
|
||
expect(useFinishedStateActions()).toEqual({ primary: mockStartStepAction, secondary: mockCloseModalAction }); | ||
}); | ||
|
||
it('return start and exit actions when view step is self', () => { | ||
useGlobalState.mockReturnValue({ activeStepName: stepNames.self }); | ||
useViewStep.mockReturnValue(stepNames.submission); | ||
|
||
expect(useFinishedStateActions()).toEqual({ primary: mockStartStepAction, secondary: mockCloseModalAction }); | ||
}); | ||
|
||
it('return null when step is not active and step state is not in progress', () => { | ||
useGlobalState.mockReturnValue({ activeStepName: 'abitrarilyActiveStepName', activeStepState: stepStates.done }); | ||
useViewStep.mockReturnValue('abitrarilyViewStepName'); | ||
|
||
expect(useFinishedStateActions()).toBe(null); | ||
}); | ||
|
||
it('return start and exit actions when step is not active and step state is in progress', () => { | ||
useGlobalState.mockReturnValue({ activeStepName: 'abitrarilyActiveStepName', activeStepState: stepStates.inProgress }); | ||
useViewStep.mockReturnValue('abitrarilyViewStepName'); | ||
|
||
expect(useFinishedStateActions()).toEqual({ primary: mockStartStepAction, secondary: mockCloseModalAction }); | ||
}); | ||
|
||
it('return load next and exit actions when step is active and step state is in progress', () => { | ||
useGlobalState.mockReturnValue({ activeStepName: 'active', activeStepState: stepStates.inProgress }); | ||
useViewStep.mockReturnValue('active'); | ||
|
||
expect(useFinishedStateActions()).toEqual({ primary: mockLoadNextAction, secondary: mockCloseModalAction }); | ||
}); | ||
|
||
it('return exit action when all steps are finished', () => { | ||
useGlobalState.mockReturnValue({ activeStepName: 'active' }); | ||
useViewStep.mockReturnValue('active'); | ||
|
||
expect(useFinishedStateActions()).toEqual({ primary: mockCloseModalAction }); | ||
}); | ||
}); | ||
|
||
it('return start and exit actions when submission is finished', () => { | ||
useHasSubmitted.mockReturnValue(true); | ||
useSubmittedAssessment.mockReturnValue(false); | ||
|
||
expect(useFinishedStateActions()).toEqual({ primary: mockStartStepAction, secondary: mockCloseModalAction }); | ||
}); | ||
}); |
154 changes: 154 additions & 0 deletions
154
src/components/ModalActions/hooks/useInProgressActions.test.js
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,154 @@ | ||
import { useGlobalState, useStepInfo } from 'hooks/app'; | ||
import { useHasSubmitted } from 'hooks/assessment'; | ||
import { useViewStep } from 'hooks/routing'; | ||
import { stepNames, stepStates } from 'constants/index'; | ||
|
||
import { | ||
useCloseModalAction, | ||
useLoadNextAction, | ||
useStartStepAction, | ||
useSubmitResponseAction, | ||
} from 'hooks/actions'; | ||
|
||
import useInProgressActions from './useInProgressActions'; | ||
|
||
jest.mock('hooks/app', () => ({ | ||
useGlobalState: jest.fn(), | ||
useStepInfo: jest.fn(), | ||
})); | ||
jest.mock('hooks/assessment', () => ({ | ||
useHasSubmitted: jest.fn(), | ||
})); | ||
jest.mock('hooks/routing', () => ({ | ||
useViewStep: jest.fn(), | ||
})); | ||
jest.mock('hooks/actions', () => ({ | ||
useCloseModalAction: jest.fn(), | ||
useLoadNextAction: jest.fn(), | ||
useStartStepAction: jest.fn(), | ||
useSubmitResponseAction: jest.fn(), | ||
})); | ||
|
||
describe('useInProgressActions', () => { | ||
const mockCloseModalAction = jest.fn().mockName('closeModalAction'); | ||
const mockLoadNextAction = jest.fn().mockName('loadNextAction'); | ||
const mockStartStepAction = jest.fn().mockName('startStepAction'); | ||
const mockSubmitResponseAction = jest.fn().mockName('submitResponseAction'); | ||
useCloseModalAction.mockReturnValue(mockCloseModalAction); | ||
useLoadNextAction.mockReturnValue(mockLoadNextAction); | ||
useStartStepAction.mockReturnValue(mockStartStepAction); | ||
useSubmitResponseAction.mockReturnValue(mockSubmitResponseAction); | ||
|
||
useGlobalState.mockReturnValue({}); | ||
useStepInfo.mockReturnValue({}); | ||
useHasSubmitted.mockReturnValue(false); | ||
useViewStep.mockReturnValue(stepNames.submission); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('return startStepAction and exitAction when hasReceivedFinalGrade is true', () => { | ||
useGlobalState.mockReturnValueOnce({ hasReceivedFinalGrade: true }); | ||
const result = useInProgressActions({ options: {} }); | ||
expect(result).toEqual({ | ||
primary: mockStartStepAction, | ||
secondary: mockCloseModalAction, | ||
}); | ||
}); | ||
|
||
it('return null when hasSubmitted is true', () => { | ||
useGlobalState.mockReturnValueOnce({ hasReceivedFinalGrade: false }); | ||
useHasSubmitted.mockReturnValueOnce(true); | ||
const result = useInProgressActions({ options: {} }); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it('return null when activeStepState is not inProgress', () => { | ||
useGlobalState.mockReturnValueOnce({ | ||
hasReceivedFinalGrade: false, | ||
activeStepState: stepStates.done, | ||
}); | ||
const result = useInProgressActions({ options: {} }); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it('return null if globalState.stepState is inProgress and step is not submission', () => { | ||
useGlobalState.mockReturnValueOnce({ | ||
hasReceivedFinalGrade: false, | ||
activeStepState: stepStates.inProgress, | ||
stepState: stepStates.inProgress, | ||
}); | ||
useViewStep.mockReturnValueOnce(stepNames.peer); | ||
const result = useInProgressActions({ options: {} }); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it('return activeSubmissionConfig when globalState.stepState is inProgress and step is submission', () => { | ||
useGlobalState.mockReturnValueOnce({ | ||
hasReceivedFinalGrade: false, | ||
activeStepState: stepStates.inProgress, | ||
stepState: stepStates.inProgress, | ||
}); | ||
const result = useInProgressActions({ options: {} }); | ||
expect(result.primary.getMockName()).toBe( | ||
mockSubmitResponseAction.getMockName(), | ||
); | ||
expect(result.secondary.getMockName()).toBe( | ||
mockCloseModalAction.getMockName(), | ||
); | ||
}); | ||
|
||
it('return loadNextAction and exitAction when activeStepName is peer and numberOfAssessmentsCompleted is true', () => { | ||
useGlobalState.mockReturnValueOnce({ | ||
hasReceivedFinalGrade: false, | ||
activeStepState: stepStates.inProgress, | ||
stepState: stepStates.done, | ||
activeStepName: stepNames.peer, | ||
}); | ||
useStepInfo.mockReturnValueOnce({ | ||
peer: { numberOfAssessmentsCompleted: true }, | ||
}); | ||
const result = useInProgressActions({ options: {} }); | ||
expect(result.primary.getMockName()).toBe(mockLoadNextAction.getMockName()); | ||
expect(result.secondary.getMockName()).toBe( | ||
mockCloseModalAction.getMockName(), | ||
); | ||
}); | ||
|
||
it('return loadNextAction and exitAction when activeStepName is studentTraining and numberOfAssessmentsCompleted is true', () => { | ||
useGlobalState.mockReturnValueOnce({ | ||
hasReceivedFinalGrade: false, | ||
activeStepState: stepStates.inProgress, | ||
stepState: stepStates.done, | ||
activeStepName: stepNames.studentTraining, | ||
}); | ||
useStepInfo.mockReturnValueOnce({ | ||
studentTraining: { numberOfAssessmentsCompleted: true }, | ||
}); | ||
const result = useInProgressActions({ options: {} }); | ||
expect(result.primary.getMockName()).toBe(mockLoadNextAction.getMockName()); | ||
expect(result.secondary.getMockName()).toBe( | ||
mockCloseModalAction.getMockName(), | ||
); | ||
}); | ||
|
||
it('return startStepAction and exitAction when activeStepName is peer and numberOfAssessmentsCompleted is false', () => { | ||
useGlobalState.mockReturnValueOnce({ | ||
hasReceivedFinalGrade: false, | ||
activeStepState: stepStates.inProgress, | ||
stepState: stepStates.done, | ||
activeStepName: stepNames.peer, | ||
}); | ||
useStepInfo.mockReturnValueOnce({ | ||
peer: { numberOfAssessmentsCompleted: false }, | ||
}); | ||
const result = useInProgressActions({ options: {} }); | ||
expect(result.primary.getMockName()).toBe( | ||
mockStartStepAction.getMockName(), | ||
); | ||
expect(result.secondary.getMockName()).toBe( | ||
mockCloseModalAction.getMockName(), | ||
); | ||
}); | ||
}); |
Oops, something went wrong.