Skip to content

Commit 8a35241

Browse files
authored
Merge pull request #5083 from yeshwanth235/issue-5063
issue-5063 changes
2 parents efb74db + 81550c3 commit 8a35241

2 files changed

Lines changed: 72 additions & 22 deletions

File tree

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

Lines changed: 13 additions & 9 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"
@@ -137,11 +137,16 @@
137137
<FullNameForm v-model="showFullNameForm" />
138138
<ChangePasswordForm v-model="showPasswordForm" />
139139
<DeleteAccountForm v-model="showDeleteConfirmation" />
140-
<Alert
141-
v-model="showExportDataNotice"
142-
:header="$tr('exportStartedHeader')"
143-
:text="$tr('exportAccountDataModalMessage')"
144-
/>
140+
141+
<KModal
142+
v-if="showExportDataNotice"
143+
:submitText="$tr('exportDataBtn')"
144+
:title="$tr('exportStartedHeader')"
145+
data-test="export-notice"
146+
@submit="showExportDataNotice = false"
147+
>
148+
{{ $tr('exportAccountDataModalMessage') }}
149+
</KModal>
145150
</div>
146151

147152
</template>
@@ -154,15 +159,13 @@
154159
import ChangePasswordForm from './ChangePasswordForm';
155160
import DeleteAccountForm from './DeleteAccountForm';
156161
import CopyToken from 'shared/views/CopyToken';
157-
import Alert from 'shared/views/Alert';
158162
159163
export default {
160164
name: 'Account',
161165
components: {
162166
ChangePasswordForm,
163167
CopyToken,
164168
FullNameForm,
165-
Alert,
166169
DeleteAccountForm,
167170
},
168171
data() {
@@ -235,6 +238,7 @@
235238
exportAccountDataModalMessage:
236239
"You'll receive an email with your data when the export is completed",
237240
exportFailed: 'Unable to export data. Please try again.',
241+
exportDataBtn: 'OK',
238242
},
239243
};
240244

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

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ function makeWrapper(currentUser = {}) {
2121
FullNameForm: true,
2222
ChangePasswordForm: true,
2323
},
24+
mocks: {
25+
$store: {
26+
dispatch: jest.fn(),
27+
},
28+
},
2429
});
2530
}
2631

@@ -52,22 +57,63 @@ describe('account tab', () => {
5257
});
5358
});
5459

55-
it('clicking name link should show name change form', () => {
56-
wrapper.find('[data-test="name-form"]').trigger('click');
57-
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);
65+
});
66+
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);
5872
});
5973

60-
it('clicking password link should show password change form', () => {
61-
wrapper.find('[data-test="password-form"]').trigger('click');
62-
expect(wrapper.vm.showPasswordForm).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+
});
6396
});
6497

65-
it('clicking export data button should call exportData', async () => {
66-
const exportData = jest.spyOn(wrapper.vm, 'exportData');
67-
exportData.mockImplementation(() => Promise.resolve());
68-
await wrapper.find('[data-test="export-link"]').trigger('click');
69-
expect(exportData).toHaveBeenCalled();
70-
await wrapper.vm.$nextTick();
71-
expect(wrapper.vm.showExportDataNotice).toBe(true);
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+
});
117+
});
72118
});
73119
});

0 commit comments

Comments
 (0)