-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #471 from hodcroftlab/302-download-data-dynamically
302 download data dynamically
- Loading branch information
Showing
79 changed files
with
1,827 additions
and
758 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Row } from 'reactstrap' | ||
import React, { useMemo } from 'react' | ||
import { ColCustom } from 'src/components/Common/ColCustom' | ||
import { useTicks, useTimeDomain } from 'src/io/useParams' | ||
import { CasesPlotCard } from 'src/components/Cases/CasesPlotCard' | ||
import { CountryFlag } from 'src/components/Common/CountryFlag' | ||
import { PerCountryCasesDistribution } from 'src/io/getPerCountryCasesData' | ||
|
||
export function CasesComponents({ | ||
withClustersFiltered, | ||
enabledClusters, | ||
}: { | ||
withClustersFiltered: PerCountryCasesDistribution[] | ||
enabledClusters: string[] | ||
}) { | ||
const timeDomain = useTimeDomain() | ||
const ticks = useTicks() | ||
|
||
const casesComponents = useMemo( | ||
() => | ||
withClustersFiltered.map(({ country, distribution }) => ( | ||
<ColCustom key={country} md={12} lg={6} xl={6} xxl={4}> | ||
<CasesPlotCard | ||
country={country} | ||
distribution={distribution} | ||
cluster_names={enabledClusters} | ||
Icon={CountryFlag} | ||
ticks={ticks} | ||
timeDomain={timeDomain} | ||
/> | ||
</ColCustom> | ||
)), | ||
[enabledClusters, withClustersFiltered, ticks, timeDomain], | ||
) | ||
return <Row className={'gx-0'}>{casesComponents}</Row> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { afterAll, afterEach, beforeAll, describe, expect, test, vi } from 'vitest' | ||
import { screen } from '@testing-library/react' | ||
import React from 'react' | ||
import { http, HttpResponse } from 'msw' | ||
import { ErrorBoundary } from 'react-error-boundary' | ||
import ResizeObserver from 'resize-observer-polyfill' | ||
import { renderWithQueryClient } from 'src/helpers/__tests__/providers' | ||
import { server } from 'src/components/SharedMutations/__tests__/mockRequests' | ||
import { FETCHER } from 'src/hooks/useAxiosQuery' | ||
import { CasesComponents } from 'src/components/Cases/CasesComponents' | ||
import { PerCountryCasesDistribution } from 'src/io/getPerCountryCasesData' | ||
|
||
globalThis.ResizeObserver = ResizeObserver | ||
|
||
describe('Cases', () => { | ||
beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) | ||
|
||
afterAll(() => server.close()) | ||
|
||
afterEach(() => { | ||
server.resetHandlers() | ||
FETCHER.getQueryClient().clear() | ||
}) | ||
describe('CasesComponents', () => { | ||
const withClustersFiltered: PerCountryCasesDistribution[] = [ | ||
{ | ||
country: 'USA', | ||
distribution: [ | ||
{ | ||
// eslint-disable-next-line camelcase | ||
stand_total_cases: 1114, | ||
week: '2020-04-27', | ||
// eslint-disable-next-line camelcase | ||
stand_estimated_cases: { | ||
'20A.EU2': 0, | ||
}, | ||
}, | ||
], | ||
}, | ||
] | ||
const enabledClusters = ['20A.EU2'] | ||
|
||
test('does not trigger error boundary when backend call succeeds', async () => { | ||
// Act | ||
renderWithQueryClient( | ||
<ErrorBoundary fallback={'Error boundary'}> | ||
<CasesComponents withClustersFiltered={withClustersFiltered} enabledClusters={enabledClusters} /> | ||
</ErrorBoundary>, | ||
) | ||
|
||
// Assert | ||
expect(await screen.findByText('USA', undefined, { timeout: 3000 })).toBeDefined() | ||
}) | ||
|
||
test('triggers error boundary when backend call fails', async () => { | ||
// Arrange | ||
server.use( | ||
http.get('/data/params.json', () => { | ||
return new HttpResponse(null, { status: 404 }) | ||
}), | ||
) | ||
// Disable console output | ||
vi.spyOn(console, 'error').mockImplementation(() => null) | ||
|
||
// Act | ||
renderWithQueryClient( | ||
<ErrorBoundary fallback={'Error boundary'}> | ||
<CasesComponents withClustersFiltered={withClustersFiltered} enabledClusters={enabledClusters} /> | ||
</ErrorBoundary>, | ||
) | ||
|
||
// Assert | ||
expect(await screen.findByText('Error boundary', undefined, { timeout: 3000 })).toBeDefined() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.