2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-11 15:59:43 +00:00
|
|
|
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-11 15:59:43 +00:00
|
|
|
|
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') {
|
2022-05-11 15:59:43 +00:00
|
|
|
const rendered = this.render(Overlay, {
|
|
|
|
global: {
|
|
|
|
stubs: {
|
2022-08-01 08:58:25 +00:00
|
|
|
SoundBars
|
2022-05-11 15:59:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
eventBus.emit('SHOW_OVERLAY', {
|
|
|
|
type,
|
|
|
|
message: 'Look at me now'
|
|
|
|
})
|
|
|
|
|
|
|
|
await this.tick()
|
2022-07-21 09:39:42 +00:00
|
|
|
|
2022-05-11 15:59:43 +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())
|
2022-05-11 15:59:43 +00:00
|
|
|
|
|
|
|
it('closes', async () => {
|
2022-07-21 09:39:42 +00:00
|
|
|
const { queryByTestId } = await this.renderComponent()
|
|
|
|
expect(queryByTestId('overlay')).not.toBeNull()
|
2022-05-11 15:59:43 +00:00
|
|
|
|
|
|
|
eventBus.emit('HIDE_OVERLAY')
|
2022-07-21 09:39:42 +00:00
|
|
|
await waitFor(() => expect(queryByTestId('overlay')).toBeNull())
|
2022-05-11 15:59:43 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|