mirror of
https://github.com/koel/koel
synced 2024-11-24 13:13:05 +00:00
feat(test): add MessageToast tests
This commit is contained in:
parent
f0f953568c
commit
9ac080fcbc
3 changed files with 49 additions and 1 deletions
40
resources/assets/js/components/ui/MessageToast.spec.ts
Normal file
40
resources/assets/js/components/ui/MessageToast.spec.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import { expect, it, vi } from 'vitest'
|
||||
import UnitTestCase from '@/__tests__/UnitTestCase'
|
||||
import MessageToast from './MessageToast.vue'
|
||||
import { fireEvent } from '@testing-library/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 () => {
|
||||
const { emitted, getByTitle } = this.renderComponent()
|
||||
await fireEvent.click(getByTitle('Click to dismiss'))
|
||||
|
||||
expect(emitted().dismiss).toBeTruthy()
|
||||
})
|
||||
|
||||
it('dismisses upon timeout', async () => {
|
||||
vi.useFakeTimers()
|
||||
|
||||
const { emitted } = this.renderComponent()
|
||||
vi.advanceTimersByTime(5000)
|
||||
expect(emitted().dismiss).toBeTruthy()
|
||||
|
||||
vi.useRealTimers()
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
// Vitest Snapshot v1
|
||||
|
||||
exports[`renders 1`] = `
|
||||
<div class="message success" title="Click to dismiss" data-v-f05fd058="">
|
||||
<aside data-v-f05fd058=""><br data-testid="icon" icon="[object Object]" class="icon" data-v-f05fd058=""><br data-testid="icon" icon="[object Object]" class="icon-dismiss" data-v-f05fd058=""></aside>
|
||||
<main data-v-f05fd058=""></main>
|
||||
</div>
|
||||
`;
|
2
resources/assets/js/types.d.ts
vendored
2
resources/assets/js/types.d.ts
vendored
|
@ -408,5 +408,5 @@ type ToastMessage = {
|
|||
id: string
|
||||
type: 'info' | 'success' | 'warning' | 'danger'
|
||||
content: string
|
||||
timeout: number
|
||||
timeout: number // seconds
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue