Skip to content

Commit 1330bf0

Browse files
[Remove Vuetify from Studio] Convert supplementary item unit tests to Vue Testing Library (#5937)
* refactor: migrate supplementaryItem tests to Vue Testing Library * Removed: uploadingHandler test * address pr review feedback --------- Co-authored-by: Samson Akol <akolson2010@gmail.com>
1 parent d6ad577 commit 1330bf0

1 file changed

Lines changed: 28 additions & 39 deletions

File tree

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
import { mount } from '@vue/test-utils';
1+
import { render, screen, configure } from '@testing-library/vue';
2+
import userEvent from '@testing-library/user-event';
3+
import VueRouter from 'vue-router';
24
import SupplementaryItem from '../supplementaryLists/SupplementaryItem';
35
import { factory } from '../../../store';
4-
import Uploader from 'shared/views/files/Uploader';
56

6-
function makeWrapper(props = {}) {
7+
configure({ testIdAttribute: 'data-test' });
8+
9+
const router = new VueRouter();
10+
11+
function renderComponent(props = {}) {
712
const store = factory();
8-
return mount(SupplementaryItem, {
13+
return render(SupplementaryItem, {
14+
router,
915
store,
1016
attachTo: document.body,
11-
propsData: {
17+
props: {
1218
fileId: 'test',
1319
presetID: 'video_subtitle',
20+
...props,
1421
},
1522
computed: {
1623
file() {
@@ -28,48 +35,30 @@ function makeWrapper(props = {}) {
2835
}
2936

3037
describe('supplementaryItem', () => {
31-
let wrapper;
32-
33-
beforeEach(() => {
34-
wrapper = makeWrapper();
35-
});
36-
37-
it('setting readonly should disable uploading', async () => {
38-
await wrapper.setProps({ readonly: true });
39-
expect(wrapper.findComponent('[data-test="upload-file"]').exists()).toBe(false);
40-
});
41-
42-
it('setting readonly should disable removing', async () => {
43-
await wrapper.setProps({ readonly: true });
44-
expect(wrapper.findComponent('[data-test="remove"]').exists()).toBe(false);
45-
});
46-
47-
it('should call uploadingHandler when Uploader starts uploading file', async () => {
48-
wrapper.findComponent(Uploader).vm.uploadingHandler({ id: 'file1' });
49-
expect(wrapper.vm.fileUploadId).toBe('file1');
38+
it('setting readonly should disable uploading', () => {
39+
renderComponent({ readonly: true });
40+
expect(screen.queryByTestId('upload-file')).not.toBeInTheDocument();
5041
});
5142

52-
it('should call uploadCompleteHandler when Uploader finishes uploading file', async () => {
53-
const uploadCompleteHandler = jest.fn();
54-
await wrapper.setProps({ uploadCompleteHandler });
55-
wrapper.findComponent(Uploader).vm.uploadCompleteHandler({ id: 'file1' });
56-
expect(uploadCompleteHandler).toHaveBeenCalledWith({ id: 'file1' });
43+
it('setting readonly should disable removing', () => {
44+
renderComponent({ readonly: true });
45+
expect(screen.queryByTestId('remove')).not.toBeInTheDocument();
5746
});
5847

59-
it('uploading should be true if progress < 1', async () => {
60-
expect(wrapper.findComponent('[data-test="uploading"]').exists()).toBe(false);
61-
const testwrapper = makeWrapper({ progress: 0.5 });
62-
expect(testwrapper.findComponent('[data-test="uploading"]').exists()).toBe(true);
48+
it('shows an upload status indicator while a file is uploading', () => {
49+
renderComponent({ progress: 0.5 });
50+
expect(screen.queryByTestId('uploading')).toBeInTheDocument();
6351
});
6452

65-
it('should disable ability to upload other files during a file upload', async () => {
66-
const testwrapper = makeWrapper({ progress: 0.5 });
67-
expect(testwrapper.findComponent('[data-test="upload-file"]').exists()).toBe(false);
53+
it('should disable ability to upload other files during a file upload', () => {
54+
renderComponent({ progress: 0.5 });
55+
expect(screen.queryByTestId('upload-file')).not.toBeInTheDocument();
6856
});
6957

7058
it('clicking remove button should emit remove event with file id', async () => {
71-
const wrapper = makeWrapper({ id: 'test-remove' });
72-
await wrapper.findComponent('[data-test="remove"]').trigger('click');
73-
expect(wrapper.emitted('remove')[0][0]).toBe('test-remove');
59+
const user = userEvent.setup();
60+
const { emitted } = renderComponent({ id: 'test-remove' });
61+
await user.click(screen.getByTestId('remove'));
62+
expect(emitted().remove[0][0]).toBe('test-remove');
7463
});
7564
});

0 commit comments

Comments
 (0)