koel/resources/assets/js/components/layout/AppHeader.spec.ts

52 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-05-11 15:24:28 +00:00
import isMobile from 'ismobilejs'
import { expect, it } from 'vitest'
2022-07-10 15:17:48 +00:00
import { fireEvent, queryAllByTestId, waitFor } from '@testing-library/vue'
import { eventBus } from '@/utils'
import compareVersions from 'compare-versions'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import AppHeader from './AppHeader.vue'
import SearchForm from '@/components/ui/SearchForm.vue'
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
protected test () {
it('toggles sidebar (mobile only)', async () => {
isMobile.any = true
const { getByTitle } = this.render(AppHeader)
const mock = this.mock(eventBus, 'emit')
await fireEvent.click(getByTitle('Show or hide the sidebar'))
expect(mock).toHaveBeenCalledWith('TOGGLE_SIDEBAR')
})
it('toggles search form (mobile only)', async () => {
isMobile.any = true
const { getByTitle, getByRole, queryByRole } = this.render(AppHeader, {
global: {
stubs: {
SearchForm
}
}
})
expect(await queryByRole('search')).toBeNull()
await fireEvent.click(getByTitle('Show or hide the search form'))
2022-07-10 15:17:48 +00:00
await waitFor(() => getByRole('search'))
})
it.each([[true, true, true], [false, true, false], [true, false, false], [false, false, false]])(
'announces a new version if applicable',
async (hasNewVersion, isAdmin, announcing) => {
this.mock(compareVersions, 'compare', hasNewVersion)
2022-07-19 08:19:57 +00:00
const { queryAllByTestId } = this.actingAsAdmin().render(AppHeader)
2022-07-10 15:17:48 +00:00
expect(queryAllByTestId('new-version')).toHaveLength(announcing ? 1 : 0)
}
)
}
}