diff --git a/squarenotsquare/__tests__/Action-Creators-test.js b/squarenotsquare/__tests__/Action-Creators-test.js index 2bb560e..e9d581c 100644 --- a/squarenotsquare/__tests__/Action-Creators-test.js +++ b/squarenotsquare/__tests__/Action-Creators-test.js @@ -1,18 +1,63 @@ import 'react-native'; -import {appInit} from '../src/redux/actions/SystemActions'; -import { APP_INIT } from '../src/redux/types/SystemTypes'; +import {appInit, goHome, goToScores} from '../src/redux/actions/SystemActions'; +import { APP_INIT, NAV_HOME, NAV_SCORES } from '../src/redux/types/SystemTypes'; import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; +import { addFinished, squareFinished, squareStartPressed } from '../src/redux/actions/UserActions'; +import { ADDITION_FINISHED, ADDITION_START, SQUARE_FINISHED, SQUARE_START } from '../src/redux/types/UserTypes'; + jest.useRealTimers(); const middlewares = [thunk]; const mockStore = configureMockStore(middlewares); test('sends action app-init', () => { - const localStore = mockStore(); + const localStore = mockStore({user: {username: 'username'}}); return localStore.dispatch(appInit()) .then( () => { - const actualAction = localStore.getActions()[0]; - expect(actualAction.type).toEqual(APP_INIT); + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(APP_INIT); }) -}); \ No newline at end of file +}); + +test ('sends action nav-home', () => { + const localStore = mockStore({user: {username: 'username'}}); + localStore.dispatch(goHome()) + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(NAV_HOME); +}) + +test ('sends action nav-scores', () => { + const localStore = mockStore({user: {username: 'username'}}); + localStore.dispatch(goToScores()) + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(NAV_SCORES); +}) + +test ('starts square game with square-start', () => { + const localStore = mockStore({user: {username: 'username'}}); + localStore.dispatch(squareStartPressed('square', 'user')) + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(SQUARE_START); +}) + +test ('starts add game with addition-start', () => { + const localStore = mockStore({user: {username: 'username'}}); + localStore.dispatch(squareStartPressed('addition', 'user')) + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(ADDITION_START); +}) + +test ('completes square game with square-finished', () => { + const localStore = mockStore({user: {username: 'username'}}); + localStore.dispatch(squareFinished(10, 10)) + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(SQUARE_FINISHED); +}) + +test ('completes add game with addition-finished', () => { + const localStore = mockStore({user: {username: 'username'}}); + localStore.dispatch(addFinished(10, 10)) + const actualAction = localStore.getActions()[0]; + expect(actualAction.type).toEqual(ADDITION_FINISHED); +}) \ No newline at end of file