From 3e1cbfa97db754c562fd065ef7c1b1ff66103e27 Mon Sep 17 00:00:00 2001 From: martin bedouret Date: Sun, 23 Jun 2019 11:51:23 -0300 Subject: [PATCH] unitest --- cboard.njsproj.user | 6 + package.json | 5 +- src/__mocks__/axios.js | 2 + src/__mocks__/store.js | 24 +++ src/__test__/helpers.test.js | 14 ++ src/__test__/i18n.test.js | 21 ++ src/__test__/reducers.test.js | 9 + src/__test__/registerServiceWorker.test.js | 42 ++++ src/__test__/store.test.js | 9 + src/api/api.test.js | 148 +++++++++++++ .../__tests__/Activate.actions.test.js | 38 ++++ .../Board/__tests__/Board.reducer.test.js | 194 ++++++++++++++++++ .../__tests__/Communicator.actions.test.js | 15 ++ .../__tests__/Communicator.reducer.test.js | 73 +++++++ .../Settings/Navigation/Navigation.test.js | 11 +- .../__snapshots__/LockToggle.test.js.snap | 2 + src/registerServiceWorker.js | 2 +- 17 files changed, 612 insertions(+), 3 deletions(-) create mode 100644 cboard.njsproj.user create mode 100644 src/__mocks__/axios.js create mode 100644 src/__mocks__/store.js create mode 100644 src/__test__/helpers.test.js create mode 100644 src/__test__/i18n.test.js create mode 100644 src/__test__/reducers.test.js create mode 100644 src/__test__/registerServiceWorker.test.js create mode 100644 src/__test__/store.test.js create mode 100644 src/api/api.test.js create mode 100644 src/components/Account/Activate/__tests__/Activate.actions.test.js create mode 100644 src/components/Board/__tests__/Board.reducer.test.js create mode 100644 src/components/Communicator/__tests__/Communicator.reducer.test.js diff --git a/cboard.njsproj.user b/cboard.njsproj.user new file mode 100644 index 000000000..c8ee29ac4 --- /dev/null +++ b/cboard.njsproj.user @@ -0,0 +1,6 @@ + + + + Debug|Any CPU + + \ No newline at end of file diff --git a/package.json b/package.json index 9a812f4df..3efafe63e 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "enzyme-adapter-react-16": "^1.13.2", "enzyme-to-json": "3.3.5", "husky": "^1.1.4", + "jest-mock-axios": "3.0.0", "lint-staged": "^7.3.0", "nock": "^10.0.2", "prettier": "1.15.3", @@ -104,7 +105,9 @@ "!src/components/**/index.js", "!src/providers/**/index.js", "!src/components/**/*.constants.js", - "!src/components/**/*.messages.js" + "!src/components/**/*.messages.js", + "!src/components/**/*.container.js", + "!src/components/**/*.helpers.js" ] }, "scripts": { diff --git a/src/__mocks__/axios.js b/src/__mocks__/axios.js new file mode 100644 index 000000000..a6719f4aa --- /dev/null +++ b/src/__mocks__/axios.js @@ -0,0 +1,2 @@ +import mockAxios from 'jest-mock-axios'; +export default mockAxios; diff --git a/src/__mocks__/store.js b/src/__mocks__/store.js new file mode 100644 index 000000000..07b8afc2f --- /dev/null +++ b/src/__mocks__/store.js @@ -0,0 +1,24 @@ + +import configureMockStore from 'redux-mock-store'; +import thunk from 'redux-thunk'; +const middlewares = [thunk]; +const mockStore = configureMockStore(middlewares); + +let initialState; + initialState = { + app: { + userData: { + authToken: "eyJhbGciOiJIUtI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFybCI6ImFueXRoaW5nQGNib2FyZC5pbyIsImlkIjoiNWJjZmE0ZWQ0OTRiMjAwMDBmOGFiOThiIiwiaXNzdWVyIjoiY2JvYXJkLmlvIiwiaWF0IjoxNTU5NzU1NTU3fQ.2ENI4GyaHwV1B-Pifi0ZUKqyGcjTSLDV0UoPKUY99bo", + email: "anything@cboard.io", + id: "5bcfa4ed494b20000f8ab98b", + lastlogin: "2018-10-23T22:47:09.367Z", + locale: "en-US", + name: "martin bedouret", + provider: "", + role: "user" + } + } + }; + const store = mockStore(initialState); + + export const getStore = () => store; diff --git a/src/__test__/helpers.test.js b/src/__test__/helpers.test.js new file mode 100644 index 000000000..a243d15e3 --- /dev/null +++ b/src/__test__/helpers.test.js @@ -0,0 +1,14 @@ +import * as helpers from '../helpers'; +describe('helpers', () => { + + it('should create a file from data', () => { + const dataUrl = "data:text/plain;charset=utf-8;base64,dGVzdGluZw=="; + const file = helpers.dataURLtoFile(dataUrl, 'myfile'); + expect(file.name).toBe("myfile"); + }); + it('should create a file with ext from data', () => { + const dataUrl = "data:text/plain;charset=utf-8;base64,dGVzdGluZw=="; + const file = helpers.dataURLtoFile(dataUrl, 'myfile.txt', true); + expect(file.name).toBe('myfile.txt.plain'); + }); +}); diff --git a/src/__test__/i18n.test.js b/src/__test__/i18n.test.js new file mode 100644 index 000000000..c965eef18 --- /dev/null +++ b/src/__test__/i18n.test.js @@ -0,0 +1,21 @@ +import * as i18n from '../i18n'; +describe('i18n', () => { + + it('should import translation data', () => { + i18n.importTranslation('es-ES') + .then((lang) => { + expect(lang.cboard.components.WelcomeScreen.login).toBe("Iniciar sesión"); + }); + }); + it('should strip Region Code', () => { + expect(i18n.stripRegionCode('es-ES')).toBe("es"); + }); + it('should normalize Language Code', () => { + expect(i18n.normalizeLanguageCode('ES-ES')).toBe("es-ES"); + expect(i18n.normalizeLanguageCode('es-es')).toBe("es-ES"); + }); + it('should normalize Language Code for two', () => { + expect(i18n.normalizeLanguageCode('ES')).toBe("es"); + expect(i18n.normalizeLanguageCode('es')).toBe("es"); + }); +}); diff --git a/src/__test__/reducers.test.js b/src/__test__/reducers.test.js new file mode 100644 index 000000000..9874186fe --- /dev/null +++ b/src/__test__/reducers.test.js @@ -0,0 +1,9 @@ + +import createReducer from '../reducers'; +describe('reducers', () => { + + it('should create Reducer', () => { + const red = createReducer(); + expect(red).toBeDefined; + }); +}); diff --git a/src/__test__/registerServiceWorker.test.js b/src/__test__/registerServiceWorker.test.js new file mode 100644 index 000000000..c404ad294 --- /dev/null +++ b/src/__test__/registerServiceWorker.test.js @@ -0,0 +1,42 @@ + +import register from '../registerServiceWorker'; +import unregister from '../registerServiceWorker'; +describe('registerServiceWorker', () => { + + global.navigator = Object.create(navigator); + Object.defineProperty(navigator, 'serviceWorker', { + value: { ready: false } + }); + global.process.env = Object.create(process.env); + Object.defineProperty(process.env, 'NODE_ENV', { + value: 'production' + }); + global.process.env = Object.create(process.env); + Object.defineProperty(process.env, 'PUBLIC_URL', { + value: 'https://app.cboard.io' + }); + global.window = Object.create(window); + Object.defineProperty(window, 'location', { + value: { + href: 'https://app.cboard.io', + origin: 'https://app.cboard.io' + }, + writable: true + }); + + it('should register Service Worker', () => { + const serviceWorker = register(jest.fn(), jest.fn()); + expect(serviceWorker).toBeDefined; + }); + it('should register Service Worker localhost', () => { + Object.defineProperty(window.location, 'hostname', { + value: 'localhost' + }); + const serviceWorker = register(jest.fn(), jest.fn()); + expect(serviceWorker).toBeDefined; + }); + it('should unregister Service Worker', () => { + const serviceWorker = unregister(); + expect(serviceWorker).toBeDefined; + }); +}); diff --git a/src/__test__/store.test.js b/src/__test__/store.test.js new file mode 100644 index 000000000..6fed32bd3 --- /dev/null +++ b/src/__test__/store.test.js @@ -0,0 +1,9 @@ + +import configureStore from '../store'; +describe('store', () => { + + it('should configure Store', () => { + const store = configureStore(); + expect(store).toBeDefined; + }); +}); diff --git a/src/api/api.test.js b/src/api/api.test.js new file mode 100644 index 000000000..8eec7c708 --- /dev/null +++ b/src/api/api.test.js @@ -0,0 +1,148 @@ + +import API from './api'; +import mockAxios from 'jest-mock-axios'; + +let store; +// allows us to easily return reponses and/or success/fail for a thunk that calls a service +const mockServiceCreator = (body, succeeds = true) => () => + new Promise((resolve, reject) => { + setTimeout(() => (succeeds ? resolve(body) : reject(body)), 10); + }); + +describe('Cboard API calls', () => { + let initialState; + // set up a fake store for all our tests + beforeEach(() => { + }); + afterEach(() => { + // cleaning up the mess left behind the previous test + mockAxios.reset(); + }); + + it("fetches results from get language api", () => { + let catchFn = jest.fn(), thenFn = jest.fn(); + + //call method + API.getLanguage('es-ES') + .then(thenFn) + .catch(catchFn); + // simulating a server response + let responseObj = { data: 'fake!' }; + mockAxios.mockResponse(responseObj); + }); + it("fetches results from get my boards api", () => { + let catchFn = jest.fn(), thenFn = jest.fn(); + + //call method + API.getMyBoards(1, 10) + .then(thenFn) + .catch(catchFn); + }); + it("fetches results from get boards api", () => { + let catchFn = jest.fn(), thenFn = jest.fn(); + + //call method + API.getBoards(1) + .then(thenFn) + .catch(catchFn); + }); + it("fetches results from get board api", () => { + let catchFn = jest.fn(), thenFn = jest.fn(); + + //call method + API.getBoard('aaaa') + .then(thenFn) + .catch(catchFn); + }); + it("fetches results from get communicators api", () => { + let catchFn = jest.fn(), thenFn = jest.fn(); + + //call method + API.getCommunicators(1,10) + .then(thenFn) + .catch(catchFn); + }); + it("fetches results from createBoard api", () => { + let catchFn = jest.fn(), thenFn = jest.fn(); + const board = { + "name": "board_name", + "author": "Postman Test", + "email": "email@qwe.com", + "format": "obf", + "tiles": [ + {} + ], + "caption": "string", + "isPublic": true, + "locale": "ar-SA" + } + //call method + API.createBoard(board) + .then(thenFn) + .catch(catchFn); + }); + it("fetches results from createCommunicator api", () => { + let catchFn = jest.fn(), thenFn = jest.fn(); + const comm = { + "name": "comm_name", + "author": "Postman Test", + "email": "email@qwe.com", + "rootBoard": "obf", + "boards": [ + {} + ] + }; + //call method + API.createCommunicator(comm) + .then(thenFn) + .catch(catchFn); + }); + it("fetches results from arasaacPictogramsSearch api", () => { + let catchFn = jest.fn(), thenFn = jest.fn(); + //call method + API.arasaacPictogramsSearch('es','perro') + .then(thenFn) + .catch(catchFn); + // simulating a server response + let responseObj = { data: 'fake!' }; + mockAxios.mockResponse(responseObj); + }); + it("fetches results from deleteBoard api", () => { + let catchFn = jest.fn(), thenFn = jest.fn(); + //call method + API.deleteBoard('esnm') + .then(thenFn) + .catch(catchFn); + }); + it("fetches results from login api", () => { + let catchFn = jest.fn(), thenFn = jest.fn(); + const user = { + "email": "email@qwe.com", + "password": "123456" + } + //call method + API.login(user) + .then(thenFn) + .catch(catchFn); + // simulating a server response + let responseObj = { data: 'fake!' }; + mockAxios.mockResponse(responseObj); + }); + it("fetches results from tawasolPictogramsSearch api", () => { + let catchFn = jest.fn(), thenFn = jest.fn(); + //call method + API.tawasolPictogramsSearch('es', 'perro') + .then(thenFn) + .catch(catchFn); + // simulating a server response + let responseObj = { data: 'fake!' }; + mockAxios.mockResponse(responseObj); + }); + it("fetches results from uploadFromDataURL api", () => { + let catchFn = jest.fn(), thenFn = jest.fn(); + //call method + API.uploadFromDataURL('es', 'perro') + .then(thenFn) + .catch(catchFn); + }); + }); diff --git a/src/components/Account/Activate/__tests__/Activate.actions.test.js b/src/components/Account/Activate/__tests__/Activate.actions.test.js new file mode 100644 index 000000000..a9cd7d0a3 --- /dev/null +++ b/src/components/Account/Activate/__tests__/Activate.actions.test.js @@ -0,0 +1,38 @@ + +import * as ac from '../Activate.actions'; +import mockAxios from 'jest-mock-axios'; +import { API_URL } from '../../../../constants'; + +afterEach(() => { + // cleaning up the mess left behind the previous test + mockAxios.reset(); +}); + +describe('Activate actions', () => { + global.window = Object.create(window); + Object.defineProperty(window, 'location', { + value: { + href: 'https://app.cboard.io', + origin: 'https://app.cboard.io' + }, + writable: true + }); + it("fetches results from get language api", () => { + + const url = 'asdf'; + + let catchFn = jest.fn(), + thenFn = jest.fn(); + + //call method + ac.activate(url) + .then(thenFn) + .catch(catchFn); + expect(mockAxios.post).toHaveBeenCalledWith(`${API_URL}/user/activate/${url}`); + // simulating a server response + let responseObj = { data: 'activated!' }; + mockAxios.mockResponse(responseObj); + + + }); +}); diff --git a/src/components/Board/__tests__/Board.reducer.test.js b/src/components/Board/__tests__/Board.reducer.test.js new file mode 100644 index 000000000..48562dd72 --- /dev/null +++ b/src/components/Board/__tests__/Board.reducer.test.js @@ -0,0 +1,194 @@ +import * as actions from '../Board.actions'; +import * as types from '../Board.constants'; +import boardReducer from '../Board.reducer'; +import defaultBoards from '../../../api/boards.json'; +import { + IMPORT_BOARDS, + ADD_BOARDS, + CHANGE_BOARD, + SWITCH_BOARD, + PREVIOUS_BOARD, + DELETE_BOARD, + CREATE_BOARD, + UPDATE_BOARD, + CREATE_TILE, + DELETE_TILES, + EDIT_TILES, + FOCUS_TILE, + CHANGE_OUTPUT, + REPLACE_BOARD, + HISTORY_REMOVE_PREVIOUS_BOARD, + UNMARK_BOARD, + CREATE_API_BOARD_SUCCESS, + CREATE_API_BOARD_FAILURE, + CREATE_API_BOARD_STARTED, + UPDATE_API_BOARD_SUCCESS, + UPDATE_API_BOARD_FAILURE, + UPDATE_API_BOARD_STARTED, + DELETE_API_BOARD_SUCCESS, + DELETE_API_BOARD_FAILURE, + DELETE_API_BOARD_STARTED, + GET_API_MY_BOARDS_SUCCESS, + GET_API_MY_BOARDS_FAILURE, + GET_API_MY_BOARDS_STARTED +} from '../Board.constants'; + +const mockBoard = { name: 'tewt', id: '123', tiles: [], isPublic: false, email: 'asd@qwe.com', markToUpdate: true }; +const [...boards] = defaultBoards.advanced; +const initialState = { + boards, + output: [], + activeBoardId: null, + navHistory: [], + isFetching: false +}; + +describe('reducer', () => { + it('should return the initial state', () => { + expect(boardReducer(undefined, {})).toEqual(initialState); + }); + it('should handle createApiBoardStarted', () => { + const createApiBoardStarted = { + type: CREATE_API_BOARD_STARTED + }; + expect(boardReducer(initialState, createApiBoardStarted)).toEqual({ ...initialState, isFetching: true }); + }); + it('should handle deleteApiBoardStarted', () => { + const deleteApiBoardStarted = { + type: DELETE_API_BOARD_STARTED + }; + expect(boardReducer(initialState, deleteApiBoardStarted)).toEqual({ ...initialState, isFetching: true }); + }); + it('should handle getApiMyBoardsStarted', () => { + const getApiMyBoardsStarted = { + type: GET_API_MY_BOARDS_STARTED + }; + expect(boardReducer(initialState, getApiMyBoardsStarted)).toEqual({ ...initialState, isFetching: true }); + }); + it('should handle updateApiBoardStarted', () => { + const updateApiBoardStarted = { + type: UPDATE_API_BOARD_STARTED + }; + expect(boardReducer(initialState, updateApiBoardStarted)).toEqual({ ...initialState, isFetching: true }); + }); + it('should handle createApiBoardFailure', () => { + const createApiBoardFailure = { + type: CREATE_API_BOARD_FAILURE + }; + expect(boardReducer(initialState, createApiBoardFailure)).toEqual({ ...initialState, isFetching: false }); + }); + it('should handle deleteApiBoardFailure', () => { + const deleteApiBoardFailure = { + type: DELETE_API_BOARD_FAILURE + }; + expect(boardReducer(initialState, deleteApiBoardFailure)).toEqual({ ...initialState, isFetching: false }); + }); + it('should handle getApiMyBoardsFailure', () => { + const getApiMyBoardsFailure = { + type: GET_API_MY_BOARDS_FAILURE + }; + expect(boardReducer(initialState, getApiMyBoardsFailure)).toEqual({ ...initialState, isFetching: false }); + }); + it('should handle updateApiBoardFailure', () => { + const updateApiBoardFailure = { + type: UPDATE_API_BOARD_FAILURE + }; + expect(boardReducer(initialState, updateApiBoardFailure)).toEqual({ ...initialState, isFetching: false }); + }); + it('should handle createApiBoardSuccess', () => { + const createApiBoardSuccess = { + type: CREATE_API_BOARD_SUCCESS, + board: mockBoard, + boardId: '456' + }; + expect(boardReducer(initialState, createApiBoardSuccess)).toEqual({ ...initialState, isFetching: false }); + }); + it('should handle deleteApiBoardSuccess', () => { + const deleteApiBoardSuccess = { + type: DELETE_API_BOARD_SUCCESS, + board: mockBoard + }; + expect(boardReducer(initialState, deleteApiBoardSuccess)).toEqual({ + ...initialState, + boards: [ + ...initialState.boards.filter(board => board.id !== '123') + ], + isFetching: false + }); + }); + it('should handle getApiMyBoardsSuccess', () => { + const getApiMyBoardsSuccess = { + type: GET_API_MY_BOARDS_SUCCESS, + boards: { data: [mockBoard, mockBoard] } + }; + expect(boardReducer(initialState, getApiMyBoardsSuccess)).toEqual({ ...initialState, boards: [...initialState.boards, mockBoard], isFetching: false }); + }); + it('should handle updateApiBoardSuccess', () => { + const updateApiBoardSuccess = { + type: UPDATE_API_BOARD_SUCCESS, + board: mockBoard + }; + expect(boardReducer(initialState, updateApiBoardSuccess)).toEqual({ ...initialState, isFetching: false }); + }); + it('should handle unmarkBoard', () => { + const unmarkBoard = { + type: UNMARK_BOARD, + boardId: '123' + }; + expect(boardReducer({ ...initialState, boards: [...initialState.boards, mockBoard] }, unmarkBoard)).toEqual({ + ...initialState, + boards: [ + ...initialState.boards.filter(board => board.id !== '123'), + { ...mockBoard, markToUpdate: false } + ] + }); + }); + it('should handle historyRemovePreviousBoard', () => { + const historyRemovePreviousBoard = { + type: HISTORY_REMOVE_PREVIOUS_BOARD, + boardId: 'root' + }; + expect(boardReducer({ + ...initialState, + navHistory: ['root', 'a', 'b'] + }, + historyRemovePreviousBoard)).toEqual({ + ...initialState, + navHistory: ['root', 'a'], + activeBoardId: "root" + }); + }); + it('should handle replaceBoard', () => { + const replaceBoard = { + type: REPLACE_BOARD, + payload: { + prev: mockBoard, + current: { ...mockBoard, id: '456' } + } + }; + expect(boardReducer({ + ...initialState, + boards: [...initialState.boards, mockBoard] + }, + replaceBoard)).toEqual({ + ...initialState, + boards: [...initialState.boards, mockBoard, { ...mockBoard, id: '456' }] + }); + }); + it('should handle addBoards', () => { + const addBoards = { + type: actions.addBoards, + boards: ['b1', 'b2'] + }; + expect(boardReducer(initialState, addBoards)).toEqual(initialState); + }); + it('should handle changeBoard', () => { + const changeBoard = { + type: actions.changeBoard, + boardId: 'b1' + }; + expect(boardReducer(initialState, changeBoard)).toEqual(initialState); + }); + + +}); diff --git a/src/components/Communicator/__tests__/Communicator.actions.test.js b/src/components/Communicator/__tests__/Communicator.actions.test.js index 9d2da53e1..50d982efe 100644 --- a/src/components/Communicator/__tests__/Communicator.actions.test.js +++ b/src/components/Communicator/__tests__/Communicator.actions.test.js @@ -172,4 +172,19 @@ describe('actions', () => { expectedAction ); }); + it('should contain thunk functions', () => { + const communicatorData = { + author: "Cboard Team", + boards: ["root"], + description: "Cboard's default communicator", + email: "support@cboard.io", + id: "cboard_default", + name: "Cboard's Communicator", + rootBoard: "root" + }; + + expect(actions.updateApiCommunicator(communicatorData)).toBeDefined(); + expect(actions.createApiCommunicator(communicatorData, 'id')).toBeDefined(); + expect(actions.getApiMyCommunicators()).toBeDefined(); + }); }); diff --git a/src/components/Communicator/__tests__/Communicator.reducer.test.js b/src/components/Communicator/__tests__/Communicator.reducer.test.js new file mode 100644 index 000000000..9bbbd18a3 --- /dev/null +++ b/src/components/Communicator/__tests__/Communicator.reducer.test.js @@ -0,0 +1,73 @@ +import * as actions from '../Communicator.actions'; +import communicatorReducer from '../Communicator.reducer'; +import defaultCommunicators from '../../../api/communicators.json'; +import { + IMPORT_COMMUNICATOR, + CREATE_COMMUNICATOR, + EDIT_COMMUNICATOR, + DELETE_COMMUNICATOR, + CHANGE_COMMUNICATOR, + ADD_BOARD_COMMUNICATOR, + DELETE_BOARD_COMMUNICATOR, + REPLACE_BOARD_COMMUNICATOR, + CREATE_API_COMMUNICATOR_SUCCESS, + CREATE_API_COMMUNICATOR_FAILURE, + CREATE_API_COMMUNICATOR_STARTED, + UPDATE_API_COMMUNICATOR_SUCCESS, + UPDATE_API_COMMUNICATOR_FAILURE, + UPDATE_API_COMMUNICATOR_STARTED, + GET_API_MY_COMMUNICATORS_SUCCESS, + GET_API_MY_COMMUNICATORS_FAILURE, + GET_API_MY_COMMUNICATORS_STARTED +} from '../Communicator.constants'; + +const defaultCommunicatorID = 'cboard_default'; +const initialState = { + communicators: defaultCommunicators, + activeCommunicatorId: defaultCommunicatorID +}; + + +describe('reducer', () => { + it('should return the initial state', () => { + expect(communicatorReducer(undefined, {})).toEqual(initialState); + }); + + it('should handle getApiMyCommunicatorsStarted', () => { + const getApiMyCommunicatorsStarted = { + type: GET_API_MY_COMMUNICATORS_STARTED + }; + expect(communicatorReducer(initialState, getApiMyCommunicatorsStarted)).toEqual({ ...initialState, isFetching: true}); + }); + it('should handle createApiMyCommunicatorsStarted', () => { + const createApiMyCommunicatorsStarted = { + type: CREATE_API_COMMUNICATOR_STARTED + }; + expect(communicatorReducer(initialState, createApiMyCommunicatorsStarted)).toEqual({ ...initialState, isFetching: true }); + }); + it('should handle updateApiMyCommunicatorsStarted', () => { + const updateApiMyCommunicatorsStarted = { + type: UPDATE_API_COMMUNICATOR_STARTED + }; + expect(communicatorReducer(initialState, updateApiMyCommunicatorsStarted)).toEqual({ ...initialState, isFetching: true }); + }); + it('should handle getApiMyCommunicatorsFailure', () => { + const getApiMyCommunicatorsFailure = { + type: GET_API_MY_COMMUNICATORS_FAILURE + }; + expect(communicatorReducer(initialState, getApiMyCommunicatorsFailure)).toEqual({ ...initialState, isFetching: false }); + }); + it('should handle createApiMyCommunicatorsFailure', () => { + const createApiMyCommunicatorsFailure = { + type: CREATE_API_COMMUNICATOR_FAILURE + }; + expect(communicatorReducer(initialState, createApiMyCommunicatorsFailure)).toEqual({ ...initialState, isFetching: false }); + }); + it('should handle updateApiMyCommunicatorsFailure', () => { + const updateApiMyCommunicatorsFailure = { + type: UPDATE_API_COMMUNICATOR_FAILURE + }; + expect(communicatorReducer(initialState, updateApiMyCommunicatorsFailure)).toEqual({ ...initialState, isFetching: false }); + }); + +}); diff --git a/src/components/Settings/Navigation/Navigation.test.js b/src/components/Settings/Navigation/Navigation.test.js index 46da94d1d..f5a882da1 100644 --- a/src/components/Settings/Navigation/Navigation.test.js +++ b/src/components/Settings/Navigation/Navigation.test.js @@ -32,7 +32,8 @@ const COMPONENT_PROPS = { updateNavigationSettings: payload => { navigationSettings = { ...navigationSettings, ...payload }; }, - onClose: () => {} + onClose: () => { }, + onSubmit: () => { } }; describe('Navigation tests', () => { @@ -57,4 +58,12 @@ describe('Navigation tests', () => { tree = toJson(wrapper); expect(tree).toMatchSnapshot(); }); + test('switch behavior', () => { + const wrapper = shallow(); + + const state = wrapper.state(); + + const switchElement = wrapper.first('FullScreenDialog'); + switchElement.simulate('onSubmit'); + }); }); diff --git a/src/components/UI/LockToggle/__snapshots__/LockToggle.test.js.snap b/src/components/UI/LockToggle/__snapshots__/LockToggle.test.js.snap index 17c64c982..6aa83f87e 100644 --- a/src/components/UI/LockToggle/__snapshots__/LockToggle.test.js.snap +++ b/src/components/UI/LockToggle/__snapshots__/LockToggle.test.js.snap @@ -12,3 +12,5 @@ exports[`LockToggle tests default renderer 1`] = ` onLockTick={[Function]} /> `; + +exports[`LockToggle tests default renderer with props 1`] = `null`; diff --git a/src/registerServiceWorker.js b/src/registerServiceWorker.js index 2c35fdb23..8146cf3bb 100644 --- a/src/registerServiceWorker.js +++ b/src/registerServiceWorker.js @@ -21,7 +21,7 @@ const isLocalhost = Boolean( export default function register(onNewContentAvailable, onContentCached) { if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { // The URL constructor is available in all browsers that support SW. - const publicUrl = new URL(process.env.PUBLIC_URL, window.location); + const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); if (publicUrl.origin !== window.location.origin) { // Our service worker won't work if PUBLIC_URL is on a different origin // from what our page is served on. This might happen if a CDN is used to