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

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import { expect, it } from 'vitest'
import { eventBus } from '@/utils'
2022-07-21 09:39:42 +00:00
import { waitFor } from '@testing-library/vue'
2022-08-01 08:58:25 +00:00
import SoundBars from '@/components/ui/SoundBars.vue'
2022-07-21 09:39:42 +00:00
import Overlay from './Overlay.vue'
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
2022-07-21 09:39:42 +00:00
private async renderComponent (type: OverlayState['type'] = 'loading') {
const rendered = this.render(Overlay, {
global: {
stubs: {
2022-08-01 08:58:25 +00:00
SoundBars
}
}
})
eventBus.emit('SHOW_OVERLAY', {
type,
message: 'Look at me now'
})
await this.tick()
2022-07-21 09:39:42 +00:00
return rendered
}
protected test () {
it.each<[OverlayState['type']]>([
['loading'],
['success'],
['info'],
['warning'],
['error']
2022-07-21 09:39:42 +00:00
])('renders %s type', async (type) => expect((await this.renderComponent(type)).html()).toMatchSnapshot())
it('closes', async () => {
2022-07-21 09:39:42 +00:00
const { queryByTestId } = await this.renderComponent()
expect(queryByTestId('overlay')).not.toBeNull()
eventBus.emit('HIDE_OVERLAY')
2022-07-21 09:39:42 +00:00
await waitFor(() => expect(queryByTestId('overlay')).toBeNull())
})
}
}