koel/resources/assets/js/components/ui/SearchForm.spec.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

import { expect, it } from 'vitest'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import { fireEvent } from '@testing-library/vue'
import { eventBus } from '@/utils'
2022-07-21 10:45:23 +00:00
import SearchForm from './SearchForm.vue'
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
protected test () {
2022-07-21 10:45:23 +00:00
it('sets focus into search box when requested', async () => {
const { getByRole } = this.render(SearchForm)
eventBus.emit('FOCUS_SEARCH_FIELD')
expect(getByRole('searchbox')).toBe(document.activeElement)
})
it('goes to search screen when search box is focused', async () => {
const mock = this.mock(this.router, 'go')
const { getByRole } = this.render(SearchForm)
await fireEvent.focus(getByRole('searchbox'))
expect(mock).toHaveBeenCalledWith('search')
})
it('emits an event when search query is changed', async () => {
const mock = this.mock(eventBus, 'emit')
const { getByRole } = this.render(SearchForm)
await fireEvent.update(getByRole('searchbox'), 'hey')
expect(mock).toHaveBeenCalledWith('SEARCH_KEYWORDS_CHANGED', 'hey')
})
}
}