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

Feature/counters #107

Merged
merged 5 commits into from Jun 14, 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 Summary Actions and Unit Tests
  • Loading branch information
IAmThePan committed Jun 14, 2018
commit bb5e0064dd9f9e85feaaf9b954282efeda5e9224
@@ -12,7 +12,6 @@
*/

import {
GET_SUMMARY_DATA,
GET_CLIQZ_MODULE_DATA,
UPDATE_TRACKER_COUNTS,
UPDATE_GHOSTERY_PAUSED,
@@ -22,12 +21,12 @@ import {
import { sendMessageInPromise } from '../utils/msg';

/**
* Fetch cliqz modules data from background
* Fetch Cliqz Modules data from background
* @return {Object} dispatch
*/
export function getCliqzModuleData(tabId) {
export function getCliqzModuleData() {
return function (dispatch) {
sendMessageInPromise('getCliqzModuleData').then((data) => {
return sendMessageInPromise('getCliqzModuleData').then((data) => {
dispatch({
type: GET_CLIQZ_MODULE_DATA,
data,
@@ -16,7 +16,7 @@ import thunk from 'redux-thunk';
import * as msg from '../../utils/msg';
import * as summaryActions from '../SummaryActions';
import {
GET_SUMMARY_DATA,
GET_CLIQZ_MODULE_DATA,
UPDATE_TRACKER_COUNTS,
UPDATE_GHOSTERY_PAUSED,
UPDATE_SITE_POLICY,
@@ -26,10 +26,10 @@ import {
const middlewares = [thunk];
const mockStore = configureStore(middlewares);

const testData = { test: true };
const testData = { adblock: {}, antitracking: {} };
msg.sendMessageInPromise = jest.fn(messageType => new Promise((resolve, reject) => {
switch (messageType) {
case 'getPanelData':
case 'getCliqzModuleData':
resolve(testData);
break;
default:
@@ -38,6 +38,19 @@ msg.sendMessageInPromise = jest.fn(messageType => new Promise((resolve, reject)
}));

describe('app/panel/actions/SummaryActions.js', () => {
test('getCliqzModuleData action should return correctly', () => {
const initialState = {};
const store = mockStore(initialState);

const data = testData;
const expectedPayload = { data, type: GET_CLIQZ_MODULE_DATA };

return store.dispatch(summaryActions.getCliqzModuleData()).then(() => {
const actions = store.getActions();
expect(actions).toEqual([expectedPayload]);
});
});

test('updateTrackerCounts action should return correctly', () => {
const initialState = {};
const store = mockStore(initialState);
@@ -66,6 +66,7 @@ class Summary extends React.Component {
this.setTrackerLatency(this.props);
this.updateSiteNotScanned(this.props);
}

/**
* Lifecycle event
*/
@@ -15,6 +15,7 @@ import Immutable from 'seamless-immutable';
import summaryReducer from '../summary';
import {
GET_SUMMARY_DATA,
GET_CLIQZ_MODULE_DATA,
UPDATE_TRACKER_COUNTS,
UPDATE_GHOSTERY_PAUSED,
UPDATE_SITE_POLICY
@@ -41,6 +42,25 @@ describe('app/panel/reducers/summary.js', () => {
expect(summaryReducer(undefined, {})).toEqual(initialState);
});

test('reducer correctly handles GET_SUMMARY_DATA', () => {
const data = { test: true };
const action = { data, type: GET_SUMMARY_DATA };
const initState = Immutable({});

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

test('reducer correctly handles GET_CLIQZ_MODULE_DATA', () => {
const data = { adblock: {}, antitracking: {} };
const action = { data, type: GET_CLIQZ_MODULE_DATA };
const initState = Immutable({});

expect(summaryReducer(initState, action)).toEqual({
adBlock: {},
antiTracking: {},
});
});

test('reducer correctly handles UPDATE_GHOSTERY_PAUSED', () => {
const data = { time: null, ghosteryPaused: true };
const action = { data, type: UPDATE_GHOSTERY_PAUSED };
ProTip! Use n and p to navigate between commits in a pull request.