koel/resources/assets/js/components/ui/upload/UploadItem.spec.ts

59 lines
1.5 KiB
TypeScript
Raw Normal View History

import { expect, it } from 'vitest'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import { screen } from '@testing-library/vue'
import { UploadFile, uploadService, UploadStatus } from '@/services'
2024-04-04 22:20:42 +00:00
import Btn from '@/components/ui/form/Btn.vue'
import UploadItem from './UploadItem.vue'
let file: UploadFile
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
protected test () {
it('renders', () => expect(this.renderComponent('Canceled').html()).toMatchSnapshot())
it.each<[UploadStatus]>([['Canceled'], ['Errored']])('allows retrying when %s', async status => {
const mock = this.mock(uploadService, 'retry')
this.renderComponent(status)
await this.user.click(screen.getByRole('button', { name: 'Retry' }))
expect(mock).toHaveBeenCalled()
})
it.each<[UploadStatus]>([
['Uploaded'],
['Errored'],
['Canceled']]
)('allows removal if not uploading', async status => {
const mock = this.mock(uploadService, 'remove')
this.renderComponent(status)
await this.user.click(screen.getByRole('button', { name: 'Remove' }))
expect(mock).toHaveBeenCalled()
})
}
2024-04-23 21:01:27 +00:00
private renderComponent (status: UploadStatus) {
file = {
status,
file: new File([], 'sample.mp3'),
id: 'x-file',
message: '',
name: 'Sample Track',
progress: 42
}
return this.render(UploadItem, {
props: {
file
},
global: {
stubs: {
Btn
}
}
})
}
}