46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
|
import { mount } from '@vue/test-utils';
|
||
|
import { describe, it, expect, vi } from 'vitest';
|
||
|
import VFileUpload from '../src/components/file/VFileUpload.vue'
|
||
|
|
||
|
describe('VFileUpload emits', () => {
|
||
|
it('doit émettre les événements personnalisés', async () => {
|
||
|
// Création des mocks
|
||
|
const onSelect = vi.fn();
|
||
|
const onUpload = vi.fn();
|
||
|
const onError = vi.fn();
|
||
|
const onRemove = vi.fn();
|
||
|
const onClear = vi.fn();
|
||
|
|
||
|
const wrapper = mount(VFileUpload, {
|
||
|
props: {
|
||
|
advanced: true,
|
||
|
onSelect,
|
||
|
onUpload,
|
||
|
onError,
|
||
|
onRemove,
|
||
|
onClear
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// Simule une sélection de fichier
|
||
|
await wrapper.vm.$emit('select', { files: [{ name: 'test.png' }] });
|
||
|
expect(onSelect).toHaveBeenCalledWith({ files: [{ name: 'test.png' }] });
|
||
|
|
||
|
// Simule une erreur
|
||
|
await wrapper.vm.$emit('error', { message: 'Erreur test' });
|
||
|
expect(onError).toHaveBeenCalledWith({ message: 'Erreur test' });
|
||
|
|
||
|
// Simule un upload
|
||
|
await wrapper.vm.$emit('upload', { files: ['fichier1'] });
|
||
|
expect(onUpload).toHaveBeenCalledWith({ files: ['fichier1'] });
|
||
|
|
||
|
// Simule une suppression
|
||
|
await wrapper.vm.$emit('remove', { file: 'test.png' });
|
||
|
expect(onRemove).toHaveBeenCalledWith({ file: 'test.png' });
|
||
|
|
||
|
// Simule un clear
|
||
|
await wrapper.vm.$emit('clear');
|
||
|
expect(onClear).toHaveBeenCalled();
|
||
|
});
|
||
|
});
|