-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web): clear combobox value when selectedOption is undefined
- Loading branch information
1 parent
b9e98d2
commit cec2e8d
Showing
4 changed files
with
42 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const getVisualViewportMock = () => ({ | ||
height: window.innerHeight, | ||
width: window.innerWidth, | ||
scale: 1, | ||
offsetLeft: 0, | ||
offsetTop: 0, | ||
addEventListener: vi.fn(), | ||
removeEventListener: vi.fn(), | ||
}); |
30 changes: 30 additions & 0 deletions
30
web/src/lib/components/shared-components/__test__/combobox.spec.ts
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,30 @@ | ||
import { getIntersectionObserverMock } from '$lib/__mocks__/intersection-observer.mock'; | ||
import { getVisualViewportMock } from '$lib/__mocks__/visual-viewport.mock'; | ||
import Combobox from '$lib/components/shared-components/combobox.svelte'; | ||
import { render, screen } from '@testing-library/svelte'; | ||
|
||
describe('Combobox component', () => { | ||
beforeAll(() => { | ||
vi.stubGlobal('IntersectionObserver', getIntersectionObserverMock()); | ||
vi.stubGlobal('visualViewport', getVisualViewportMock()); | ||
}); | ||
|
||
it('shows selected option', () => { | ||
render(Combobox, { | ||
label: 'test', | ||
selectedOption: { label: 'option-1', value: 'option-1' }, | ||
}); | ||
|
||
expect(screen.getByRole('combobox')).toHaveValue('option-1'); | ||
}); | ||
|
||
it('clears the selected option when set to undefined', async () => { | ||
const { rerender } = render(Combobox, { | ||
label: 'test', | ||
selectedOption: { label: 'option-1', value: 'option-1' }, | ||
}); | ||
|
||
await rerender({ selectedOption: undefined }); | ||
expect(screen.getByRole('combobox')).toHaveValue(''); | ||
}); | ||
}); |
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