test(boardwalk): cover the build id, the reload banner and the chunk reload guard (quick-261028-rqb)
This commit is contained in:
53
admin/tests/ui/UpdateBanner.test.ts
Normal file
53
admin/tests/ui/UpdateBanner.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { enableAutoUnmount, mount } from '@vue/test-utils'
|
||||
import { nextTick } from 'vue'
|
||||
import { noteBuild, resetBuildUpdate } from '../../src/app/buildUpdate'
|
||||
import UpdateBanner from '../../src/components/ui/UpdateBanner.vue'
|
||||
import { page } from '../../src/state/usePreferences'
|
||||
import { resetState } from '../helpers'
|
||||
|
||||
beforeEach(() => {
|
||||
resetState()
|
||||
resetBuildUpdate()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
enableAutoUnmount(afterEach)
|
||||
|
||||
describe('UpdateBanner', () => {
|
||||
it('is hidden while no new build is known', () => {
|
||||
const wrapper = mount(UpdateBanner)
|
||||
expect(wrapper.find('[data-update-banner]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('shows the new-version text and reloads only on Reload', async () => {
|
||||
const reload = vi.spyOn(page, 'reload').mockImplementation(() => undefined)
|
||||
const wrapper = mount(UpdateBanner)
|
||||
noteBuild('bbbbbbbbbbbb', 'aaaaaaaaaaaa')
|
||||
await nextTick()
|
||||
const banner = wrapper.find('[data-update-banner]')
|
||||
expect(banner.exists()).toBe(true)
|
||||
expect(banner.attributes('role')).toBe('status')
|
||||
expect(banner.attributes('aria-live')).toBe('polite')
|
||||
expect(banner.text()).toContain('Dostępna jest nowa wersja panelu.')
|
||||
expect(wrapper.find('[data-update-reload]').text()).toBe('Odśwież')
|
||||
expect(reload).not.toHaveBeenCalled()
|
||||
await wrapper.find('[data-update-reload]').trigger('click')
|
||||
expect(reload).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('hides on Close', async () => {
|
||||
const reload = vi.spyOn(page, 'reload').mockImplementation(() => undefined)
|
||||
const wrapper = mount(UpdateBanner)
|
||||
noteBuild('bbbbbbbbbbbb', 'aaaaaaaaaaaa')
|
||||
await nextTick()
|
||||
const close = wrapper.find('[data-update-close]')
|
||||
expect(close.attributes('aria-label')).toBe('Zamknij')
|
||||
await close.trigger('click')
|
||||
expect(wrapper.find('[data-update-banner]').exists()).toBe(false)
|
||||
expect(reload).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user