@@ -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