diff --git a/client/src/App.test.js b/client/src/App.test.js index a754b201bf9c6caf5271293588189fb4210f99d1..7743a98da02df3403e9f8d3eab611f75ab475098 100644 --- a/client/src/App.test.js +++ b/client/src/App.test.js @@ -1,9 +1,17 @@ import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; +import { Provider } from 'react-redux'; +import store from './redux/store'; +import renderer from 'react-test-renderer'; it('renders without crashing', () => { const div = document.createElement('div'); - ReactDOM.render(<App />, div); + ReactDOM.render(<Provider store={store}> <App /></Provider>, div); ReactDOM.unmountComponentAtNode(div); }); + +it('App renders correctly', () => { + const tree = renderer.create(<Provider store={store} ><App /></Provider>).toJSON(); + expect(tree).toMatchSnapshot(); +}) diff --git a/client/src/components/Filter.test.js b/client/src/components/Filter.test.js new file mode 100644 index 0000000000000000000000000000000000000000..0ef6aef106eda844bb09b0e202b601a8b48df405 --- /dev/null +++ b/client/src/components/Filter.test.js @@ -0,0 +1,11 @@ +import React from 'react'; +import Filter from './Filter'; +import renderer from 'react-test-renderer'; +import { Provider } from 'react-redux'; +import store from '../redux/store'; + + +it('Filter renders correctly', () => { + const tree = renderer.create(<Provider store={store} ><Filter /></Provider>).toJSON(); + expect(tree).toMatchSnapshot(); +}) diff --git a/client/src/components/MovieDetail.test.js b/client/src/components/MovieDetail.test.js new file mode 100644 index 0000000000000000000000000000000000000000..e16abb6703df56f292fe4ef6af3cf9bca17ccd51 --- /dev/null +++ b/client/src/components/MovieDetail.test.js @@ -0,0 +1,11 @@ +import React from 'react'; +import MovieDetail from './MovieDetail'; +import renderer from 'react-test-renderer'; +import { Provider } from 'react-redux'; +import store from '../redux/store'; + + +it('Movie detail renders correctly', () => { + const tree = renderer.create(<Provider store={store} ><MovieDetail /></Provider>).toJSON(); + expect(tree).toMatchSnapshot(); +}) diff --git a/client/src/components/SortButton.test.js b/client/src/components/SortButton.test.js new file mode 100644 index 0000000000000000000000000000000000000000..a8fe3d886e7d4faec2c0359b1071c5da32f1920c --- /dev/null +++ b/client/src/components/SortButton.test.js @@ -0,0 +1,11 @@ +import React from 'react'; +import SortButton from './SortButton'; +import renderer from 'react-test-renderer'; +import { Provider } from 'react-redux'; +import store from '../redux/store'; + + +it('Sort button renders correctly', () => { + const tree = renderer.create(<Provider store={store} ><SortButton /></Provider>).toJSON(); + expect(tree).toMatchSnapshot(); +}) diff --git a/client/src/redux/actions.test.js b/client/src/redux/actions.test.js new file mode 100644 index 0000000000000000000000000000000000000000..f36b64f2a51c4b8d31c2f3020ff27210008bfa5b --- /dev/null +++ b/client/src/redux/actions.test.js @@ -0,0 +1,64 @@ +import * as actions from './actions'; +import { ORDER, SORT } from '../constants'; + +describe('acions', () => { + it('Should create an action to switch order', () => { + const expectedAction = { + type: actions.SELECT_ORDER, + payload: { + orderType: ORDER.DESC + } + } + expect(actions.selectOrder(ORDER.ASC)).toEqual(expectedAction); + }) + + it('Should create an action to change sort type', () => { + const expectedAction = { + type: actions.SELECT_SORT, + payload: { + sortType: SORT.TITLE + } + } + expect(actions.selectSort(SORT.TITLE)).toEqual(expectedAction); + }) + + it('Should create an action to change the filter state (toggle it)', () => { + const expectedAction = { + type: actions.FILTER_STATE, + bool: true + } + expect(actions.filterState(false)).toEqual(expectedAction); + }) + + it('Should create an action to change the filter rating', () => { + const expectedAction = { + type: actions.FILTER_RATED, + rating: 'R' + } + expect(actions.filterRated('R')).toEqual(expectedAction); + }) + + it('Should create an action to change the filter state (toggle it)', () => { + const expectedAction = { + type: actions.FILTER_GENRE, + genre: 'Crime' + } + expect(actions.filterGenre('Crime')).toEqual(expectedAction); + }) + + it('Should create an action to change a ', () => { + const expectedAction = { + type: actions.FILTER_LANGUAGE, + language: 'Norwegian' + } + expect(actions.filterLanguage('Norwegian')).toEqual(expectedAction); + }) + + it('Should create an action to set a current movie', () => { + const expectedAction = { + type: actions.CURRENT_MOVIE, + title: 'lorem ipsum' + } + expect(actions.currentMovie('lorem ipsum')).toEqual(expectedAction); + }) +}) diff --git a/client/src/redux/reducers/reducers.test.js b/client/src/redux/reducers/reducers.test.js new file mode 100644 index 0000000000000000000000000000000000000000..1fdff5189c4f4e8ec4ca68b790f25f025c97bdc8 --- /dev/null +++ b/client/src/redux/reducers/reducers.test.js @@ -0,0 +1,88 @@ +import order from './order'; +import sort from './sort'; +import currentReducer from './current'; +import filter from './filter'; +import { ORDER, SORT } from '../../constants'; +import * as actions from '../actions'; + +describe('order reducer', () => { + it('should return the initial state', () => { + expect(order(undefined, {})).toEqual(ORDER.ASC) + }) + + it('should handle an order change', () => { + expect(order(ORDER.DESC, { + type: actions.SELECT_ORDER, + payload: { + orderType: ORDER.DESC + } + })).toEqual(ORDER.DESC) + }) +}) + + + +describe('sort reducer', () => { + it('should return the initial state', () => { + expect(sort(undefined, {})).toEqual(SORT.TITLE) + }) + it('should handle a sort change', () => { + expect(sort(SORT.TITLE, { + type: actions.SELECT_SORT, + payload: { sortType: SORT.YEAR } + })).toEqual(SORT.YEAR) + }) +}) + + + + +describe('filter reducer', () => { + it('should return the initial state', () => { + expect(filter(undefined, {})).toEqual({ + filter_state : false, + filter_rated : [], + filter_language:Â [], + filter_genre:[] + }) + }) + it('should handle change in filters', () => { + expect(filter(undefined, { + type: actions.FILTER_RATED, + rating: 'PG' + })).toEqual({ + filter_state : false, + filter_rated : ['PG'], + filter_language:Â [], + filter_genre:[] + }) + expect(filter({ + filter_state : false, + filter_rated : ['PG'], + filter_language:Â [], + filter_genre:[] + }, { + type: actions.FILTER_RATED, + rating: 'R' + })).toEqual({ + filter_state : false, + filter_rated : ['PG', 'R'], + filter_language:Â [], + filter_genre:[] + }) + }) +}) + + +describe('current movie reducer', () => { + it('should return the initial state', () => { + expect(currentReducer(undefined, {})).toEqual({ + current_title : "" + }) + }) + it('should handle an input', () => { + expect(currentReducer({ current_title: "EARLIER" }, { title: "LATER", type: actions.CURRENT_MOVIE } )).toEqual({ + current_title: "LATER" + }) + }) +})