diff --git a/client/src/__mocks__/axios.js b/client/src/__mocks__/axios.js index c295396124b8f0a928a0f4fd0c999c963f1b0ecc..40f0914f659785d8b4ceac257e64ceaf0ab3e847 100644 --- a/client/src/__mocks__/axios.js +++ b/client/src/__mocks__/axios.js @@ -1,4 +1,5 @@ export default { get: jest.fn().mockImplementation(), post: jest.fn().mockImplementation(), + defaults: { headers: { common: { Authorization: '' } } }, } diff --git a/client/src/actions/cities.test.ts b/client/src/actions/cities.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..d5298d29a010b619ed0c2b25973f8f8a9fb8710b --- /dev/null +++ b/client/src/actions/cities.test.ts @@ -0,0 +1,19 @@ +import mockedAxios from 'axios' +import expect from 'expect' // You can use any testing library +import configureMockStore from 'redux-mock-store' +import thunk from 'redux-thunk' +import { getCities } from './cities' + +const middlewares = [thunk] +const mockStore = configureMockStore(middlewares) + +it('dispatches no actions when failing to get cities', async () => { + console.log = jest.fn() + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.reject(new Error('getting cities failed')) + }) + const store = mockStore({ competitions: { filterParams: [] } }) + await getCities()(store.dispatch) + expect(store.getActions()).toEqual([]) + expect(console.log).toHaveBeenCalled() +}) diff --git a/client/src/actions/communication.ts b/client/src/actions/communication.ts deleted file mode 100644 index d0719cd320f73b11d8a8243130a67896a48bf6e0..0000000000000000000000000000000000000000 --- a/client/src/actions/communication.ts +++ /dev/null @@ -1,75 +0,0 @@ -import Types from './types.js' - -export function axiosPost( - path: any, - data: any, - config = undefined, - startCB = undefined, - successCB = undefined, - errorCB = undefined -) { - return { - type: Types.AXIOS_POST, - path, - data, - config, - startCB, - successCB, - errorCB, - } -} - -export function axiosPostSuccess(path: any, data: any, previousAction: any) { - return { - type: Types.AXIOS_POST_SUCCESS, - path, - data, - previousAction, - } -} - -export function axiosPostError(path: any, data: any, previousAction: any) { - return { - type: Types.AXIOS_POST_ERROR, - path, - data, - previousAction, - } -} - -export function axiosGet( - path: any, - data: any, - config = undefined, - startCB = undefined, - successCB = undefined, - errorCB = undefined -) { - return { - type: Types.AXIOS_GET, - path, - data, - config, - startCB, - successCB, - errorCB, - } -} - -export function axiosGetSuccess(path: any, data: any, previousAction: any) { - return { - type: Types.AXIOS_GET_SUCCESS, - path, - data, - previousAction, - } -} - -export function axiosGetError(path: any, data: any, previousAction: any) { - return { - type: Types.AXIOS_GET_ERROR, - path, - data, - previousAction, - } -} diff --git a/client/src/actions/competitions.test.ts b/client/src/actions/competitions.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..52be36acb658576e9b5c1ffc1b40394c338d0f5f --- /dev/null +++ b/client/src/actions/competitions.test.ts @@ -0,0 +1,73 @@ +import mockedAxios from 'axios' +import expect from 'expect' // You can use any testing library +import configureMockStore from 'redux-mock-store' +import thunk from 'redux-thunk' +import { CompetitionFilterParams } from './../interfaces/FilterParams' +import { getCompetitions, setFilterParams } from './competitions' +import Types from './types' + +const middlewares = [thunk] +const mockStore = configureMockStore(middlewares) + +it('dispatches correct actions when getting competitions', async () => { + const compRes: any = { + data: { + items: [ + { + id: 21, + name: 'ggff', + year: 2021, + style_id: 1, + city: { name: 'city_name', id: 5 }, + }, + { + id: 22, + name: 'sssss', + year: 2021, + style_id: 1, + city: { name: 'city_name', id: 5 }, + }, + ], + count: 2, + total_count: 3, + }, + } + + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.resolve(compRes) + }) + const expectedActions = [ + { type: Types.SET_COMPETITIONS, payload: compRes.data.items }, + { type: Types.SET_COMPETITIONS_TOTAL, payload: compRes.data.total_count }, + { type: Types.SET_COMPETITIONS_COUNT, payload: compRes.data.count }, + ] + const store = mockStore({ competitions: { filterParams: [] } }) + await getCompetitions()(store.dispatch, store.getState as any) + expect(store.getActions()).toEqual(expectedActions) +}) + +it('dispatches correct actions when setting filterParams', () => { + const testFilterParams: CompetitionFilterParams = { + page: 0, + pageSize: 3, + name: 'name', + cityId: 0, + styleId: 0, + year: 2000, + } + const expectedActions = [{ type: Types.SET_COMPETITIONS_FILTER_PARAMS, payload: testFilterParams }] + const store = mockStore({}) + setFilterParams(testFilterParams)(store.dispatch) + expect(store.getActions()).toEqual(expectedActions) +}) + +it('dispatches no actions when failing to get competitions', async () => { + console.log = jest.fn() + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.reject(new Error('getting competitions failed')) + }) + const store = mockStore({ competitions: { filterParams: [] } }) + await getCompetitions()(store.dispatch, store.getState as any) + expect(store.getActions()).toEqual([]) + expect(console.log).toHaveBeenCalled() +}) diff --git a/client/src/actions/presentation.test.ts b/client/src/actions/presentation.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..53ea4847dcf1aaf3e1ba9a04c643d1d44b5f27f0 --- /dev/null +++ b/client/src/actions/presentation.test.ts @@ -0,0 +1,59 @@ +import mockedAxios from 'axios' +import expect from 'expect' // You can use any testing library +import configureMockStore from 'redux-mock-store' +import thunk from 'redux-thunk' +import { Slide } from '../interfaces/Slide' +import { + getPresentationCompetition, + getPresentationTeams, + setCurrentSlide, + setCurrentSlideNext, + setCurrentSlidePrevious, +} from './presentation' +import Types from './types' + +const middlewares = [thunk] +const mockStore = configureMockStore(middlewares) + +it('dispatches no actions when failing to get competitions', async () => { + console.log = jest.fn() + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.reject(new Error('getting competitions failed')) + }) + const store = mockStore({ competitions: { filterParams: [] } }) + await getPresentationCompetition('0')(store.dispatch) + expect(store.getActions()).toEqual([]) + expect(console.log).toHaveBeenCalled() +}) + +it('dispatches no actions when failing to get teams', async () => { + console.log = jest.fn() + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.reject(new Error('getting teams failed')) + }) + const store = mockStore({ competitions: { filterParams: [] } }) + await getPresentationTeams('0')(store.dispatch) + expect(store.getActions()).toEqual([]) + expect(console.log).toHaveBeenCalled() +}) +it('dispatches correct actions when setting slide', () => { + const testSlide: Slide = { competition_id: 0, id: 5, order: 5, timer: 20, title: '' } + const expectedActions = [{ type: Types.SET_PRESENTATION_SLIDE, payload: testSlide }] + const store = mockStore({}) + setCurrentSlide(testSlide)(store.dispatch) + expect(store.getActions()).toEqual(expectedActions) +}) + +it('dispatches correct actions when setting previous slide', () => { + const expectedActions = [{ type: Types.SET_PRESENTATION_SLIDE_PREVIOUS }] + const store = mockStore({}) + setCurrentSlidePrevious()(store.dispatch) + expect(store.getActions()).toEqual(expectedActions) +}) + +it('dispatches correct actions when setting next slide', () => { + const expectedActions = [{ type: Types.SET_PRESENTATION_SLIDE_NEXT }] + const store = mockStore({}) + setCurrentSlideNext()(store.dispatch) + expect(store.getActions()).toEqual(expectedActions) +}) diff --git a/client/src/actions/roles.test.ts b/client/src/actions/roles.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..94ca142f23d93601e9fe5afc8df8766d7241e977 --- /dev/null +++ b/client/src/actions/roles.test.ts @@ -0,0 +1,19 @@ +import mockedAxios from 'axios' +import expect from 'expect' // You can use any testing library +import configureMockStore from 'redux-mock-store' +import thunk from 'redux-thunk' +import { getRoles } from './roles' + +const middlewares = [thunk] +const mockStore = configureMockStore(middlewares) + +it('dispatches no actions when failing to get roles', async () => { + console.log = jest.fn() + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.reject(new Error('getting roles failed')) + }) + const store = mockStore({ competitions: { filterParams: [] } }) + await getRoles()(store.dispatch) + expect(store.getActions()).toEqual([]) + expect(console.log).toHaveBeenCalled(); +}) diff --git a/client/src/actions/searchUser.test.ts b/client/src/actions/searchUser.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..66c155079a82d0efd21f0df949c669ab70f85c22 --- /dev/null +++ b/client/src/actions/searchUser.test.ts @@ -0,0 +1,74 @@ +import mockedAxios from 'axios' +import expect from 'expect' // You can use any testing library +import configureMockStore from 'redux-mock-store' +import thunk from 'redux-thunk' +import { UserFilterParams } from './../interfaces/FilterParams' +import { getSearchUsers, setFilterParams } from './searchUser' +import Types from './types' + +const middlewares = [thunk] +const mockStore = configureMockStore(middlewares) +it('dispatches correct actions when getting users', async () => { + const userRes: any = { + data: { + items: [ + { + id: 21, + name: 'ggff', + email: 'email@test.com', + year: 2021, + role_id: 1, + city_id: 0, + }, + { + id: 22, + name: 'sssss', + email: 'email@test.com', + year: 2021, + role_id: 1, + city_id: 0, + }, + ], + count: 2, + total_count: 3, + }, + } + + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.resolve(userRes) + }) + const expectedActions = [ + { type: Types.SET_SEARCH_USERS, payload: userRes.data.items }, + { type: Types.SET_SEARCH_USERS_TOTAL_COUNT, payload: userRes.data.total_count }, + { type: Types.SET_SEARCH_USERS_COUNT, payload: userRes.data.count }, + ] + const store = mockStore({ searchUsers: { filterParams: [] } }) + await getSearchUsers()(store.dispatch, store.getState as any) + expect(store.getActions()).toEqual(expectedActions) +}) + +it('dispatches correct actions when setting filterParams', () => { + const testFilterParams: UserFilterParams = { + page: 0, + pageSize: 3, + name: 'name', + cityId: 0, + email: 'email@test.com', + roleId: 0, + } + const expectedActions = [{ type: Types.SET_SEARCH_USERS_FILTER_PARAMS, payload: testFilterParams }] + const store = mockStore({}) + setFilterParams(testFilterParams)(store.dispatch) + expect(store.getActions()).toEqual(expectedActions) +}) + +it('dispatches no actions when failing to get users', async () => { + console.log = jest.fn() + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.reject(new Error('getting users failed')) + }) + const store = mockStore({ searchUsers: { filterParams: [] } }) + await getSearchUsers()(store.dispatch, store.getState as any) + expect(store.getActions()).toEqual([]) + expect(console.log).toHaveBeenCalled() +}) diff --git a/client/src/actions/types.ts b/client/src/actions/types.ts index c0b7b629afa54a43de4c8ef8ddfba2cc551aa5d4..a8736c4b26b751a48f6f01d888dc46e630c4f6ea 100644 --- a/client/src/actions/types.ts +++ b/client/src/actions/types.ts @@ -8,7 +8,7 @@ export default { SET_SEARCH_USERS_COUNT: 'SET_SEARCH_USERS_COUNT', SET_SEARCH_USERS_TOTAL_COUNT: 'SET_SEARCH_USERS_TOTAL_COUNT', SET_ERRORS: 'SET_ERRORS', - CLEAR_ERRORS: 'SET_ERRORS', + CLEAR_ERRORS: 'CLEAR_ERRORS', SET_UNAUTHENTICATED: 'SET_UNAUTHENTICATED', SET_AUTHENTICATED: 'SET_AUTHENTICATED', SET_COMPETITIONS: 'SET_COMPETITIONS', @@ -23,10 +23,4 @@ export default { SET_CITIES: 'SET_CITIES', SET_CITIES_TOTAL: 'SET_CITIES_TOTAL', SET_CITIES_COUNT: 'SET_CITIES_COUNT', - AXIOS_GET: 'AXIOS_GET', - AXIOS_GET_SUCCESS: 'AXIOS_GET_SUCCESS', - AXIOS_GET_ERROR: 'AXIOS_GET_ERROR', - AXIOS_POST: 'AXIOS_POST', - AXIOS_POST_SUCCESS: 'AXIOS_POST_SUCCESS', - AXIOS_POST_ERROR: 'AXIOS_POST_ERROR', } diff --git a/client/src/actions/user.test.ts b/client/src/actions/user.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..156b17183a76117f87ead4f049346d85e499fea0 --- /dev/null +++ b/client/src/actions/user.test.ts @@ -0,0 +1,81 @@ +import mockedAxios from 'axios' +import expect from 'expect' // You can use any testing library +import { createMemoryHistory } from 'history' +import configureMockStore from 'redux-mock-store' +import thunk from 'redux-thunk' +import Types from './types' +import { loginUser, logoutUser } from './user' + +const middlewares = [thunk] +const mockStore = configureMockStore(middlewares) + +it('dispatches correct actions when logging in user', async () => { + const loginRes: any = { + data: { + access_token: 'TEST_ACCESS_TOKEN', + }, + } + const userDataRes: any = { + data: { + name: 'test_name', + }, + } + ;(mockedAxios.post as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.resolve(loginRes) + }) + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.resolve(userDataRes) + }) + const expectedActions = [ + { type: Types.LOADING_UI }, + { type: Types.LOADING_USER }, + { type: Types.CLEAR_ERRORS }, + { type: Types.SET_USER, payload: { name: 'test_name' } }, + ] + const store = mockStore({}) + const history = createMemoryHistory() + await loginUser({ email: 'test@email.com', password: 'testpassword' }, history)(store.dispatch) + expect(store.getActions()).toEqual(expectedActions) +}) + +it('dispatches correct action when logging out user', async () => { + const store = mockStore({}) + await logoutUser()(store.dispatch) + expect(store.getActions()).toEqual([{ type: Types.SET_UNAUTHENTICATED }]) +}) + +it('dispatches correct action when failing to log in user', async () => { + console.log = jest.fn() + const errorMessage = 'getting teams failed' + ;(mockedAxios.post as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.reject({ response: { data: errorMessage } }) + }) + const store = mockStore({ competitions: { filterParams: [] } }) + const history = createMemoryHistory() + const expectedActions = [{ type: Types.LOADING_UI }, { type: Types.SET_ERRORS, payload: errorMessage }] + await loginUser({ email: 'test@email.com', password: 'testpassword' }, history)(store.dispatch) + expect(store.getActions()).toEqual(expectedActions) + expect(console.log).toHaveBeenCalled() +}) + +it('dispatches correct actions when failing to get user data', async () => { + console.log = jest.fn() + const loginRes: any = { + data: { + access_token: 'TEST_ACCESS_TOKEN', + }, + } + ;(mockedAxios.post as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.resolve(loginRes) + }) + const errorMessage = 'getting teams failed' + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.reject({ response: { data: errorMessage } }) + }) + const store = mockStore({ competitions: { filterParams: [] } }) + const history = createMemoryHistory() + const expectedActions = [{ type: Types.LOADING_UI }, { type: Types.LOADING_USER }, { type: Types.CLEAR_ERRORS }] + await loginUser({ email: 'test@email.com', password: 'testpassword' }, history)(store.dispatch) + expect(store.getActions()).toEqual(expectedActions) + expect(console.log).toHaveBeenCalled() +}) diff --git a/client/src/actions/user.ts b/client/src/actions/user.ts index 72d764c861db49024c5fbcf00e3291efc35b2609..30374ccafb38fd3c1f6e9a72378104b2cf2611fd 100644 --- a/client/src/actions/user.ts +++ b/client/src/actions/user.ts @@ -17,10 +17,10 @@ export const loginUser = (userData: AccountLoginModel, history: History) => asyn history.push('/admin') //redirecting to admin page after login success }) .catch((err) => { - console.error(err) + console.log(err) dispatch({ type: Types.SET_ERRORS, - payload: err.response.data, + payload: err && err.response && err.response.data, }) }) } @@ -30,7 +30,6 @@ export const getUserData = () => async (dispatch: AppDispatch) => { await axios .get('/users') .then((res) => { - console.log(res.data) dispatch({ type: Types.SET_USER, payload: res.data, diff --git a/client/src/pages/admin/regions/AddRegion.test.tsx b/client/src/pages/admin/regions/AddRegion.test.tsx new file mode 100644 index 0000000000000000000000000000000000000000..06b2052a55f14482dbe1474f03aad76894f2677f --- /dev/null +++ b/client/src/pages/admin/regions/AddRegion.test.tsx @@ -0,0 +1,16 @@ +import { render } from '@testing-library/react' +import React from 'react' +import { Provider } from 'react-redux' +import { BrowserRouter } from 'react-router-dom' +import store from '../../../store' +import AddRegion from './AddRegion' + +it('renders add region', () => { + render( + <BrowserRouter> + <Provider store={store}> + <AddRegion /> + </Provider> + </BrowserRouter> + ) +}) diff --git a/client/src/pages/admin/regions/Regions.test.tsx b/client/src/pages/admin/regions/Regions.test.tsx new file mode 100644 index 0000000000000000000000000000000000000000..7046bff04fc8fc9fc8cb3f08d0d140d0d475b5a3 --- /dev/null +++ b/client/src/pages/admin/regions/Regions.test.tsx @@ -0,0 +1,37 @@ +import { render } from '@testing-library/react' +import mockedAxios from 'axios' +import React from 'react' +import { Provider } from 'react-redux' +import { BrowserRouter } from 'react-router-dom' +import store from '../../../store' +import RegionManager from './Regions' + +it('renders region manager', () => { + const cityRes: any = { + data: { + items: [ + { + id: 1, + name: 'Link\u00f6ping', + }, + { + id: 2, + name: 'Stockholm', + }, + ], + count: 2, + total_count: 3, + }, + } + + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.resolve(cityRes) + }) + render( + <BrowserRouter> + <Provider store={store}> + <RegionManager /> + </Provider> + </BrowserRouter> + ) +}) diff --git a/client/src/pages/admin/users/AddUser.test.tsx b/client/src/pages/admin/users/AddUser.test.tsx new file mode 100644 index 0000000000000000000000000000000000000000..5c825570418e638403040ae3ba73423a01acda24 --- /dev/null +++ b/client/src/pages/admin/users/AddUser.test.tsx @@ -0,0 +1,16 @@ +import { render } from '@testing-library/react' +import React from 'react' +import { Provider } from 'react-redux' +import { BrowserRouter } from 'react-router-dom' +import store from '../../../store' +import EditUser from './EditUser' + +it('renders edit user', () => { + render( + <BrowserRouter> + <Provider store={store}> + <EditUser user={{ id: 0, name: '', email: '', role_id: 0, city_id: 0 }} /> + </Provider> + </BrowserRouter> + ) +}) diff --git a/client/src/pages/admin/users/EditUser.test.tsx b/client/src/pages/admin/users/EditUser.test.tsx new file mode 100644 index 0000000000000000000000000000000000000000..bf2b00900792996caa42100b61dac03138401c70 --- /dev/null +++ b/client/src/pages/admin/users/EditUser.test.tsx @@ -0,0 +1,16 @@ +import { render } from '@testing-library/react' +import React from 'react' +import { Provider } from 'react-redux' +import { BrowserRouter } from 'react-router-dom' +import store from '../../../store' +import AddUser from './AddUser' + +it('renders edit user', () => { + render( + <BrowserRouter> + <Provider store={store}> + <AddUser /> + </Provider> + </BrowserRouter> + ) +}) diff --git a/client/src/pages/admin/users/UserManager.test.tsx b/client/src/pages/admin/users/UserManager.test.tsx new file mode 100644 index 0000000000000000000000000000000000000000..f50cbed8ded2b12d3d487e96f1d185bca2a2cbf8 --- /dev/null +++ b/client/src/pages/admin/users/UserManager.test.tsx @@ -0,0 +1,43 @@ +import { render } from '@testing-library/react' +import mockedAxios from 'axios' +import React from 'react' +import { Provider } from 'react-redux' +import { BrowserRouter } from 'react-router-dom' +import store from '../../../store' +import UserManager from './UserManager' + +it('renders user manager', () => { + const userRes: any = { + data: { + items: [ + { + id: 1, + name: 'user1', + email: 'user1@email.com', + role_id: 0, + city_id: 0, + }, + { + id: 2, + name: 'Stockholm', + email: 'user2@email.com', + role_id: 0, + city_id: 0, + }, + ], + count: 2, + total_count: 3, + }, + } + + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.resolve(userRes) + }) + render( + <BrowserRouter> + <Provider store={store}> + <UserManager /> + </Provider> + </BrowserRouter> + ) +}) diff --git a/client/src/pages/admin/users/UserManager.tsx b/client/src/pages/admin/users/UserManager.tsx index 11a34128b9093784cb79cb7e19bada1a457e6e71..df9cdec0b1618291b3efbe903aea69f94351aaad 100644 --- a/client/src/pages/admin/users/UserManager.tsx +++ b/client/src/pages/admin/users/UserManager.tsx @@ -70,7 +70,6 @@ const UserManager: React.FC = (props: any) => { }, []) useEffect(() => { - console.log('asd') setEditAnchorEl(null) setAnchorEl(null) }, [users]) diff --git a/client/src/pages/presentationEditor/components/CompetitionSettings.test.tsx b/client/src/pages/presentationEditor/components/CompetitionSettings.test.tsx index e6f87e7e2beba3141c73d9bca5064d5f8e19ad4d..592581d4f8b3eaa884b7e0b409f39ee5ae8e5344 100644 --- a/client/src/pages/presentationEditor/components/CompetitionSettings.test.tsx +++ b/client/src/pages/presentationEditor/components/CompetitionSettings.test.tsx @@ -1,7 +1,7 @@ import { render } from '@testing-library/react' import React from 'react' -import CompetitionSettings from './CompetitionSettings' +import ImageComponentDisplay from './ImageComponentDisplay' -it('renders competition settings', () => { - render(<CompetitionSettings />) +it('renders image component display', () => { + render(<ImageComponentDisplay component={{ id: 0, x: 0, y: 0, w: 0, h: 0, type: 0, media_id: 0 }} />) }) diff --git a/client/src/pages/presentationEditor/components/ImageComponentDisplay.test.tsx b/client/src/pages/presentationEditor/components/ImageComponentDisplay.test.tsx new file mode 100644 index 0000000000000000000000000000000000000000..b726023b8e6079e7a631c2be396857e9ca0ef4c1 --- /dev/null +++ b/client/src/pages/presentationEditor/components/ImageComponentDisplay.test.tsx @@ -0,0 +1,7 @@ +import { render } from '@testing-library/react' +import React from 'react' +import ImageComponentDisplay from './ImageComponentDisplay' + +it('renders competition settings', () => { + render(<ImageComponentDisplay component={{ id: 0, x: 0, y: 0, w: 0, h: 0, media_id: 0, type: 2 }} />) +}) diff --git a/client/src/pages/presentationEditor/components/TextComponentDisplay.test.tsx b/client/src/pages/presentationEditor/components/TextComponentDisplay.test.tsx new file mode 100644 index 0000000000000000000000000000000000000000..8f61ee36f8bb86e9e422b135c76448c31d60a6d4 --- /dev/null +++ b/client/src/pages/presentationEditor/components/TextComponentDisplay.test.tsx @@ -0,0 +1,12 @@ +import { Editor } from '@tinymce/tinymce-react' +import { mount } from 'enzyme' +import React from 'react' +import TextComponentDisplay from './TextComponentDisplay' + +it('renders text component display', () => { + const testText = 'TEST' + const container = mount( + <TextComponentDisplay component={{ id: 0, x: 0, y: 0, w: 0, h: 0, text: testText, type: 2, font: '123123' }} /> + ) + expect(container.find(Editor).prop('initialValue')).toBe(testText) +}) diff --git a/client/src/reducers/citiesReducer.test.ts b/client/src/reducers/citiesReducer.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..320268952b997a799b1a6bf35191cfe88cdfd2b5 --- /dev/null +++ b/client/src/reducers/citiesReducer.test.ts @@ -0,0 +1,53 @@ +import Types from '../actions/types' +import citiesReducer from './citiesReducer' + +const initialState = { + cities: [], + total: 0, + count: 0, +} + +it('should return the initial state', () => { + expect(citiesReducer(undefined, {} as any)).toEqual(initialState) +}) + +it('should handle SET_CITIES', () => { + const testCities = [{ name: 'testName', id: 0 }] + expect( + citiesReducer(initialState, { + type: Types.SET_CITIES, + payload: testCities, + }) + ).toEqual({ + cities: testCities, + total: 0, + count: 0, + }) +}) + +it('should handle SET_CITIES_TOTAL', () => { + const testTotal = 123123 + expect( + citiesReducer(initialState, { + type: Types.SET_CITIES_TOTAL, + payload: testTotal, + }) + ).toEqual({ + cities: [], + total: testTotal, + count: 0, + }) +}) +it('should handle SET_CITIES_COUNT', () => { + const testCount = 456456 + expect( + citiesReducer(initialState, { + type: Types.SET_CITIES_COUNT, + payload: testCount, + }) + ).toEqual({ + cities: [], + total: 0, + count: testCount, + }) +}) diff --git a/client/src/reducers/presentationReducer.test.ts b/client/src/reducers/presentationReducer.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..cf4ded4132b1fa1cb1490a89584791032746385b --- /dev/null +++ b/client/src/reducers/presentationReducer.test.ts @@ -0,0 +1,193 @@ +import Types from '../actions/types' +import { RichSlide } from '../interfaces/ApiRichModels' +import { Slide } from '../interfaces/Slide' +import presentationReducer from './presentationReducer' + +const initialState = { + competition: { + name: '', + id: 0, + city: { + id: 0, + name: '', + }, + slides: [], + year: 0, + teams: [], + }, + slide: { + competition_id: 0, + id: 0, + order: 0, + timer: 0, + title: '', + }, + teams: [], +} + +it('should return the initial state', () => { + expect(presentationReducer(undefined, {} as any)).toEqual(initialState) +}) + +it('should handle SET_PRESENTATION_COMPETITION', () => { + const testCompetition = { + name: 'testCompName', + id: 4, + city: { + id: 3, + name: 'testCityName', + }, + slides: [{ id: 20 }], + year: 1999, + teams: [], + } + expect( + presentationReducer(initialState, { + type: Types.SET_PRESENTATION_COMPETITION, + payload: testCompetition, + }) + ).toEqual({ + competition: testCompetition, + slide: testCompetition.slides[0], + teams: [], + }) +}) + +it('should handle SET_PRESENTATION_TEAMS', () => { + const testTeams = [ + { + name: 'testTeamName1', + id: 3, + }, + { + name: 'testTeamName2', + id: 5, + }, + ] + expect( + presentationReducer(initialState, { + type: Types.SET_PRESENTATION_TEAMS, + payload: testTeams, + }) + ).toEqual({ + competition: initialState.competition, + slide: initialState.slide, + teams: testTeams, + }) +}) + +it('should handle SET_PRESENTATION_SLIDE', () => { + const testSlide = [ + { + competition_id: 20, + id: 4, + order: 3, + timer: 123, + title: 'testSlideTitle', + }, + ] + expect( + presentationReducer(initialState, { + type: Types.SET_PRESENTATION_SLIDE, + payload: testSlide, + }) + ).toEqual({ + competition: initialState.competition, + slide: testSlide, + teams: initialState.teams, + }) +}) + +describe('should handle SET_PRESENTATION_SLIDE_PREVIOUS', () => { + it('by changing slide to the previous if there is one', () => { + const testPresentationState = { + competition: { + ...initialState.competition, + slides: [ + { competition_id: 0, order: 0 }, + { competition_id: 0, order: 1 }, + ] as RichSlide[], + }, + teams: initialState.teams, + slide: { competition_id: 0, order: 1 } as Slide, + } + expect( + presentationReducer(testPresentationState, { + type: Types.SET_PRESENTATION_SLIDE_PREVIOUS, + }) + ).toEqual({ + competition: testPresentationState.competition, + slide: testPresentationState.competition.slides[0], + teams: testPresentationState.teams, + }) + }) + it('by not changing slide if there is no previous one', () => { + const testPresentationState = { + competition: { + ...initialState.competition, + slides: [ + { competition_id: 0, order: 0 }, + { competition_id: 0, order: 1 }, + ] as RichSlide[], + }, + teams: initialState.teams, + slide: { competition_id: 0, order: 0 } as Slide, + } + expect( + presentationReducer(testPresentationState, { + type: Types.SET_PRESENTATION_SLIDE_PREVIOUS, + }) + ).toEqual({ + competition: testPresentationState.competition, + slide: testPresentationState.competition.slides[0], + teams: testPresentationState.teams, + }) + }) +}) + +describe('should handle SET_PRESENTATION_SLIDE_NEXT', () => { + it('by changing slide to the next if there is one', () => { + const testPresentationState = { + competition: { + ...initialState.competition, + slides: [ + { competition_id: 0, order: 0 }, + { competition_id: 0, order: 1 }, + ] as RichSlide[], + }, + teams: initialState.teams, + slide: { competition_id: 0, order: 0 } as Slide, + } + expect( + presentationReducer(testPresentationState, { + type: Types.SET_PRESENTATION_SLIDE_NEXT, + }) + ).toEqual({ + competition: testPresentationState.competition, + slide: testPresentationState.competition.slides[1], + teams: testPresentationState.teams, + }) + }) + it('by not changing slide if there is no next one', () => { + const testPresentationState = { + competition: { + ...initialState.competition, + slides: [ + { competition_id: 0, order: 0 }, + { competition_id: 0, order: 1 }, + ] as RichSlide[], + }, + teams: initialState.teams, + slide: { competition_id: 0, order: 1 } as Slide, + } + expect( + presentationReducer(testPresentationState, { + type: Types.SET_PRESENTATION_SLIDE_NEXT, + }) + ).toEqual({ + competition: testPresentationState.competition, + slide: testPresentationState.competition.slides[1], + teams: testPresentationState.teams, + }) + }) +}) diff --git a/client/src/reducers/uiReducer.test.ts b/client/src/reducers/uiReducer.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..cea5c3ad137dc8f4fbcc2bb88ccd136fd487f5f9 --- /dev/null +++ b/client/src/reducers/uiReducer.test.ts @@ -0,0 +1,64 @@ +import Types from '../actions/types' +import userReducer from './userReducer' + +const initialState = { + authenticated: false, + loading: false, + userInfo: null, +} + +it('should return the initial state', () => { + expect(userReducer(undefined, {} as any)).toEqual(initialState) +}) + +it('should handle SET_AUTHENTICATED', () => { + expect( + userReducer(initialState, { + type: Types.SET_AUTHENTICATED, + }) + ).toEqual({ + authenticated: true, + loading: initialState.loading, + userInfo: initialState.userInfo, + }) +}) + +it('should handle SET_UNAUTHENTICATED', () => { + expect( + userReducer(initialState, { + type: Types.SET_UNAUTHENTICATED, + }) + ).toEqual(initialState) +}) + +it('should handle SET_USER', () => { + const testUserInfo = { + name: 'testName', + email: 'test@email.com', + role: { id: 0, name: 'roleName' }, + city: { id: 0, name: 'cityName' }, + id: 0, + } + expect( + userReducer(initialState, { + type: Types.SET_USER, + payload: testUserInfo, + }) + ).toEqual({ + authenticated: true, + loading: false, + userInfo: testUserInfo, + }) +}) + +it('should handle LOADING_USER', () => { + expect( + userReducer(initialState, { + type: Types.LOADING_USER, + }) + ).toEqual({ + loading: true, + authenticated: initialState.authenticated, + userInfo: initialState.userInfo, + }) +}) diff --git a/client/src/reducers/userReducer.test.ts b/client/src/reducers/userReducer.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..6ccf026801679367515f6fcc7756554e54845889 --- /dev/null +++ b/client/src/reducers/userReducer.test.ts @@ -0,0 +1,45 @@ +import Types from '../actions/types' +import uiReducer from './uiReducer' + +const initialState = { + loading: false, + errors: null, +} + +it('should return the initial state', () => { + expect(uiReducer(undefined, {} as any)).toEqual(initialState) +}) + +it('should handle SET_ERRORS', () => { + const testError = { message: 'errorMessage' } + expect( + uiReducer(initialState, { + type: Types.SET_ERRORS, + payload: testError, + }) + ).toEqual({ + loading: false, + errors: testError, + }) +}) + +it('should handle CLEAR_ERRORS', () => { + expect( + uiReducer(initialState, { + type: Types.CLEAR_ERRORS, + }) + ).toEqual({ + loading: false, + errors: null, + }) +}) +it('should handle LOADING_UI', () => { + expect( + uiReducer(initialState, { + type: Types.LOADING_UI, + }) + ).toEqual({ + loading: true, + errors: initialState.errors, + }) +}) diff --git a/client/src/utils/checkAuthentication.test.ts b/client/src/utils/checkAuthentication.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..901f331d6cc32c68e2a87c32338e879719c736af --- /dev/null +++ b/client/src/utils/checkAuthentication.test.ts @@ -0,0 +1,59 @@ +import mockedAxios from 'axios' +import Types from '../actions/types' +import store from '../store' +import { CheckAuthentication } from './checkAuthentication' + +it('dispatches correct actions when auth token is ok', async () => { + const userRes: any = { + data: { + name: 'username', + }, + } + + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.resolve(userRes) + }) + + const spy = jest.spyOn(store, 'dispatch') + const testToken = + 'Bearer eyJ0eXAiOiJeyJ0eXAiOiJKV1QeyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2MTgzMDQ5MzksImV4cCI6MzI1MTI1MjU3NTcsImF1ZCI6Ind3dy5leGFtcGxlLmNvbSIsInN1YiI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJHaXZlbk5hbWUiOiJKb2hubnkiLCJTdXJuYW1lIjoiUm9ja2V0IiwiRW1haWwiOiJqcm9ja2V0QGV4YW1wbGUuY29tIiwiUm9sZSI6WyJNYW5hZ2VyIiwiUHJvamVjdCBBZG1pbmlzdHJhdG9yIl19.DrOOcCo5jMR-SNERE0uRp_kolQ2HjX8-hHXYEMnIxSceyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2MTgzMDQ5MzksImV4cCI6MzI1MTI1MjU3NTcsImF1ZCI6Ind3dy5leGFtcGxlLmNvbSIsInN1YiI6Impyb2NrZXRA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2MTgzMDQ5MzksImV4cCI6MzI1MTI1MjU3NTcsImF1ZCI6Ind3dy5leGFtcGxlLmNvbSIsInN1YiI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJHaXZlbk5hbWUiOiJKb2hubnkiLCJTdXJuYW1lIjoiUm9ja2V0IiwiRW1haWwiOiJqcm9ja2V0QGV4YW1wbGUuY29tIiwiUm9sZSI6WyJNYW5hZ2VyIiwiUHJvamVjdCBBZG1pbmlzdHJhdG9yIl19.DrOOcCo5jMR-SNERE0uRp_kolQ2HjX8-hHXYEMnIxScKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2MTgzMDQ5MzksImV4cCI6MzI1MTI1MjU3NTcsImF1ZCI6Ind3dy5leGFtcGxlLmNvbSIsInN1YiI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJHaXZlbk5hbWUiOiJKb2hubnkiLCJTdXJuYW1lIjoiUm9ja2V0IiwiRW1haWwiOiJqcm9ja2V0QGV4YW1wbGUuY29tIiwiUm9sZSI6WyJNYW5hZ2VyIiwiUHJvamVjdCBBZG1pbmlzdHJhdG9yIl19.DrOOcCo5jMR-SNERE0uRp_kolQ2HjX8-hHXYEMnIxSc' + localStorage.setItem('token', testToken) + await CheckAuthentication() + expect(spy).toBeCalledWith({ type: Types.LOADING_USER }) + expect(spy).toBeCalledWith({ type: Types.SET_AUTHENTICATED }) + expect(spy).toBeCalledWith({ type: Types.SET_USER, payload: userRes.data }) + expect(spy).toBeCalledTimes(3) +}) + +it('dispatches correct actions when getting user data fails', async () => { + console.log = jest.fn() + ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { + return Promise.reject(new Error('failed getting user data')) + }) + + const spy = jest.spyOn(store, 'dispatch') + const testToken = + 'Bearer eyJ0eXAiOiJeyJ0eXAiOiJKV1QeyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxp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ja2V0QGV4YW1wbGUuY29tIiwiUm9sZSI6WyJNYW5hZ2VyIiwiUHJvamVjdCBBZG1pbmlzdHJhdG9yIl19.DrOOcCo5jMR-SNERE0uRp_kolQ2HjX8-hHXYEMnIxSc' + localStorage.setItem('token', testToken) + await CheckAuthentication() + expect(spy).toBeCalledWith({ type: Types.LOADING_USER }) + expect(spy).toBeCalledWith({ type: Types.SET_UNAUTHENTICATED }) + expect(spy).toBeCalledTimes(2) + expect(console.log).toHaveBeenCalled() +}) + +it('dispatches no actions when no token exists', async () => { + const spy = jest.spyOn(store, 'dispatch') + await CheckAuthentication() + expect(spy).not.toBeCalled() +}) + +it('dispatches correct actions when token is expired', async () => { + const testToken = + 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2MTgzMDY1MTUsImV4cCI6MTU4Njc3MDUxNSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsIkdpdmVuTmFtZSI6IkpvaG5ueSIsIlN1cm5hbWUiOiJSb2NrZXQiLCJFbWFpbCI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IEFkbWluaXN0cmF0b3IiXX0.R5-oWGGumd-YWPoKyziJmVB8SdX6B9SsV6m7novIfgg' + localStorage.setItem('token', testToken) + const spy = jest.spyOn(store, 'dispatch') + await CheckAuthentication() + expect(spy).toBeCalledWith({ type: Types.SET_UNAUTHENTICATED }) + expect(spy).toBeCalledTimes(1) +}) diff --git a/client/src/utils/checkAuthentication.ts b/client/src/utils/checkAuthentication.ts index 83b735543422b79e6c2323243d8fa1468566cbf4..231781543c4b8c3088585568fbeedbcab4e16f41 100644 --- a/client/src/utils/checkAuthentication.ts +++ b/client/src/utils/checkAuthentication.ts @@ -15,7 +15,6 @@ export const CheckAuthentication = async () => { if (decodedToken.exp * 1000 >= Date.now()) { axios.defaults.headers.common['Authorization'] = authToken store.dispatch({ type: Types.LOADING_USER }) - console.log('loading user') await axios .get('/users') .then((res) => { @@ -26,7 +25,7 @@ export const CheckAuthentication = async () => { }) }) .catch((error) => { - console.error(error) + console.log(error) UnAuthorized() }) } else {