-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93df17d
commit 076ab37
Showing
3 changed files
with
107 additions
and
0 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,48 @@ | ||
import { describe, expect, test, afterEach } from 'vitest'; | ||
import { render, screen, cleanup, fireEvent } from '@testing-library/svelte'; | ||
import SearchBar from '../../lib/home/Search.svelte'; | ||
import { districts } from '../../data'; | ||
describe('Unit:Home/Search', () => { | ||
let searchValue = ''; | ||
let selectValue = ''; | ||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
test('should change value according to change event', async () => { | ||
render(SearchBar, { searchValue, selectValue }); | ||
|
||
const inputText = 'Test search'; | ||
const inputElements = screen.getAllByTestId('search-input'); | ||
|
||
inputElements.forEach(async (inputElement) => { | ||
await fireEvent.input(inputElement, { | ||
target: { | ||
value: inputText, | ||
}, | ||
}); | ||
|
||
expect((inputElement as HTMLInputElement).value).toBe(inputText); | ||
}); | ||
}); | ||
|
||
test('should change select value upon change', () => { | ||
render(SearchBar, { searchValue, selectValue }); | ||
|
||
const selectElement = screen.getByTestId('search-select'); | ||
districts.forEach((district) => { | ||
fireEvent.select(selectElement, { | ||
target: { | ||
value: district, | ||
}, | ||
}); | ||
expect((selectElement as HTMLSelectElement).value).toBe(district); | ||
}); | ||
}); | ||
|
||
test('snapshot test', () => { | ||
render(SearchBar, { searchValue, selectValue }); | ||
|
||
expect(screen).toMatchSnapshot(); | ||
}); | ||
}); |
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,56 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`Unit:Home/Search > snapshot test 1`] = ` | ||
{ | ||
"debug": [Function], | ||
"findAllByAltText": [Function], | ||
"findAllByDisplayValue": [Function], | ||
"findAllByLabelText": [Function], | ||
"findAllByPlaceholderText": [Function], | ||
"findAllByRole": [Function], | ||
"findAllByTestId": [Function], | ||
"findAllByText": [Function], | ||
"findAllByTitle": [Function], | ||
"findByAltText": [Function], | ||
"findByDisplayValue": [Function], | ||
"findByLabelText": [Function], | ||
"findByPlaceholderText": [Function], | ||
"findByRole": [Function], | ||
"findByTestId": [Function], | ||
"findByText": [Function], | ||
"findByTitle": [Function], | ||
"getAllByAltText": [Function], | ||
"getAllByDisplayValue": [Function], | ||
"getAllByLabelText": [Function], | ||
"getAllByPlaceholderText": [Function], | ||
"getAllByRole": [Function], | ||
"getAllByTestId": [Function], | ||
"getAllByText": [Function], | ||
"getAllByTitle": [Function], | ||
"getByAltText": [Function], | ||
"getByDisplayValue": [Function], | ||
"getByLabelText": [Function], | ||
"getByPlaceholderText": [Function], | ||
"getByRole": [Function], | ||
"getByTestId": [Function], | ||
"getByText": [Function], | ||
"getByTitle": [Function], | ||
"logTestingPlaygroundURL": [Function], | ||
"queryAllByAltText": [Function], | ||
"queryAllByDisplayValue": [Function], | ||
"queryAllByLabelText": [Function], | ||
"queryAllByPlaceholderText": [Function], | ||
"queryAllByRole": [Function], | ||
"queryAllByTestId": [Function], | ||
"queryAllByText": [Function], | ||
"queryAllByTitle": [Function], | ||
"queryByAltText": [Function], | ||
"queryByDisplayValue": [Function], | ||
"queryByLabelText": [Function], | ||
"queryByPlaceholderText": [Function], | ||
"queryByRole": [Function], | ||
"queryByTestId": [Function], | ||
"queryByText": [Function], | ||
"queryByTitle": [Function], | ||
} | ||
`; |
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