-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(website): add mutation filter to the search (#818)
- Loading branch information
1 parent
830d923
commit c7b4e6c
Showing
12 changed files
with
413 additions
and
42 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
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
77 changes: 77 additions & 0 deletions
77
website/src/components/SearchPage/fields/MutationField.spec.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,77 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { describe, expect, test, vi } from 'vitest'; | ||
|
||
import { MutationField } from './MutationField.tsx'; | ||
import type { MutationFilter } from '../../../types/config.ts'; | ||
import type { ReferenceGenomesSequenceNames } from '../../../types/referencesGenomes.ts'; | ||
|
||
const singleSegmentedReferenceGenome: ReferenceGenomesSequenceNames = { | ||
nucleotideSequences: ['main'], | ||
genes: ['gene1', 'gene2'], | ||
}; | ||
|
||
const multiSegmentedReferenceGenome: ReferenceGenomesSequenceNames = { | ||
nucleotideSequences: ['seg1', 'seg2'], | ||
genes: ['gene1', 'gene2'], | ||
}; | ||
|
||
function renderField( | ||
value: MutationFilter, | ||
onChange: (mutationFilter: MutationFilter) => void, | ||
referenceGenome: ReferenceGenomesSequenceNames, | ||
) { | ||
render(<MutationField value={value} onChange={onChange} referenceGenomes={referenceGenome} />); | ||
} | ||
|
||
describe('MutationField', () => { | ||
test('should render provided value', async () => { | ||
const handleChange = vi.fn(); | ||
renderField( | ||
{ | ||
aminoAcidMutationQueries: ['gene1:10Y'], | ||
nucleotideMutationQueries: ['A20T'], | ||
nucleotideInsertionQueries: ['ins_30:G?G'], | ||
}, | ||
handleChange, | ||
singleSegmentedReferenceGenome, | ||
); | ||
expect(screen.queryByText('gene1:10Y')).toBeInTheDocument(); | ||
expect(screen.queryByText('A20T')).toBeInTheDocument(); | ||
expect(screen.queryByText('ins_30:G?G')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should accept input and dispatch events (single-segmented)', async () => { | ||
const handleChange = vi.fn(); | ||
renderField({}, handleChange, singleSegmentedReferenceGenome); | ||
|
||
await userEvent.type(screen.getByLabelText('Mutations'), 'G100A{enter}'); | ||
expect(handleChange).toHaveBeenCalledWith({ | ||
nucleotideMutationQueries: ['G100A'], | ||
aminoAcidMutationQueries: [], | ||
nucleotideInsertionQueries: [], | ||
aminoAcidInsertionQueries: [], | ||
}); | ||
}); | ||
|
||
test('should accept input and dispatch events (multi-segmented)', async () => { | ||
const handleChange = vi.fn(); | ||
renderField({}, handleChange, multiSegmentedReferenceGenome); | ||
|
||
await userEvent.type(screen.getByLabelText('Mutations'), 'seg1:G100A{enter}'); | ||
expect(handleChange).toHaveBeenCalledWith({ | ||
nucleotideMutationQueries: ['seg1:G100A'], | ||
aminoAcidMutationQueries: [], | ||
nucleotideInsertionQueries: [], | ||
aminoAcidInsertionQueries: [], | ||
}); | ||
}); | ||
|
||
test('should reject invalid input', async () => { | ||
const handleChange = vi.fn(); | ||
renderField({}, handleChange, singleSegmentedReferenceGenome); | ||
|
||
await userEvent.type(screen.getByLabelText('Mutations'), 'main:G200A{enter}'); | ||
expect(handleChange).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
Oops, something went wrong.