diff --git a/src/components/Warnings/StaleDataWarnings.spec.js b/src/components/Warnings/StaleDataWarnings.spec.js index ba46aa24b..f30224ad8 100644 --- a/src/components/Warnings/StaleDataWarnings.spec.js +++ b/src/components/Warnings/StaleDataWarnings.spec.js @@ -1,25 +1,31 @@ import { testRender as render, screen } from '../../testUtils/test-utils'; import { StaleDataWarnings } from './StaleDataWarnings'; -import { merge } from '../../testUtils/functionHelpers'; -import { aggsState } from '../../reducers/aggs/aggsSlice'; +import { resAggWarning } from './fixture'; +import fetchMock from 'jest-fetch-mock'; describe('StaleDataWarnings', () => { - const renderComponent = (newAggsState) => { - merge(newAggsState, aggsState); + const renderComponent = () => { const data = { - aggs: newAggsState, + routes: { queryString: '?fdsfds' }, }; render(, { preloadedState: data, }); }; - test('data issue warning', () => { - renderComponent({ - hasDataIssue: true, - isDataStale: false, - }); + beforeEach(() => { + fetchMock.resetMocks(); + }); + test('data issue warning', async () => { + const dataWarning = { + ...resAggWarning, + }; + dataWarning._meta.has_data_issue = true; + fetchMock.mockResponseOnce(JSON.stringify(dataWarning)); + renderComponent(); + + await screen.findByText(/We’re currently experiencing technical/); expect( screen.getByText( /We’re currently experiencing technical issues that have delayed the refresh of data on the Consumer Complaint Database./, @@ -30,12 +36,15 @@ describe('StaleDataWarnings', () => { ).toBeInTheDocument(); }); - test('stale data warning', () => { - renderComponent({ - hasDataIssue: false, - isDataStale: true, - }); + test('stale data warning', async () => { + const dataWarning = { + ...resAggWarning, + }; + dataWarning._meta.is_data_stale = true; + fetchMock.mockResponseOnce(JSON.stringify(dataWarning)); + renderComponent(); + await screen.findByText(/We’re currently experiencing technical/); expect( screen.getByText( /We’re currently experiencing technical issues that have delayed the refresh of data on the Consumer Complaint Database./, @@ -45,12 +54,17 @@ describe('StaleDataWarnings', () => { screen.getByText(/We expect to refresh the data in the next few days./), ).toBeInTheDocument(); }); - test('both data issues', () => { - renderComponent({ - hasDataIssue: true, - isDataStale: true, - }); + test('both data issues', async () => { + const dataWarning = { + ...resAggWarning, + }; + dataWarning._meta.has_data_issue = true; + dataWarning._meta.is_data_stale = true; + + fetchMock.mockResponseOnce(JSON.stringify(dataWarning)); + renderComponent(); + await screen.findByText(/We’re currently experiencing technical/); expect( screen.getByText( /We’re currently experiencing technical issues that have delayed the refresh of data on the Consumer Complaint Database./, @@ -62,7 +76,15 @@ describe('StaleDataWarnings', () => { }); test('no issues', () => { - renderComponent({}); + fetchMock.mockResponseOnce( + JSON.stringify({ + _meta: { + is_data_stale: false, + has_data_issue: false, + }, + }), + ); + renderComponent(); expect( screen.queryByText(/We expect to refresh the data in the next few days./), ).toBeNull(); diff --git a/src/components/Warnings/fixture.js b/src/components/Warnings/fixture.js new file mode 100644 index 000000000..8b1f4b907 --- /dev/null +++ b/src/components/Warnings/fixture.js @@ -0,0 +1 @@ +export const resAggWarning = { 'took': 3079, 'timed_out': false, '_shards': { 'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0 }, 'hits': { 'total': { 'value': 6650388, 'relation': 'eq' }, 'max_score': null, 'hits': [] }, 'aggregations': {}, '_meta': { 'license': 'CC0', 'last_updated': '2024-11-06T12:00:00-05:00', 'last_indexed': '2024-11-07T12:00:00-05:00', 'total_record_count': 6650388, 'is_data_stale': false, 'has_data_issue': false, 'break_points': {} } }; \ No newline at end of file