-
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): Change data use terms in bulk (#3322)
* Add TODO * Add dialog stub * More stub progress * Factor out BaseDialog * Factor out BaseDialog in new Dialog * Add todos * Add download parameters * clean up * Add some notes * Rename * refactoring SequenceFilter * add docs * partial test fixes * Test fix * More test fix * test fix * WIP * Data can be downloaded! * Remove dead code * Can edit just selected sequences now * Remove TODO * Update todo * WIP * Add more skeleton stuff * Remove TODOs * progress * a bit of cleanup * Add button * Layout progress * WIP * Refactor DataUseTermsSelector * Add DataUseTermsSelector to EditDataUseTermsModal * format * Getting close! * Fix a timing issue * remove ':' from active filters for consistency * Show button only on 'released' page * set min date in popup * rename, cleanup * rename, cleanup * rename, cleanup * remove debug statement * Add unit test stub * Better 'not logged in' handling * Add stub test * Add DataUseTermsSelector tests * Update website/src/components/DataUseTerms/EditDataUseTermsModal.tsx Co-authored-by: Theo Sanderson <[email protected]> * don't select anything by default * Update website/src/components/DataUseTerms/EditDataUseTermsModal.tsx Co-authored-by: Theo Sanderson <[email protected]> * Make 'Open Data Use Terms' a link to the data use terms page * fix mobile layout: use flex-col for screens<md * move text below selection * add calendar description option; replace 'cyan' with primary color for date picker * Add info about edit successful * Re-use hook toast handlers * rename type->option * format * Show data use terms column when editing data use terms is possible * Only update date where date needs to be updated * Disable button if no sequences would get updated --------- Co-authored-by: Theo Sanderson <[email protected]>
- Loading branch information
1 parent
5b78356
commit 272d34b
Showing
27 changed files
with
1,009 additions
and
463 deletions.
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
website/src/components/DataUseTerms/DataUseTermsSelector.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,140 @@ | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { DateTime } from 'luxon'; | ||
import { describe, expect, test, vi } from 'vitest'; | ||
|
||
import DataUseTermsSelector from './DataUseTermsSelector'; | ||
import { openDataUseTermsOption, restrictedDataUseTermsOption } from '../../types/backend.ts'; | ||
|
||
describe('DataUseTermsSelector', () => { | ||
test('calls setDataUseTerms when an input is clicked', () => { | ||
const mockSetDataUseTerms = vi.fn(); | ||
const maxRestrictedUntil = DateTime.now().plus({ days: 30 }); | ||
|
||
render( | ||
<DataUseTermsSelector | ||
initialDataUseTermsOption={openDataUseTermsOption} | ||
maxRestrictedUntil={maxRestrictedUntil} | ||
setDataUseTerms={mockSetDataUseTerms} | ||
/>, | ||
); | ||
|
||
// Restricted radio input | ||
const restrictedInput = screen.getByLabelText('Restricted'); | ||
fireEvent.click(restrictedInput); | ||
|
||
expect(mockSetDataUseTerms).toHaveBeenCalledWith({ | ||
type: restrictedDataUseTermsOption, | ||
restrictedUntil: maxRestrictedUntil.toFormat('yyyy-MM-dd'), | ||
}); | ||
|
||
// Open radio input | ||
const openInput = screen.getByLabelText('Open'); | ||
fireEvent.click(openInput); | ||
|
||
expect(mockSetDataUseTerms).toHaveBeenCalledWith({ type: openDataUseTermsOption }); | ||
}); | ||
|
||
test('opens the modal when calendarUseModal is true and "Change date" button is clicked', () => { | ||
const mockSetDataUseTerms = vi.fn(); | ||
const maxRestrictedUntil = DateTime.now().plus({ days: 30 }); | ||
|
||
render( | ||
<DataUseTermsSelector | ||
initialDataUseTermsOption={restrictedDataUseTermsOption} | ||
maxRestrictedUntil={maxRestrictedUntil} | ||
calendarUseModal | ||
setDataUseTerms={mockSetDataUseTerms} | ||
/>, | ||
); | ||
|
||
const changeDateButton = screen.getByText('Change date'); | ||
fireEvent.click(changeDateButton); | ||
|
||
expect(screen.getByText('Change date until which sequences are restricted')).toBeInTheDocument(); | ||
}); | ||
|
||
test('does not use the modal when calendarUseModal is false and renders the inline datepicker instead', () => { | ||
const mockSetDataUseTerms = vi.fn(); | ||
const maxRestrictedUntil = DateTime.now().plus({ days: 30 }); | ||
|
||
render( | ||
<DataUseTermsSelector | ||
initialDataUseTermsOption={restrictedDataUseTermsOption} | ||
maxRestrictedUntil={maxRestrictedUntil} | ||
calendarUseModal={false} | ||
setDataUseTerms={mockSetDataUseTerms} | ||
/>, | ||
); | ||
|
||
expect(screen.queryByText('Mon')).toBeInTheDocument(); | ||
expect(screen.queryByText('Tue')).toBeInTheDocument(); | ||
expect(screen.queryByText('Wed')).toBeInTheDocument(); | ||
expect(screen.queryByText('Change date')).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('updates the date when a date is clicked in the inline datepicker', () => { | ||
const mockSetDataUseTerms = vi.fn(); | ||
const maxRestrictedUntil = DateTime.fromISO('2077-07-15'); | ||
|
||
render( | ||
<DataUseTermsSelector | ||
initialDataUseTermsOption={restrictedDataUseTermsOption} | ||
maxRestrictedUntil={maxRestrictedUntil} | ||
calendarUseModal={false} | ||
setDataUseTerms={mockSetDataUseTerms} | ||
/>, | ||
); | ||
|
||
const dateButton = screen.getByText('14'); | ||
fireEvent.click(dateButton); | ||
|
||
expect(mockSetDataUseTerms).toHaveBeenCalledWith({ | ||
type: restrictedDataUseTermsOption, | ||
restrictedUntil: '2077-07-14', | ||
}); | ||
}); | ||
|
||
test('updates the date via modal when "Change date" is clicked, a date is selected, and submitted', () => { | ||
const mockSetDataUseTerms = vi.fn(); | ||
const maxRestrictedUntil = DateTime.fromISO('2077-07-15'); | ||
|
||
render( | ||
<DataUseTermsSelector | ||
initialDataUseTermsOption={restrictedDataUseTermsOption} | ||
maxRestrictedUntil={maxRestrictedUntil} | ||
calendarUseModal | ||
setDataUseTerms={mockSetDataUseTerms} | ||
/>, | ||
); | ||
|
||
// Open the modal | ||
const changeDateButton = screen.getByText('Change date'); | ||
fireEvent.click(changeDateButton); | ||
|
||
// Select a date in the modal | ||
const dateButton = screen.getByText('14'); | ||
fireEvent.click(dateButton); | ||
|
||
// Submit the modal | ||
const submitButton = screen.getByText('Save'); | ||
fireEvent.click(submitButton); | ||
|
||
expect(mockSetDataUseTerms).toHaveBeenCalledWith({ | ||
type: restrictedDataUseTermsOption, | ||
restrictedUntil: '2077-07-14', | ||
}); | ||
}); | ||
|
||
test('renders with no radio input selected when initialDataUseTermsType is not set', () => { | ||
const mockSetDataUseTerms = vi.fn(); | ||
const maxRestrictedUntil = DateTime.fromISO('2077-07-15'); | ||
|
||
render(<DataUseTermsSelector maxRestrictedUntil={maxRestrictedUntil} setDataUseTerms={mockSetDataUseTerms} />); | ||
|
||
const openInput = screen.getByLabelText('Open'); | ||
const restrictedInput = screen.getByLabelText('Restricted'); | ||
|
||
expect(openInput).not.toBeChecked(); | ||
expect(restrictedInput).not.toBeChecked(); | ||
}); | ||
}); |
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.