2022-07-26 15:08:35 +00:00
|
|
|
import { expect, it, vi } from 'vitest'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-07-26 15:08:35 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import MessageToast from './MessageToast.vue'
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
private renderComponent () {
|
|
|
|
return this.render(MessageToast, {
|
|
|
|
props: {
|
|
|
|
message: {
|
|
|
|
id: 101,
|
|
|
|
type: 'success',
|
|
|
|
message: 'Everything is fine',
|
|
|
|
timeout: 5
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('renders', () => expect(this.renderComponent().html()).toMatchSnapshot())
|
|
|
|
|
|
|
|
it('dismisses upon click', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
const { emitted } = this.renderComponent()
|
|
|
|
await this.user.click(screen.getByTitle('Click to dismiss'))
|
2022-07-26 15:08:35 +00:00
|
|
|
|
|
|
|
expect(emitted().dismiss).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('dismisses upon timeout', async () => {
|
|
|
|
vi.useFakeTimers()
|
|
|
|
|
|
|
|
const { emitted } = this.renderComponent()
|
|
|
|
vi.advanceTimersByTime(5000)
|
|
|
|
expect(emitted().dismiss).toBeTruthy()
|
|
|
|
|
|
|
|
vi.useRealTimers()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|