mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2026-01-20 20:01:22 +00:00
Add tests to upload error bug fix
Co-authored-by: mattwr18 <mattwr18@gmail.com>
This commit is contained in:
parent
0111e60f1d
commit
78100bec37
@ -26,6 +26,7 @@ describe('Upload', () => {
|
||||
success: jest.fn(),
|
||||
error: jest.fn(),
|
||||
},
|
||||
$t: jest.fn(),
|
||||
}
|
||||
|
||||
const propsData = {
|
||||
@ -34,7 +35,7 @@ describe('Upload', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const file = {
|
||||
const fileSuccess = {
|
||||
filename: 'avatar.jpg',
|
||||
previewElement: {
|
||||
classList: {
|
||||
@ -59,13 +60,38 @@ describe('Upload', () => {
|
||||
wrapper = shallowMount(Upload, { localVue, propsData, mocks })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it('sends a the UpdateUser mutation when vddrop is called', () => {
|
||||
wrapper.vm.vddrop([{ filename: 'avatar.jpg' }])
|
||||
expect(mocks.$apollo.mutate).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('thumbnail', () => {
|
||||
wrapper.vm.thumbnail(file, dataUrl)
|
||||
expect(file.previewElement.classList.add).toHaveBeenCalledTimes(1)
|
||||
wrapper.vm.thumbnail(fileSuccess, dataUrl)
|
||||
expect(fileSuccess.previewElement.classList.add).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
describe('error handling', () => {
|
||||
const message = 'File upload failed'
|
||||
const fileError = { status: 'error' }
|
||||
|
||||
it('defaults to error false', () => {
|
||||
expect(wrapper.vm.error).toEqual(false)
|
||||
})
|
||||
|
||||
it('shows an error toaster when verror is called', () => {
|
||||
wrapper.vm.verror(fileError, message)
|
||||
expect(mocks.$toast.error).toHaveBeenCalledWith(fileError.status, message)
|
||||
})
|
||||
|
||||
it('changes error status from false to true to false', () => {
|
||||
wrapper.vm.verror(fileError, message)
|
||||
expect(wrapper.vm.error).toEqual(true)
|
||||
jest.runAllTimers()
|
||||
expect(wrapper.vm.error).toEqual(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user