Skip to content

Commit

Permalink
DATAP-1335 deprecate redux mock store (#545)
Browse files Browse the repository at this point in the history
* save refactor

adding better middleware code, fixing references

adding tests for queryManager middleware, handle date objects, fixing bugs from fromIsoString

save work

save work, updates

update test

adding tests for complaints compound actions

remove deprecated dependencies

* remove unnecessary refactor

update stuff

move queryManager to another dir, update store test util, removed unused selector file

update test coverage

* fix CI/headless test

* undo relabel

* test

* fixin tests
  • Loading branch information
flacoman91 authored Oct 7, 2024
1 parent 7cd827a commit 17edcdd
Show file tree
Hide file tree
Showing 41 changed files with 835 additions and 910 deletions.
22 changes: 18 additions & 4 deletions cypress/e2e/common/filters.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ describe('Filter Panel', () => {
});
cy.log('apply dates');

cy.get('#date_received-from').clear();
cy.get('#date_received-from').type('2015-09-11');
cy.get('#date_received-from').clear({
force: true,
});

// TODO: this fails in headless mode for some reason without force:true but it works fine in
// electron / chrome headed version
cy.get('#date_received-from').type('2015-09-11', {
force: true,
});
cy.get('#date_received-from').blur();

cy.wait('@getComplaintsDateFrom');
Expand All @@ -61,8 +68,15 @@ describe('Filter Panel', () => {

cy.log('apply a through date');

cy.get('#date_received-through').clear();
cy.get('#date_received-through').type('2020-10-31');
cy.get('#date_received-through').clear({
force: true,
});

// TODO: this fails in headless mode for some reason without force:true but it works fine in
// electron / chrome headed version
cy.get('#date_received-through').type('2020-10-31', {
force: true,
});
cy.get('#date_received-through').blur();

cy.url().should('include', 'date_received_max=2020-10-31');
Expand Down
129 changes: 63 additions & 66 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.

8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,9 @@
"react-dom": "^18.3.1",
"react-modal": "^3.16.1",
"react-redux": "^9.1.2",
"react-router-dom": "^6.23.1",
"react-router-dom": "^6.26.0",
"react-scripts": "^5.0.1",
"react-test-renderer": "^18.2.0",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.2",
"redux-mock-store": "^1.5.4",
"redux-thunk": "^2.2.0",
"release-it": "^17.3.0",
"string-replace-loader": "^3.1.0",
"stylelint": "^16.5.0",
Expand Down Expand Up @@ -136,7 +132,7 @@
"coverageThreshold": {
"global": {
"branches": 85,
"functions": 91,
"functions": 89,
"lines": 93,
"statements": 93
}
Expand Down
71 changes: 18 additions & 53 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,37 @@
import './css/App.less';
import { applyMiddleware, createStore } from 'redux';
import { Route, BrowserRouter as Router, Routes } from 'react-router-dom';
import { composeWithDevTools } from 'redux-devtools-extension';
import { Provider } from 'react-redux';
import queryManager from './middleware/queryManager';
import { ComplaintDetail } from './components/ComplaintDetail/ComplaintDetail';
import reducers from './reducers';
import { SearchComponents } from './components/Search/SearchComponents';
import thunkMiddleware from 'redux-thunk';
import synchUrl from './middleware/synchUrl/synchUrl';

const middleware = [thunkMiddleware, queryManager, synchUrl];

const composeEnhancers = composeWithDevTools({
// required for redux-devtools-extension
// Specify name here, actionsBlacklist, actionsCreators and other options
// if needed
});

// required format for redux-devtools-extension
const store = createStore(
reducers,
composeEnhancers(
applyMiddleware(...middleware),
// other store enhancers if any
),
);

/* eslint-disable camelcase */
export const DetailComponents = () => {
return (
<main role="main">
<ComplaintDetail />
</main>
);
};
/* eslint-enable camelcase */

// eslint-disable-next-line react/no-multi-comp
/**
* Main App Component
*
* @returns {JSX.Element} Main app
*/
export const App = () => {
const App = () => {
return (
<Provider store={store}>
<Router>
<Routes>
{/*
<Router>
<Routes>
{/*
we need these duplicate routes to match relative path
/data-research/consumer-complaints/search
from CF.gov
local
which is just the root at localhost:3000/
*/}
<Route index element={<SearchComponents />} />
<Route
path="/data-research/consumer-complaints/search"
element={<SearchComponents />}
/>
<Route
path="/data-research/consumer-complaints/search/detail/:id"
element={<DetailComponents />}
/>
<Route path="/detail/:id" element={<DetailComponents />} />
</Routes>
</Router>
</Provider>
<Route index element={<SearchComponents />} />
<Route
path="/data-research/consumer-complaints/search"
element={<SearchComponents />}
/>
<Route
path="/data-research/consumer-complaints/search/detail/:id"
element={<ComplaintDetail />}
/>
<Route path="/detail/:id" element={<ComplaintDetail />} />
</Routes>
</Router>
);
};

export default App;
84 changes: 84 additions & 0 deletions src/App.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import App from './App';
import { Provider } from 'react-redux';
import 'regenerator-runtime/runtime';
import { render, screen, waitFor } from '@testing-library/react';
import * as useUpdateLocationHook from './hooks/useUpdateLocation';
import store from './app/store';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
import { ComplaintDetail } from './components/ComplaintDetail/ComplaintDetail';

jest.mock('highcharts/modules/accessibility');
jest.mock('highcharts/highmaps');

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

render(
<Provider store={store}>
<App />
</Provider>,
);

expect(updateLocationHookSpy).toBeCalled();

expect(screen.getByText(/Consumer Complaint Database/)).toBeInTheDocument();
expect(screen.getByText(/Search within/)).toBeInTheDocument();
expect(
screen.getByRole('button', { name: /Show advanced search tips/ }),
).toBeInTheDocument();
});

it('renders tour button', async () => {
const updateLocationHookSpy = jest
.spyOn(useUpdateLocationHook, 'useUpdateLocation')
.mockImplementation(() => jest.fn());

render(
<Provider store={store}>
<App />
</Provider>,
);

expect(updateLocationHookSpy).toBeCalled();

expect(screen.getByText(/Consumer Complaint Database/)).toBeInTheDocument();
expect(screen.getByText(/Search within/)).toBeInTheDocument();
expect(
screen.getByRole('button', { name: /Show advanced search tips/ }),
).toBeInTheDocument();

await waitFor(() => {
expect(
screen.getByRole('button', { name: /Take a tour/ }),
).toBeInTheDocument();
});
});

it('renders the detail route', () => {
render(
<MemoryRouter initialEntries={['/detail/6026335']}>
<Provider store={store}>
<Routes>
<Route path="/detail/:id" element={<ComplaintDetail />} />
</Routes>
</Provider>
</MemoryRouter>,
);

expect(
screen.getByRole('link', { name: /Back to search results/ }),
).toBeInTheDocument();
expect(
screen.getByRole('link', { name: /Back to search results/ }),
).toHaveAttribute(
'href',
'/?chartType=line&dateInterval=Month&dateRange=3y&date_received_max=2020-05-05&date_received_min=2017-05-05&lens=Product&searchField=all&subLens=sub_product&tab=Trends',
);

expect(screen.getByText('This page is loading')).toBeInTheDocument();
});
});
72 changes: 0 additions & 72 deletions src/__tests__/App.spec.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/actions/__fixtures__/emptyStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defaultAggs as aggs } from '../../reducers/aggs/aggs';
import { defaultDetail as detail } from '../../reducers/detail/detail';
import { defaultMap as map } from '../../reducers/map/map';
import { defaultQuery as query } from '../../reducers/query/query';
import { defaultTrends as trends } from '../../reducers/trends/trends';
import { defaultResults as results } from '../../reducers/results/results';
import { defaultView as view } from '../../reducers/view/view';

export default Object.freeze({
aggs,
detail,
map,
query,
results,
trends,
view,
});
Loading

0 comments on commit 17edcdd

Please sign in to comment.