Skip to content

Commit

Permalink
fix app test
Browse files Browse the repository at this point in the history
complaints.spec fix

fixing unit test coverage

updating unit tests

update unit test, remove dead code

update selectors, fix trends test

fixing a test

remove unused isfromexternal param

comment out unused selectors

remove unused code

remove unused code

remove unused code

remove unused code

adding unit test for search component

fix comment

updating test

fix cypress test in doc detail view

fixing test

fixing some unit tests

revert cypress fixes

fixing tests

adding pager reset when date change

fixing test

fixing unit tests

fixing unit tests

fixing unit tests

add dist

squash fixtures, remove mutation observer, doesnt seem like it is needed

squash
  • Loading branch information
flacoman91 committed Oct 16, 2024
1 parent cfdd8aa commit 7192be5
Show file tree
Hide file tree
Showing 52 changed files with 4,000 additions and 689 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
\*_/**fixtures**/_.js
**fixtures**/_.json
serviceWorker.js
8 changes: 4 additions & 4 deletions cypress/e2e/document/document.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ describe('Document View', () => {
cy.intercept(request, fixture).as('getAggsResults');

request =
'?**&field=all&has_narrative=true&search_term=pizza&size=10&sort=relevance_desc';
'?**&field=all&frm=0&has_narrative=true&no_aggs=true&search_term=pizza&size=10&sort=relevance_desc';
fixture = { fixture: 'document/get-results.json' };
cy.intercept(request, fixture).as('getResults');

cy.intercept('GET', '/_suggest/?text=pizza', []);

cy.visit(
'?searchText=pizza&has_narrative=true&size=10&sort=relevance_desc&tab=List'
'?searchText=pizza&has_narrative=true&size=10&sort=relevance_desc&tab=List',
);

cy.get('select#select-sort option:selected').should(
'have.text',
'Relevance'
'Relevance',
);

cy.contains('.pill', 'Has narrative').should('be.visible');
Expand All @@ -82,7 +82,7 @@ describe('Document View', () => {

cy.get('select#select-sort option:selected').should(
'have.text',
'Relevance'
'Relevance',
);

cy.contains('.pill', 'Has narrative').should('be.visible');
Expand Down
2,822 changes: 2,821 additions & 1 deletion cypress/fixtures/document/get-complaints.json

Large diffs are not rendered by default.

44 changes: 43 additions & 1 deletion cypress/fixtures/document/get-detail.json
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
{"took":11,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":{"value":1,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"complaint-public-v2","_type":"_doc","_id":"3146099","_score":1.0,"_source":{"product":"Credit card or prepaid card","complaint_what_happened":"my card has been declined for \" suspicious '' purchases and they are not able to prevent, or remedy the problem. I've worked with them multiple times and after excessive hold times on each call, it continues and can't seem to be fixed. \n\nEach time I call it's a different excuse. \n\nThis started in early XXXX of XXXX and has occurred in XXXX, XXXX, XXXX of XXXX, XXXX of XXXX and XX/XX/XXXX. \n\nThe purchases were for the following : 1. Pizza at local Pizza shop. ( 1 block from house ) 2. XXXX XXXX for prescription medicine and household ( 2 miles from home ) 3. Online game service using a virtual card number that was exclusively provided by capital one for this service.","date_sent_to_company":"2019-02-07T12:00:00-05:00","issue":"Trouble using your card",":updated_at":1639539163,"date_received_formatted":"02/07/19","sub_product":"General-purpose credit card or charge card","zip_code":"19438","tags":null,"has_narrative":true,"complaint_id":"3146099","date_sent_to_company_formatted":"02/07/19","timely":"Yes","consumer_consent_provided":"Consent provided","company_response":"Closed with explanation","date_indexed":"2021-12-15T12:00:00-05:00","submitted_via":"Web","date_indexed_formatted":"12/15/21","company":"CAPITAL ONE FINANCIAL CORPORATION","date_received":"2019-02-07T12:00:00-05:00","state":"PA","consumer_disputed":"N/A","company_public_response":null,"sub_issue":"Can't use card to make purchases"}}]}}
{
"took": 11,
"timed_out": false,
"_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 },
"hits": {
"total": { "value": 1, "relation": "eq" },
"max_score": 1.0,
"hits": [
{
"_index": "complaint-public-v2",
"_type": "_doc",
"_id": "3146099",
"_score": 1.0,
"_source": {
"product": "Credit card or prepaid card",
"complaint_what_happened": "my card has been declined for \" suspicious '' purchases and they are not able to prevent, or remedy the problem. I've worked with them multiple times and after excessive hold times on each call, it continues and can't seem to be fixed. \n\nEach time I call it's a different excuse. \n\nThis started in early XXXX of XXXX and has occurred in XXXX, XXXX, XXXX of XXXX, XXXX of XXXX and XX/XX/XXXX. \n\nThe purchases were for the following : 1. Pizza at local Pizza shop. ( 1 block from house ) 2. XXXX XXXX for prescription medicine and household ( 2 miles from home ) 3. Online game service using a virtual card number that was exclusively provided by capital one for this service.",
"date_sent_to_company": "2019-02-07T12:00:00-05:00",
"issue": "Trouble using your card",
":updated_at": 1639539163,
"date_received_formatted": "02/07/19",
"sub_product": "General-purpose credit card or charge card",
"zip_code": "19438",
"tags": null,
"has_narrative": true,
"complaint_id": "3146099",
"date_sent_to_company_formatted": "02/07/19",
"timely": "Yes",
"consumer_consent_provided": "Consent provided",
"company_response": "Closed with explanation",
"date_indexed": "2021-12-15T12:00:00-05:00",
"submitted_via": "Web",
"date_indexed_formatted": "12/15/21",
"company": "CAPITAL ONE FINANCIAL CORPORATION",
"date_received": "2019-02-07T12:00:00-05:00",
"state": "PA",
"consumer_disputed": "N/A",
"company_public_response": null,
"sub_issue": "Can't use card to make purchases"
}
}
]
}
}
6 changes: 3 additions & 3 deletions dist/ccdb5.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ccdb5.css.map

