2022-05-11 15:24:28 +00:00
|
|
|
import isMobile from 'ismobilejs'
|
2022-05-09 09:59:31 +00:00
|
|
|
import { expect, it } from 'vitest'
|
2022-07-10 15:17:48 +00:00
|
|
|
import { fireEvent, queryAllByTestId, waitFor } from '@testing-library/vue'
|
2022-05-07 08:12:16 +00:00
|
|
|
import { eventBus } from '@/utils'
|
2022-05-11 15:24:28 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
2022-05-07 08:12:16 +00:00
|
|
|
import compareVersions from 'compare-versions'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-09 09:59:31 +00:00
|
|
|
import AppHeader from './AppHeader.vue'
|
|
|
|
import SearchForm from '@/components/ui/SearchForm.vue'
|
2022-05-07 08:12:16 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-09 09:59:31 +00:00
|
|
|
protected test () {
|
|
|
|
it('toggles sidebar (mobile only)', async () => {
|
|
|
|
isMobile.any = true
|
|
|
|
const { getByTitle } = this.render(AppHeader)
|
|
|
|
const mock = this.mock(eventBus, 'emit')
|
2022-05-07 08:12:16 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
await fireEvent.click(getByTitle('Show or hide the sidebar'))
|
2022-05-07 08:12:16 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
expect(mock).toHaveBeenCalledWith('TOGGLE_SIDEBAR')
|
|
|
|
})
|
2022-05-07 08:12:16 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
it('toggles search form (mobile only)', async () => {
|
|
|
|
isMobile.any = true
|
2022-05-07 08:12:16 +00:00
|
|
|
|
2022-05-12 09:51:58 +00:00
|
|
|
const { getByTitle, getByRole, queryByRole } = this.render(AppHeader, {
|
2022-05-09 09:59:31 +00:00
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
SearchForm
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-05-07 08:12:16 +00:00
|
|
|
|
2022-05-12 09:51:58 +00:00
|
|
|
expect(await queryByRole('search')).toBeNull()
|
2022-05-07 08:12:16 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
await fireEvent.click(getByTitle('Show or hide the search form'))
|
2022-07-10 15:17:48 +00:00
|
|
|
await waitFor(() => getByRole('search'))
|
2022-05-07 08:12:16 +00:00
|
|
|
})
|
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
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-05-07 08:12:16 +00:00
|
|
|
|
2022-05-11 15:24:28 +00:00
|
|
|
const { queryAllByTestId } = this.actingAs(factory<User>('user', { is_admin: isAdmin })).render(AppHeader)
|
2022-05-09 09:59:31 +00:00
|
|
|
|
2022-07-10 15:17:48 +00:00
|
|
|
expect(queryAllByTestId('new-version')).toHaveLength(announcing ? 1 : 0)
|
2022-05-09 09:59:31 +00:00
|
|
|
}
|
|
|
|
)
|
2022-05-07 08:12:16 +00:00
|
|
|
}
|
2022-05-09 09:59:31 +00:00
|
|
|
}
|
|
|
|
|