-
Notifications
You must be signed in to change notification settings - Fork 17
feat: configurable default remote assignment validity period #1441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
37726bd
feat: configurable default remote assignment validity period
thomasbeaudry a5f3476
Merge remote-tracking branch 'origin/main' into feat/configurable-ass…
thomasbeaudry bc8f0eb
fix(web): correct instrument-showcase keyboard UX and cover assignmen…
thomasbeaudry bf54846
fix(web): read DOM value on blur so Firefox autosave triggers reliably
thomasbeaudry 4aaba52
Merge remote-tracking branch 'origin/main' into feat/configurable-ass…
thomasbeaudry 3461a1c
fix(testing): make the assignment-duration spec independent of browse…
thomasbeaudry d1359af
refactor(web): move assignment duration helpers out of the route modules
thomasbeaudry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,59 @@ | ||
| import { ConfigService, getModelToken, LoggingService, PRISMA_CLIENT_TOKEN } from '@douglasneuroinformatics/libnest'; | ||
| import type { Model } from '@douglasneuroinformatics/libnest'; | ||
| import { MockFactory } from '@douglasneuroinformatics/libnest/testing'; | ||
| import type { MockedInstance } from '@douglasneuroinformatics/libnest/testing'; | ||
| import { Test } from '@nestjs/testing'; | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { DemoService } from '@/demo/demo.service'; | ||
| import { InstrumentReposService } from '@/instrument-repos/instrument-repos.service'; | ||
| import { UsersService } from '@/users/users.service'; | ||
|
|
||
| import { SetupService } from '../setup.service'; | ||
|
|
||
| describe('SetupService', () => { | ||
| let setupService: SetupService; | ||
| let setupStateModel: MockedInstance<Model<'SetupState'>>; | ||
|
|
||
| beforeEach(async () => { | ||
| vi.stubGlobal('__RELEASE__', { buildTime: 0, type: 'test', version: '0.0.0' }); | ||
| const moduleRef = await Test.createTestingModule({ | ||
| providers: [ | ||
| SetupService, | ||
| MockFactory.createForModelToken(getModelToken('SetupState')), | ||
| MockFactory.createForService(ConfigService), | ||
| MockFactory.createForService(DemoService), | ||
| MockFactory.createForService(InstrumentReposService), | ||
| MockFactory.createForService(LoggingService), | ||
| MockFactory.createForService(UsersService), | ||
| { provide: PRISMA_CLIENT_TOKEN, useValue: {} } | ||
| ] | ||
| }).compile(); | ||
| setupService = moduleRef.get(SetupService); | ||
| setupStateModel = moduleRef.get(getModelToken('SetupState')); | ||
| moduleRef.get<MockedInstance<ConfigService>>(ConfigService).get.mockReturnValue(false); | ||
| }); | ||
|
|
||
| describe('updateState', () => { | ||
| it('should persist defaultAssignmentDurationDays', async () => { | ||
| setupStateModel.findFirst.mockResolvedValue({ id: 'setup-1', isSetup: true }); | ||
| await setupService.updateState({ defaultAssignmentDurationDays: 45 }); | ||
| expect(setupStateModel.update.mock.lastCall?.[0]).toMatchObject({ | ||
| data: { defaultAssignmentDurationDays: 45 }, | ||
| where: { id: 'setup-1' } | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getState', () => { | ||
| it('should return the saved defaultAssignmentDurationDays', async () => { | ||
| setupStateModel.findFirst.mockResolvedValue({ defaultAssignmentDurationDays: 45, isDemo: false, isSetup: true }); | ||
| await expect(setupService.getState()).resolves.toMatchObject({ defaultAssignmentDurationDays: 45 }); | ||
| }); | ||
|
|
||
| it('should return null when unset', async () => { | ||
| setupStateModel.findFirst.mockResolvedValue({ isDemo: false, isSetup: true }); | ||
| await expect(setupService.getState()).resolves.toMatchObject({ defaultAssignmentDurationDays: null }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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
26 changes: 26 additions & 0 deletions
26
apps/web/src/components/InstrumentShowcase/__tests__/InstrumentShowcase.test.tsx
This file contains hidden or 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,26 @@ | ||
| import { cleanup, fireEvent, render, screen } from '@testing-library/react'; | ||
| import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { InstrumentShowcase } from '../InstrumentShowcase'; | ||
|
|
||
| // Initialises the shared libui translator, which the showcase's controls read on render. | ||
| import '@/services/i18n'; | ||
|
|
||
| describe('InstrumentShowcase', () => { | ||
| afterEach(cleanup); | ||
|
|
||
| it('should not submit the wrapping search form when Enter is pressed with no matching instruments', () => { | ||
| render(<InstrumentShowcase data={[]} onSelect={vi.fn()} />); | ||
| const searchBar = screen.getByRole('searchbox'); | ||
| // fireEvent returns false when the event was canceled (preventDefault called). Leaving it | ||
| // un-cancelled lets the SearchBar form submit and reload the app back to the login page. | ||
| expect(fireEvent.keyDown(searchBar, { key: 'Enter' })).toBe(false); | ||
| }); | ||
|
|
||
| it('should not select anything when Enter is pressed with no matching instruments', () => { | ||
| const onSelect = vi.fn(); | ||
| render(<InstrumentShowcase data={[]} onSelect={onSelect} />); | ||
| fireEvent.keyDown(screen.getByRole('searchbox'), { key: 'Enter' }); | ||
| expect(onSelect).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or 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,26 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { useTranslation } from '@douglasneuroinformatics/libui/hooks'; | ||
| import { CheckIcon, Loader2Icon } from 'lucide-react'; | ||
|
|
||
| export const SaveStatus = ({ state }: { state: 'idle' | 'saved' | 'saving' }) => { | ||
| const { t } = useTranslation(); | ||
| if (state === 'idle') { | ||
| return null; | ||
| } | ||
| return ( | ||
| <div className="fixed bottom-4 right-4 z-50 flex items-center gap-1.5 rounded-full border border-slate-200/70 bg-white/95 px-3 py-1.5 text-xs font-medium shadow-md backdrop-blur dark:border-slate-700/70 dark:bg-slate-800/95"> | ||
|
joshunrau marked this conversation as resolved.
|
||
| {state === 'saving' ? ( | ||
| <React.Fragment> | ||
| <Loader2Icon className="text-muted-foreground h-3.5 w-3.5 animate-spin" /> | ||
| <span className="text-muted-foreground">{t({ en: 'Saving…', fr: 'Enregistrement…' })}</span> | ||
| </React.Fragment> | ||
| ) : ( | ||
| <React.Fragment> | ||
| <CheckIcon className="h-3.5 w-3.5 text-green-600" /> | ||
| <span>{t({ en: 'All changes saved', fr: 'Modifications enregistrées' })}</span> | ||
| </React.Fragment> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.