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