Skip to content

Commit

Permalink
fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flacoman91 committed Sep 19, 2024
1 parent 00b2a6d commit 007f8a5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 78 deletions.
15 changes: 0 additions & 15 deletions src/api/message/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,3 @@ export function onResponse(config, response, successAction, store) {

store.dispatch(successAction(actionPayload));
}

// /**
// * Reverses the logic applied in the extract*** functions
// *
// * @param {object} params - the parameters returned from an API call
// * @returns {object} a version of the store based on the params
// */
// export function parseParamsToStore(params) {
// return {
// comparisons: parsers.parseParamsToCompare(params),
// query: parsers.parseParamsToQuery(params),
// trends: parsers.parseParamsToTrends(params),
// viewModel: parsers.parseParamsToViewModel(params),
// };
// }
42 changes: 3 additions & 39 deletions src/api/params/params.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* eslint-disable camelcase */

// import { defaultSort } from '../../../constants';
// import { validateDatePeriod } from '../../../reducers/utils/dateReducers';
import { capitalize, clamp, removeNullProperties } from '../../utils';
// const isEqual = require('react-fast-compare');
import { clamp } from '../../utils';
import { enforceValues } from '../../utils/reducers';
// ----------------------------------------------------------------------------
// return parameter objects

Expand Down Expand Up @@ -108,7 +105,7 @@ export function extractReducerAttributes(reducer, attributes) {
export function extractQueryParams(queryState) {
const query = queryState;
const params = {
searchField: query.searchField ?? 'all',
field: enforceValues(query.searchField, 'searchField'),
// edge case for doc complaint override in
// actions/complaints.js
frm:
Expand Down Expand Up @@ -176,7 +173,6 @@ export function extractQueryParams(queryState) {
// validateDatePeriod(query.dateRange);
// }
//
//
// // Handle sort
// /* istanbul ignore else */
// if (sort) {
Expand Down Expand Up @@ -213,35 +209,3 @@ export function extractTrendsParams(state) {

return params;
}

/**
* Reverses extractTrendsParams
*
* @param {object} params - the parameters returned from the API
* @returns {object} a version of the trends state
*/
export function parseParamsToTrends(params) {
const { focus, lens, subLens, trend_depth } = params;
const trends = {
focus,
lens,
subLens,
trend_depth,
};

return removeNullProperties(trends);
}

/**
* Handles the view model specific params
*
* @param {object} params - the parameters returned from the API
* @returns {object} a version of the view model state
*/
export function parseParamsToViewModel(params) {
const { trend_interval: interval } = params;

return removeNullProperties({
interval: capitalize(interval),
});
}
26 changes: 5 additions & 21 deletions src/api/params/params.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe('api.v2.params', () => {
it('handles missing dates', () => {
actual = sut.extractAggregationParams(fixtureStore);
expect(actual).toEqual({
date_received_min: '2011-07-21',
date_received_max: '2018-01-01',
field: 'all',
});
});
Expand Down Expand Up @@ -48,10 +50,10 @@ describe('api.v2.params', () => {
beforeEach(() => {
fixtureStore.trends = {
lens: 'ItemName',
trend_depth: 10,
trendDepth: 10,
};
fixtureStore.viewModel = {
interval: 'Quantum',
fixtureStore.query = {
dateInterval: 'quantum',
};
});

Expand Down Expand Up @@ -106,23 +108,5 @@ describe('api.v2.params', () => {
expect(actual.search_after).toEqual('1__12345');
});
});

describe('parseParamsToTrends', () => {
it('reverses extractTrendsParams', () => {
const forward = sut.extractTrendsParams(fixtureStore);
const reversed = sut.parseParamsToTrends(forward);
expect(fixtureStore.trends).toEqual(expect.objectContaining(reversed));
});
});

describe('parseParamsToViewModel', () => {
it('reverses extractTrendsParams', () => {
const forward = sut.extractTrendsParams(fixtureStore);
const reversed = sut.parseParamsToViewModel(forward);
expect(fixtureStore.viewModel).toEqual(
expect.objectContaining(reversed),
);
});
});
});
});
5 changes: 3 additions & 2 deletions src/middleware/synchUrl/synchUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ function getQueryAttrs(tab) {
if (tab === MODE_LIST) {
return defaultParams.concat(['size', 'page', 'sort']);
}
// if (tab === MODE_TRENDS) {
if (tab === MODE_TRENDS) {
return defaultParams.concat(['dateInterval']);
}
return defaultParams;
// }
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/reducers/query/querySlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,13 @@ export const querySlice = createSlice({
.addCase('routes/routeChanged', (state, action) => {
const { params } = action.payload;
// Set some variables from the URL
const keys = ['dateRange', 'searchField', 'searchText', 'sort'];
const keys = [
'dateRange',
'dateInterval',
'searchField',
'searchText',
'sort',
];
keys.forEach((item) => {
if (params[item]) {
state[item] = enforceValues(params[item], item);
Expand Down

0 comments on commit 007f8a5

Please sign in to comment.