diff --git a/contentcuration/contentcuration/frontend/settings/pages/Account/index.vue b/contentcuration/contentcuration/frontend/settings/pages/Account/index.vue index 49cafe9816..ff66b59f0c 100644 --- a/contentcuration/contentcuration/frontend/settings/pages/Account/index.vue +++ b/contentcuration/contentcuration/frontend/settings/pages/Account/index.vue @@ -36,7 +36,7 @@ {{ fullName }} - + + + {{ $tr('exportAccountDataModalMessage') }} + @@ -154,7 +159,6 @@ import ChangePasswordForm from './ChangePasswordForm'; import DeleteAccountForm from './DeleteAccountForm'; import CopyToken from 'shared/views/CopyToken'; - import Alert from 'shared/views/Alert'; export default { name: 'Account', @@ -162,7 +166,6 @@ ChangePasswordForm, CopyToken, FullNameForm, - Alert, DeleteAccountForm, }, data() { @@ -235,6 +238,7 @@ exportAccountDataModalMessage: "You'll receive an email with your data when the export is completed", exportFailed: 'Unable to export data. Please try again.', + exportDataBtn: 'OK', }, }; diff --git a/contentcuration/contentcuration/frontend/settings/pages/__tests__/account.spec.js b/contentcuration/contentcuration/frontend/settings/pages/__tests__/account.spec.js index 8f0f1ee4aa..a6ab62b3f0 100644 --- a/contentcuration/contentcuration/frontend/settings/pages/__tests__/account.spec.js +++ b/contentcuration/contentcuration/frontend/settings/pages/__tests__/account.spec.js @@ -21,6 +21,11 @@ function makeWrapper(currentUser = {}) { FullNameForm: true, ChangePasswordForm: true, }, + mocks: { + $store: { + dispatch: jest.fn(), + }, + }, }); } @@ -52,22 +57,63 @@ describe('account tab', () => { }); }); - it('clicking name link should show name change form', () => { - wrapper.find('[data-test="name-form"]').trigger('click'); - expect(wrapper.vm.showFullNameForm).toBe(true); + it(`clicking 'Edit full name' link should show name change form`, () => { + wrapper.find('[data-test="edit-name-btn"]').trigger('click'); + const nameForm = wrapper.findComponent({ name: 'FullNameForm' }); + expect(nameForm.exists()).toBe(true); + expect(nameForm.isVisible()).toBe(true); + }); + + it(`clicking 'Change password' button should show password change form`, () => { + wrapper.find('[data-test="change-password-btn"]').trigger('click'); + const passwordForm = wrapper.findComponent({ name: 'ChangePasswordForm' }); + expect(passwordForm.exists()).toBe(true); + expect(passwordForm.isVisible()).toBe(true); }); - it('clicking password link should show password change form', () => { - wrapper.find('[data-test="password-form"]').trigger('click'); - expect(wrapper.vm.showPasswordForm).toBe(true); + describe('clicking export data button', () => { + let exportData; + + beforeEach(async () => { + exportData = jest.spyOn(wrapper.vm, 'exportData'); + exportData.mockImplementation(() => Promise.resolve()); + wrapper.find('[data-test="export-link"]').trigger('click'); + await wrapper.vm.$nextTick(); + }); + + it(`should call 'exportData'`, async () => { + expect(exportData).toHaveBeenCalled(); + }); + + it('should display export data notice', async () => { + const notice = wrapper.find('[data-test="export-notice"]'); + expect(notice.exists()).toBe(true); + expect(notice.isVisible()).toBe(true); + expect(notice.text()).toContain( + "You'll receive an email with your data when the export is completed", + ); + }); }); - it('clicking export data button should call exportData', async () => { - const exportData = jest.spyOn(wrapper.vm, 'exportData'); - exportData.mockImplementation(() => Promise.resolve()); - await wrapper.find('[data-test="export-link"]').trigger('click'); - expect(exportData).toHaveBeenCalled(); - await wrapper.vm.$nextTick(); - expect(wrapper.vm.showExportDataNotice).toBe(true); + describe('on export data failure', () => { + let exportData; + + beforeEach(async () => { + exportData = jest.spyOn(wrapper.vm, 'exportData'); + exportData.mockImplementation(() => Promise.reject('error')); + wrapper.find('[data-test="export-link"]').trigger('click'); + await wrapper.vm.$nextTick(); + }); + + it(`shouldn't display export data notice`, async () => { + const notice = wrapper.find('[data-test="export-notice"]'); + expect(notice.exists()).toBe(false); + }); + + it(`should call 'showSnackbar' with a correct message`, () => { + expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('showSnackbar', { + text: 'Unable to export data. Please try again.', + }); + }); }); });