@@ -17,6 +17,7 @@ describe('Component: Google File Picker', () => {
1717 loadGapiModules : jest . fn ( ) . mockReturnValue ( of ( void 0 ) ) ,
1818 } ;
1919
20+ const handleFolderSelection = jest . fn ( ) ;
2021 const setDeveloperKey = jest . fn ( ) . mockReturnThis ( ) ;
2122 const setAppId = jest . fn ( ) . mockReturnThis ( ) ;
2223 const addView = jest . fn ( ) . mockReturnThis ( ) ;
@@ -39,6 +40,18 @@ describe('Component: Google File Picker', () => {
3940 selectSnapshot : jest . fn ( ) . mockReturnValue ( 'mock-token' ) ,
4041 } ;
4142
43+ beforeAll ( ( ) => {
44+ window . google = {
45+ picker : {
46+ Action : null ,
47+ } ,
48+ } ;
49+ } ) ;
50+
51+ afterAll ( ( ) => {
52+ delete ( window as any ) . google ;
53+ } ) ;
54+
4255 describe ( 'isFolderPicker - true' , ( ) => {
4356 beforeEach ( async ( ) => {
4457 jest . clearAllMocks ( ) ;
@@ -84,8 +97,10 @@ describe('Component: Google File Picker', () => {
8497 fixture = TestBed . createComponent ( GoogleFilePickerComponent ) ;
8598 component = fixture . componentInstance ;
8699 fixture . componentRef . setInput ( 'isFolderPicker' , true ) ;
87- fixture . componentRef . setInput ( 'rootFolderId' , 'root-folder-id' ) ;
88- fixture . componentRef . setInput ( 'selectedFolderName' , 'selected-folder-name' ) ;
100+ fixture . componentRef . setInput ( 'rootFolder' , {
101+ itemId : 'root-folder-id' ,
102+ } ) ;
103+ fixture . componentRef . setInput ( 'handleFolderSelection' , handleFolderSelection ) ;
89104 fixture . componentRef . setInput ( 'accountId' , 'account-id' ) ;
90105 fixture . detectChanges ( ) ;
91106 } ) ;
@@ -118,6 +133,41 @@ describe('Component: Google File Picker', () => {
118133 expect ( build ) . toHaveBeenCalledWith ( ) ;
119134 expect ( setVisible ) . toHaveBeenCalledWith ( true ) ;
120135 } ) ;
136+
137+ describe ( 'pickerCallback' , ( ) => {
138+ it ( 'should handle a folder selection `PICKED` action' , ( ) => {
139+ window . google . picker . Action = {
140+ PICKED : 'PICKED' ,
141+ } ;
142+ component . pickerCallback (
143+ Object ( {
144+ action : 'PICKED' ,
145+ docs : [
146+ Object ( {
147+ itemId : 'item id' ,
148+ itemName : 'item name' ,
149+ } ) ,
150+ ] ,
151+ } )
152+ ) ;
153+
154+ expect ( handleFolderSelection ) . toHaveBeenCalledWith ( Object ( { } ) ) ;
155+ } ) ;
156+
157+ it ( 'should handle a folder selection not `PICKED` action' , ( ) => {
158+ window . google . picker . Action = {
159+ PICKED : 'not picked' ,
160+ } ;
161+
162+ component . pickerCallback (
163+ Object ( {
164+ action : 'Loading' ,
165+ } )
166+ ) ;
167+
168+ expect ( handleFolderSelection ) . not . toHaveBeenCalled ( ) ;
169+ } ) ;
170+ } ) ;
121171 } ) ;
122172
123173 describe ( 'isFolderPicker - false' , ( ) => {
@@ -164,8 +214,10 @@ describe('Component: Google File Picker', () => {
164214 fixture = TestBed . createComponent ( GoogleFilePickerComponent ) ;
165215 component = fixture . componentInstance ;
166216 fixture . componentRef . setInput ( 'isFolderPicker' , false ) ;
167- fixture . componentRef . setInput ( 'rootFolderId' , 'root-folder-id' ) ;
168- fixture . componentRef . setInput ( 'selectedFolderName' , 'selected-folder-name' ) ;
217+ fixture . componentRef . setInput ( 'rootFolder' , {
218+ itemId : 'root-folder-id' ,
219+ } ) ;
220+ fixture . componentRef . setInput ( 'handleFolderSelection' , jest . fn ( ) ) ;
169221 fixture . detectChanges ( ) ;
170222 } ) ;
171223
0 commit comments