Skip to content

Commit 5399b92

Browse files
committed
Cleanup few tests
Improve clarity and remove dependencies of tests on wrapper internal implementation
1 parent 30029a5 commit 5399b92

2 files changed

Lines changed: 54 additions & 24 deletions

File tree

contentcuration/contentcuration/frontend/settings/pages/Account/index.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
{{ fullName }}
3737
<KButton
3838
class="px-2"
39-
data-test="name-form"
39+
data-test="edit-name-btn"
4040
appearance="basic-link"
4141
:text="$tr('editFullNameAction')"
4242
@click="showFullNameForm = true"
@@ -54,7 +54,7 @@
5454
class="row"
5555
>
5656
<KButton
57-
data-test="password-form"
57+
data-test="change-password-btn"
5858
appearance="basic-link"
5959
:text="$tr('changePasswordAction')"
6060
@click="showPasswordForm = true"
@@ -142,6 +142,7 @@
142142
v-if="showExportDataNotice"
143143
:submitText="$tr('exportDataBtn')"
144144
:title="$tr('exportStartedHeader')"
145+
data-test="export-notice"
145146
@submit="showExportDataNotice = false"
146147
>
147148
{{ $tr('exportAccountDataModalMessage') }}

contentcuration/contentcuration/frontend/settings/pages/__tests__/account.spec.js

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function makeWrapper(currentUser = {}) {
2525
$store: {
2626
dispatch: jest.fn(),
2727
},
28-
$tr: text => text,
2928
},
3029
});
3130
}
@@ -58,33 +57,63 @@ describe('account tab', () => {
5857
});
5958
});
6059

61-
it('clicking name link should show name change form', () => {
62-
wrapper.find('[data-test="name-form"]').trigger('click');
63-
expect(wrapper.vm.showFullNameForm).toBe(true);
60+
it(`clicking 'Edit full name' link should show name change form`, () => {
61+
wrapper.find('[data-test="edit-name-btn"]').trigger('click');
62+
const nameForm = wrapper.findComponent({ name: 'FullNameForm' });
63+
expect(nameForm.exists()).toBe(true);
64+
expect(nameForm.isVisible()).toBe(true);
6465
});
6566

66-
it('clicking password link should show password change form', () => {
67-
wrapper.find('[data-test="password-form"]').trigger('click');
68-
expect(wrapper.vm.showPasswordForm).toBe(true);
67+
it(`clicking 'Change password' button should show password change form`, () => {
68+
wrapper.find('[data-test="change-password-btn"]').trigger('click');
69+
const passwordForm = wrapper.findComponent({ name: 'ChangePasswordForm' });
70+
expect(passwordForm.exists()).toBe(true);
71+
expect(passwordForm.isVisible()).toBe(true);
6972
});
7073

71-
it('clicking export data button should call exportData', async () => {
72-
const exportData = jest.spyOn(wrapper.vm, 'exportData');
73-
exportData.mockImplementation(() => Promise.resolve());
74-
await wrapper.find('[data-test="export-link"]').trigger('click');
75-
expect(exportData).toHaveBeenCalled();
76-
await wrapper.vm.$nextTick();
77-
expect(wrapper.vm.showExportDataNotice).toBe(true);
74+
describe('clicking export data button', () => {
75+
let exportData;
76+
77+
beforeEach(async () => {
78+
exportData = jest.spyOn(wrapper.vm, 'exportData');
79+
exportData.mockImplementation(() => Promise.resolve());
80+
wrapper.find('[data-test="export-link"]').trigger('click');
81+
await wrapper.vm.$nextTick();
82+
});
83+
84+
it(`should call 'exportData'`, async () => {
85+
expect(exportData).toHaveBeenCalled();
86+
});
87+
88+
it('should display export data notice', async () => {
89+
const notice = wrapper.find('[data-test="export-notice"]');
90+
expect(notice.exists()).toBe(true);
91+
expect(notice.isVisible()).toBe(true);
92+
expect(notice.text()).toContain(
93+
"You'll receive an email with your data when the export is completed",
94+
);
95+
});
7896
});
7997

80-
it('export data failure', async () => {
81-
const exportData = jest.spyOn(wrapper.vm, 'exportData');
82-
exportData.mockImplementation(() => Promise.reject('error'));
83-
await wrapper.find('[data-test="export-link"]').trigger('click');
84-
expect(exportData).toHaveBeenCalled();
85-
expect(wrapper.vm.showExportDataNotice).toBe(false);
86-
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('showSnackbar', {
87-
text: wrapper.vm.$tr('exportFailed'),
98+
describe('on export data failure', () => {
99+
let exportData;
100+
101+
beforeEach(async () => {
102+
exportData = jest.spyOn(wrapper.vm, 'exportData');
103+
exportData.mockImplementation(() => Promise.reject('error'));
104+
wrapper.find('[data-test="export-link"]').trigger('click');
105+
await wrapper.vm.$nextTick();
106+
});
107+
108+
it(`shouldn't display export data notice`, async () => {
109+
const notice = wrapper.find('[data-test="export-notice"]');
110+
expect(notice.exists()).toBe(false);
111+
});
112+
113+
it(`should call 'showSnackbar' with a correct message`, () => {
114+
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('showSnackbar', {
115+
text: 'Unable to export data. Please try again.',
116+
});
88117
});
89118
});
90119
});

0 commit comments

Comments
 (0)