forked from Sage-Bionetworks/synapse-web-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic test looking for legend elements based on data. plot render…
…ing should be validated visually
- Loading branch information
1 parent
cf9a8f0
commit 0c9fb1a
Showing
3 changed files
with
67 additions
and
21 deletions.
There are no files selected for viewing
19 changes: 0 additions & 19 deletions
19
packages/synapse-react-client/src/components/TimelinePlot/TimelinePhase.stories.tsx
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
packages/synapse-react-client/src/components/TimelinePlot/TimelinePlot.integration.test.tsx
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,65 @@ | ||
import { act, render, screen, waitFor, within } from '@testing-library/react' | ||
import React from 'react' | ||
import TimelinePlot, { TimelinePlotProps } from './TimelinePlot' | ||
import { createWrapper } from '../../testutils/TestingLibraryUtils' | ||
|
||
import { SynapseClient } from '../../index' | ||
import queryResultBundleJson from '../../mocks/query/syn51735464' | ||
|
||
const timelineProps: TimelinePlotProps = { | ||
observationsSql: 'select * from syn123', | ||
species: 'Rattus norvegicus', | ||
resourceId: '9971e47e-976a-4631-8edd-5cae04304b01', | ||
} | ||
|
||
async function renderTimeline(props: TimelinePlotProps = timelineProps) { | ||
let component | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
await act(async () => { | ||
component = render(<TimelinePlot {...props} />, { | ||
wrapper: createWrapper(), | ||
}) | ||
}) | ||
return component | ||
} | ||
|
||
describe('TimelinePlot tests', () => { | ||
jest | ||
.spyOn(SynapseClient, 'getFullQueryTableResults') | ||
.mockResolvedValue(queryResultBundleJson) | ||
|
||
it('renders all phases of the timeline plot', async () => { | ||
await renderTimeline() | ||
expect(SynapseClient.getFullQueryTableResults).toHaveBeenCalledTimes(1), | ||
expect(await screen.findAllByText('PRENATAL')).toHaveLength(1) | ||
expect(await screen.findAllByText('NEONATAL')).toHaveLength(1) | ||
expect(await screen.findAllByText('WEANLING')).toHaveLength(1) | ||
expect(await screen.findAllByText('JUVENILE')).toHaveLength(1) | ||
expect(await screen.findAllByText('ADOLESCENT')).toHaveLength(1) | ||
expect(await screen.findAllByText('ADULT')).toHaveLength(1) | ||
}) | ||
|
||
it('does not render a phase if it has no event data', async () => { | ||
const newRows = queryResultBundleJson.queryResult?.queryResults.rows.filter( | ||
row => { | ||
return row.values[1] != 'juvenile' | ||
}, | ||
) | ||
queryResultBundleJson.queryResult!.queryResults.rows = newRows! | ||
await renderTimeline() | ||
expect(await screen.findAllByText('PRENATAL')).toHaveLength(1) | ||
expect(await screen.findAllByText('NEONATAL')).toHaveLength(1) | ||
expect(await screen.findAllByText('WEANLING')).toHaveLength(1) | ||
expect(await screen.findAllByText('ADOLESCENT')).toHaveLength(1) | ||
expect(await screen.findAllByText('ADULT')).toHaveLength(1) | ||
|
||
// test | ||
let notExist = false | ||
try { | ||
await screen.findAllByText('JUVENILE') | ||
} catch (error) { | ||
notExist = true | ||
} | ||
expect(notExist).toEqual(true) | ||
}) | ||
}) |
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