Large diffs are not rendered by default.

119 changes: 59 additions & 60 deletions dist/ccdb5.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ccdb5.js.map

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions src/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import { render, screen } from '@testing-library/react';
import * as useUpdateLocationHook from './hooks/useUpdateLocation';
import store from './app/store';
import { ComplaintDetail } from './components/ComplaintDetail/ComplaintDetail';
import { waitFor } from './testUtils/test-utils';
jest.mock('highcharts/modules/accessibility');
jest.mock('highcharts/highmaps');

describe('initial state', () => {
test('renders search page', () => {
const updateLocationHookSpy = jest
.spyOn(useUpdateLocationHook, 'useUpdateLocation')
.mockImplementation(() => jest.fn());

it('renders search page', async () => {
const updateLocationHookSpy = jest.spyOn(
useUpdateLocationHook,
'useUpdateLocation',
);
render(
<Provider store={store}>
<App />
Expand All @@ -27,12 +28,14 @@ describe('initial state', () => {
expect(
screen.getByRole('button', { name: /Show advanced search tips/ }),
).toBeInTheDocument();
expect(
screen.getByRole('button', { name: /Take a tour/ }),
).toBeInTheDocument();
});
await waitFor(() => {
expect(
screen.getByRole('button', { name: /Take a tour/ }),
).toBeInTheDocument();
});
}, 10000);

test('renders the detail route', () => {
it('renders the detail route', () => {
render(
<MemoryRouter initialEntries={['/detail/6026335']}>
<Provider store={store}>
Expand Down
4 changes: 4 additions & 0 deletions src/actions/__tests__/complaints.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('action::complaints', () => {
describe('getComplaints', () => {
let expectedUrl;
beforeEach(() => {
fixtureStore = initialState();
expectedUrl = expectedHitsQS;
fixtureStore.view.tab = constants.MODE_LIST;
});
Expand Down Expand Up @@ -79,6 +80,7 @@ describe('action::complaints', () => {
let expectedUrl;

beforeEach(() => {
fixtureStore = initialState();
fixtureStore.view.tab = constants.MODE_DETAIL;
expectedUrl = '@@API123';
});
Expand Down Expand Up @@ -112,6 +114,7 @@ describe('action::complaints', () => {
let expectedUrl;

beforeEach(() => {
fixtureStore = initialState();
fixtureStore.view.tab = constants.MODE_MAP;
expectedUrl =
'@@APIgeo/states/?date_received_max=2020-05-05' +
Expand Down Expand Up @@ -144,6 +147,7 @@ describe('action::complaints', () => {
let expectedUrl;

beforeEach(() => {
fixtureStore = initialState();
fixtureStore.view.tab = constants.MODE_TRENDS;
expectedUrl =
'@@APItrends?date_received_max=2020-05-05' +
Expand Down
2 changes: 1 addition & 1 deletion src/actions/complaints.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function getAggregations() {
const uri = API_PLACEHOLDER + qs;

// This call is already in process
if (store.aggs.activeCall) {
if (uri === store.aggs.activeCall) {
return null;
}

Expand Down
17 changes: 0 additions & 17 deletions src/actions/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { routeChanged } from '../reducers/routes/routesSlice';
import queryString from 'query-string';
const isEqual = require('react-fast-compare');

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -55,19 +54,3 @@ export function changeRoute(path, params) {
}
};
}

/**
* Converts a Location object into structures needed by the reducers
*
* @param {Location} location - information about the host, path and query string
* @returns {object} the pathname and a dictionary of the query string params
*/
export function processLocation(location) {
const qs = location.search;
const params = queryString.parse(qs);

return {
pathname: location.pathname,
params,
};
}
10 changes: 10 additions & 0 deletions src/actions/sendHitsQuery/sendHitsQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,15 @@ describe('api::sendHitsQuery', () => {
expect(dispatch.mock.calls.length).toEqual(1);
expect(spy1).toHaveBeenCalledTimes(1);
});
it('ignores unknown modes', () => {
fixtureStore.view.tab = 'foo';
spy1 = jest
.spyOn(sutComplaints, 'getTrends')
.mockImplementation(() => jest.fn());

sutHits.sendHitsQuery()(dispatch, getState);
expect(dispatch.mock.calls.length).toEqual(0);
expect(spy1).toHaveBeenCalledTimes(0);
});
});
});
89 changes: 17 additions & 72 deletions src/api/params/params.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable camelcase */
import { clamp } from '../../utils';
import { clamp, removeNullProperties } from '../../utils';
import { enforceValues } from '../../utils/reducers';
// ----------------------------------------------------------------------------
// return parameter objects
Expand All @@ -13,21 +13,13 @@ import { enforceValues } from '../../utils/reducers';
export function extractAggregationParams(state) {
const { filters, query } = state;

const set1 = {
field: 'all',
};

if (query.dateRange) {
set1.date_received_max = query.date_received_max;
set1.date_received_min = query.date_received_min;
}
const queryState = extractQueryParams(query);

if (query.searchField) {
set1.field = query.searchField;
}
if (query.searchText) {
set1.search_term = query.searchText;
}
const queryParams = Object.keys(queryState).filter(
(key) =>
// exclude these from query
!['frm', 'size', 'sort'].includes(key),
);

const filterParams = Object.keys(filters).filter(
(key) =>
Expand All @@ -36,12 +28,15 @@ export function extractAggregationParams(state) {
key,
),
);

// Grab specific attributes from the reducers
return Object.assign(
const newObject = Object.assign(
{},
set1,
extractReducerAttributes(queryState, queryParams),
extractReducerAttributes(filters, filterParams),
);

return removeNullProperties(newObject);
}

/**
Expand Down Expand Up @@ -105,6 +100,10 @@ export function extractReducerAttributes(reducer, attributes) {
export function extractQueryParams(queryState) {
const query = queryState;
const params = {
company_received_max: query.company_received_max,
company_received_min: query.company_received_min,
date_received_max: query.date_received_max,
date_received_min: query.date_received_min,
field: enforceValues(query.searchField, 'searchField'),
// edge case for doc complaint override in
// actions/complaints.js
Expand All @@ -116,12 +115,6 @@ export function extractQueryParams(queryState) {
sort: query.sort,
};

/* istanbul ignore else */
if (query.dateRange) {
params.date_received_max = query.date_received_max;
params.date_received_min = query.date_received_min;
}

/* istanbul ignore else */
if (query.searchText) {
params.search_term = query.searchText;
Expand All @@ -131,57 +124,9 @@ export function extractQueryParams(queryState) {
params.search_after = query.searchAfter;
}

return params;
return removeNullProperties(params);
}

// /**
// * Reverses extractQueryParams
// *
// * @param {object} params - the parameters returned from the API
// * @returns {object} a version of the query state
// */
// export function parseParamsToQuery(params) {
// const {
// date_received_max,
// date_received_min,
// field,
// frm: frm_as_string,
// search_term,
// size: size_as_string,
// sort,
// } = params;
//
// const size = parseInt(size_as_string, 10);
// const frm = parseInt(frm_as_string, 10);
//
// const query = {
// page: (frm + size) / size,
// searchText: search_term || '',
// // searchFields: revSearchFieldMap[field],
// size,
// };
//
// // Handle the dates
// const dateRange = removeNullProperties({
// to: date_received_max,
// from: date_received_min,
// });
//
// /* istanbul ignore else */
// if (!isEqual(dateRange, {})) {
// query.dateRange = dateRange;
// validateDatePeriod(query.dateRange);
// }
//
// // Handle sort
// /* istanbul ignore else */
// if (sort) {
// query.sort = sortNames(sort);
// }
//
// return removeNullProperties(query);
// }

/**
* Selects specific variables from the trends reducer to be used in a query str
*
Expand Down
21 changes: 7 additions & 14 deletions src/api/url/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,21 @@ export function buildUri(state) {
let params;

switch (tab) {
case MODE_LIST:
params = paramFns.extractBasicParams(filters, query);
params.no_aggs = true;
break;

case MODE_MAP:
params = Object.assign(
{ no_aggs: true },
paramFns.extractBasicParams(filters, query),
);
break;

case MODE_TRENDS:
default:
params = Object.assign(
{ no_aggs: true },
{},
paramFns.extractBasicParams(filters, query),
paramFns.extractTrendsParams(state),
);
break;
case MODE_LIST:
case MODE_MAP:
default:
params = Object.assign(paramFns.extractBasicParams(filters, query));
break;
}

params.no_aggs = true;
return formatUri('', params);
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/Charts/RowChart/RowChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { scrollToFocus } from '../../../utils/trends';
import { focusChanged } from '../../../reducers/trends/trendsSlice';
import { rowCollapsed, rowExpanded } from '../../../reducers/view/viewSlice';

import { selectAggsRootState } from '../../../reducers/aggs/selectors';
import { selectAggsRoot } from '../../../reducers/aggs/selectors';
import { selectTrendsLens } from '../../../reducers/trends/selectors';
import {
selectViewIsPrintMode,
Expand All @@ -36,7 +36,7 @@ export const RowChart = ({
const dispatch = useDispatch();
const tab = useSelector(selectViewTab);
const trendsLens = useSelector(selectTrendsLens);
const aggs = useSelector(selectAggsRootState);
const aggs = useSelector(selectAggsRoot);
const expandedRows = useSelector(selectViewExpandedRows);
const isPrintMode = useSelector(selectViewIsPrintMode);
const width = useSelector(selectViewWidth);
Expand Down
Loading

0 comments on commit 7192be5

Please sign in to comment.