2022-05-10 16:05:03 +00:00
|
|
|
import { expect, it } from 'vitest'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-10-08 10:54:25 +00:00
|
|
|
import { UploadFile, uploadService, UploadStatus } from '@/services'
|
2022-05-10 16:05:03 +00:00
|
|
|
import Btn from '@/components/ui/Btn.vue'
|
|
|
|
import UploadItem from './UploadItem.vue'
|
|
|
|
|
|
|
|
let file: UploadFile
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-10 16:05:03 +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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('renders', () => expect(this.renderComponent('Canceled').html()).toMatchSnapshot())
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
it.each<[UploadStatus]>([['Canceled'], ['Errored']])('allows retrying when %s', async status => {
|
2022-05-10 16:05:03 +00:00
|
|
|
const mock = this.mock(uploadService, 'retry')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent(status)
|
2022-05-10 16:05:03 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Retry' }))
|
2022-05-10 16:05:03 +00:00
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
it.each<[UploadStatus]>([
|
|
|
|
['Uploaded'],
|
|
|
|
['Errored'],
|
|
|
|
['Canceled']]
|
2022-11-29 10:18:58 +00:00
|
|
|
)('allows removal if not uploading', async status => {
|
2022-05-10 16:05:03 +00:00
|
|
|
const mock = this.mock(uploadService, 'remove')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent(status)
|
2022-05-10 16:05:03 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Remove' }))
|
2022-05-10 16:05:03 +00:00
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|