Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-862: Unit tests for the Panel #31

Merged
merged 3 commits into from Apr 12, 2018
Merged
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Update reducers to test for immutable state

  • Loading branch information
IAmThePan committed Apr 10, 2018
commit 7a6b984accb60134a3d2ae3c6aec404b58cb28df
@@ -11,6 +11,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0
*/

import Immutable from 'seamless-immutable';
import summaryReducer from '../summary';
import {
GET_SUMMARY_DATA,
@@ -20,7 +21,7 @@ import {
} from '../../constants/constants';

// Copied from app/panel/reducers/summary.js
const initialState = {
const initialState = Immutable({
alertCounts: {
total: 0,
},
@@ -33,7 +34,7 @@ const initialState = {
blocked: 0,
},
tab_id: 0,
};
});

describe('app/panel/reducers/summary.js', () => {
test('initial state is correct', () => {
@@ -43,17 +44,19 @@ describe('app/panel/reducers/summary.js', () => {
test('reducer correctly handles GET_SUMMARY_DATA', () => {
const data = { test: true };
const action = { data, type: GET_SUMMARY_DATA };
const initState = Immutable({});

expect(summaryReducer({}, action)).toEqual(data);
expect(summaryReducer(initState, action)).toEqual(data);
});

test('reducer correctly handles UPDATE_GHOSTERY_PAUSED', () => {
const data = { time: null, ghosteryPaused: true };
const action = { data, type: UPDATE_GHOSTERY_PAUSED };

const updatedState = initialState;
updatedState.paused_blocking = data.ghosteryPaused;
updatedState.paused_blocking_timeout = data.time;
const updatedState = Immutable.merge(initialState, {
paused_blocking: data.ghosteryPaused,
paused_blocking_timeout: data.time
});

expect(summaryReducer(undefined, action)).toEqual(updatedState);
});
@@ -62,12 +65,12 @@ describe('app/panel/reducers/summary.js', () => {
const data = { type: 'blacklist' };
const action = { data, type: UPDATE_SITE_POLICY };

const initState = {
const initState = Immutable({
pageHost: 'www.cnn.com',
sitePolicy: 2,
site_blacklist: [],
site_whitelist: ['cnn.com']
};
});

expect(summaryReducer(initState, action)).toEqual({
pageHost: 'www.cnn.com',
@@ -85,8 +88,9 @@ describe('app/panel/reducers/summary.js', () => {
num_ss_allowed: 2
};
const action = { data, type: UPDATE_TRACKER_COUNTS };
const initState = Immutable({});

expect(summaryReducer({}, action)).toEqual({
expect(summaryReducer(initState, action)).toEqual({
trackerCounts: {
blocked: 3,
allowed: 5,

Some generated files are not rendered by default. Learn more.

@@ -94,6 +94,7 @@
"read-file": "^0.2.0",
"redux-mock-store": "^1.5.1",
"sass-loader": "^6.0.6",
"seamless-immutable": "^7.1.3",
"sinon": "^4.2.2",
"sinon-chrome": "^2.2.1",
"style-loader": "^0.19.0",
ProTip! Use n and p to navigate between commits in a pull request.