@@ -57,7 +57,7 @@ suite('DatabaseTreeItem Test Suite', () => {
5757 . then ( done , done ) ;
5858 } ) ;
5959
60- test ( 'when expanded shows the collections of a database in tree' , ( done ) => {
60+ test ( 'when expanded shows the collections of a database in tree' , async ( ) => {
6161 const testDatabaseTreeItem = new DatabaseTreeItem (
6262 mockDatabaseNames [ 1 ] ,
6363 new DataServiceStub ( ) ,
@@ -68,22 +68,18 @@ suite('DatabaseTreeItem Test Suite', () => {
6868
6969 testDatabaseTreeItem . onDidExpand ( ) ;
7070
71- testDatabaseTreeItem
72- . getChildren ( )
73- . then ( ( collections ) => {
74- assert (
75- collections . length > 0 ,
76- `Expected more than one collection to be returned, recieved ${ collections . length } `
77- ) ;
71+ const collections = await testDatabaseTreeItem . getChildren ( ) ;
72+ assert (
73+ collections . length > 0 ,
74+ `Expected more than one collection to be returned, recieved ${ collections . length } `
75+ ) ;
7876
79- assert (
80- collections [ 1 ] . label ===
81- mockDatabases [ mockDatabaseNames [ 1 ] ] . collections [ 1 ] . name ,
82- `Expected a tree item child with the label collection name ${ mockDatabases [ mockDatabaseNames [ 1 ] ] . collections [ 1 ] . name
83- } found ${ collections [ 1 ] . label } `
84- ) ;
85- } )
86- . then ( done , done ) ;
77+ assert (
78+ collections [ 1 ] . label ===
79+ mockDatabases [ mockDatabaseNames [ 1 ] ] . collections [ 1 ] . name ,
80+ `Expected a tree item child with the label collection name ${ mockDatabases [ mockDatabaseNames [ 1 ] ] . collections [ 1 ] . name
81+ } found ${ collections [ 1 ] . label } `
82+ ) ;
8783 } ) ;
8884
8985 test ( 'when expanded and collapsed its collections cache their expanded documents' , async ( ) => {
@@ -150,7 +146,7 @@ suite('DatabaseTreeItem Test Suite', () => {
150146 ) ;
151147 } ) ;
152148
153- test ( 'collections are displayed in the alphanumerical case insensitive order, with system collections last' , ( done ) => {
149+ test ( 'collections are displayed in the alphanumerical case insensitive order, with system collections last' , async ( ) => {
154150 const testDatabaseTreeItem = new DatabaseTreeItem (
155151 mockDatabaseNames [ 2 ] ,
156152 new DataServiceStub ( ) ,
@@ -171,18 +167,15 @@ suite('DatabaseTreeItem Test Suite', () => {
171167 'system.views'
172168 ] ;
173169
174- testDatabaseTreeItem
175- . getChildren ( )
176- . then ( ( collectionTreeItems : CollectionTreeItem [ ] ) => {
177- assert . deepEqual (
178- collectionTreeItems
179- . map ( ( { collectionName } ) => collectionName )
180- . join ( ) ,
181- expectedCollectionsOrder . join ( ) ,
182- 'Expected collections to be in alphanumerical order but they were not'
183- ) ;
184- } )
185- . then ( done , done ) ;
170+ const collectionTreeItems : CollectionTreeItem [ ] = await testDatabaseTreeItem
171+ . getChildren ( ) ;
172+ assert . deepEqual (
173+ collectionTreeItems
174+ . map ( ( { collectionName } ) => collectionName )
175+ . join ( ) ,
176+ expectedCollectionsOrder . join ( ) ,
177+ 'Expected collections to be in alphanumerical order but they were not'
178+ ) ;
186179 } ) ;
187180
188181 suite ( 'Live Database Tests' , function ( ) {
@@ -192,7 +185,7 @@ suite('DatabaseTreeItem Test Suite', () => {
192185 await cleanupTestDB ( ) ;
193186 } ) ;
194187
195- test ( 'schema is cached when a database is collapsed and expanded' , ( done ) => {
188+ test ( 'schema is cached when a database is collapsed and expanded' , async ( ) => {
196189 const mockDocWithThirtyFields = {
197190 _id : 32 ,
198191 testerObject : {
@@ -203,106 +196,94 @@ suite('DatabaseTreeItem Test Suite', () => {
203196 mockDocWithThirtyFields [ `field${ i } ` ] = 'some value' ;
204197 }
205198
206- seedDataAndCreateDataService ( 'ramenNoodles' , [
199+ const dataService = await seedDataAndCreateDataService ( 'ramenNoodles' , [
207200 mockDocWithThirtyFields
208- ] ) . then ( ( dataService ) => {
209- const testDatabaseTreeItem = new DatabaseTreeItem (
210- TEST_DB_NAME ,
211- dataService ,
212- true ,
213- false ,
214- { }
215- ) ;
216-
217- testDatabaseTreeItem
218- . getChildren ( )
219- . then ( ( collectionTreeItems : CollectionTreeItem [ ] ) => {
220- assert (
221- collectionTreeItems [ 0 ] . isExpanded === false ,
222- 'Expected collection tree item not to be expanded on default.'
223- ) ;
224-
225- collectionTreeItems [ 0 ] . onDidExpand ( ) ;
226- const schemaTreeItem = collectionTreeItems [ 0 ] . getSchemaChild ( ) ;
227- if ( ! schemaTreeItem ) {
228- assert ( false , 'No schema tree item found on collection.' ) ;
229- return ;
230- }
231- schemaTreeItem . onDidExpand ( ) ;
232- schemaTreeItem . onShowMoreClicked ( ) ;
233-
234- schemaTreeItem . getChildren ( ) . then ( ( fields : any [ ] ) => {
235- const amountOfFields = fields . length ;
236- const expectedFields = 30 ;
237- assert (
238- expectedFields === amountOfFields ,
239- `Expected ${ expectedFields } fields, recieved ${ amountOfFields } `
240- ) ;
241-
242- assert (
243- ! ! schemaTreeItem . childrenCache . testerObject ,
244- 'Expected the subdocument field to be in the schema cache.'
245- ) ;
246- // Expand the subdocument.
247- schemaTreeItem . childrenCache . testerObject . onDidExpand ( ) ;
248-
249- testDatabaseTreeItem . onDidCollapse ( ) ;
250- testDatabaseTreeItem
251- . getChildren ( )
252- . then ( ( postCollapseCollectionTreeItems ) => {
253- assert (
254- postCollapseCollectionTreeItems . length === 0 ,
255- `Expected the database tree to return no children when collapsed, found ${ collectionTreeItems . length } `
256- ) ;
257-
258- testDatabaseTreeItem . onDidExpand ( ) ;
259- testDatabaseTreeItem
260- . getChildren ( )
261- . then ( ( newCollectionTreeItems ) => {
262- dataService . disconnect ( ( ) => { } ) ;
263-
264- const postCollapseSchemaTreeItem = newCollectionTreeItems [ 0 ] . getSchemaChild ( ) ;
265- assert (
266- postCollapseSchemaTreeItem . isExpanded === true ,
267- 'Expected collection tree item to be expanded from cache.'
268- ) ;
269-
270- postCollapseSchemaTreeItem
271- . getChildren ( )
272- . then ( ( fieldsPostCollapseExpand ) => {
273- // It should cache that we activated show more.
274- const amountOfCachedFields =
275- fieldsPostCollapseExpand . length ;
276- const expectedCachedFields = 30 ;
277- assert (
278- amountOfCachedFields === expectedCachedFields ,
279- `Expected a cached ${ expectedCachedFields } fields to be returned, found ${ amountOfCachedFields } `
280- ) ;
281-
282- const testerObjectField = fieldsPostCollapseExpand . find (
283- ( field ) => field . fieldName === 'testerObject'
284- ) ;
285-
286- assert (
287- ! ! testerObjectField ,
288- 'Expected the subdocument field to still be in the schema cache.'
289- ) ;
290- assert (
291- testerObjectField . isExpanded ,
292- 'Expected the subdocument field to still be expanded.'
293- ) ;
294- assert (
295- testerObjectField . collapsibleState ===
296- vscode . TreeItemCollapsibleState . Expanded ,
297- `Expected the subdocument field to have an expanded state (2), found ${ postCollapseSchemaTreeItem . childrenCache . testerObject . collapsibleState } .`
298- ) ;
299- } )
300- . then ( done , done ) ;
301- } , done ) ;
302- } , done ) ;
303- } , done ) ;
304- } , done ) ;
305- } ) ;
201+ ] ) ;
202+ const testDatabaseTreeItem = new DatabaseTreeItem (
203+ TEST_DB_NAME ,
204+ dataService ,
205+ true ,
206+ false ,
207+ { }
208+ ) ;
209+
210+ const collectionTreeItems : CollectionTreeItem [ ] = await testDatabaseTreeItem . getChildren ( ) ;
211+ assert (
212+ collectionTreeItems [ 0 ] . isExpanded === false ,
213+ 'Expected collection tree item not to be expanded on default.'
214+ ) ;
215+
216+ collectionTreeItems [ 0 ] . onDidExpand ( ) ;
217+ const schemaTreeItem = collectionTreeItems [ 0 ] . getSchemaChild ( ) ;
218+ if ( ! schemaTreeItem ) {
219+ assert ( false , 'No schema tree item found on collection.' ) ;
220+ return ;
221+ }
222+ schemaTreeItem . onDidExpand ( ) ;
223+ schemaTreeItem . onShowMoreClicked ( ) ;
224+
225+ const fields : any [ ] = await schemaTreeItem . getChildren ( ) ;
226+ const amountOfFields = fields . length ;
227+ const expectedFields = 30 ;
228+ assert (
229+ expectedFields === amountOfFields ,
230+ `Expected ${ expectedFields } fields, recieved ${ amountOfFields } `
231+ ) ;
232+
233+ assert (
234+ ! ! schemaTreeItem . childrenCache . testerObject ,
235+ 'Expected the subdocument field to be in the schema cache.'
236+ ) ;
237+ // Expand the subdocument.
238+ schemaTreeItem . childrenCache . testerObject . onDidExpand ( ) ;
239+
240+ testDatabaseTreeItem . onDidCollapse ( ) ;
241+ const postCollapseCollectionTreeItems = await testDatabaseTreeItem
242+ . getChildren ( ) ;
243+ assert (
244+ postCollapseCollectionTreeItems . length === 0 ,
245+ `Expected the database tree to return no children when collapsed, found ${ collectionTreeItems . length } `
246+ ) ;
247+
248+ testDatabaseTreeItem . onDidExpand ( ) ;
249+ const newCollectionTreeItems = await testDatabaseTreeItem
250+ . getChildren ( ) ;
251+ dataService . disconnect ( ( ) => { } ) ;
252+
253+ const postCollapseSchemaTreeItem = newCollectionTreeItems [ 0 ] . getSchemaChild ( ) ;
254+ assert (
255+ postCollapseSchemaTreeItem . isExpanded === true ,
256+ 'Expected collection tree item to be expanded from cache.'
257+ ) ;
258+
259+ const fieldsPostCollapseExpand = await postCollapseSchemaTreeItem
260+ . getChildren ( ) ;
261+ // It should cache that we activated show more.
262+ const amountOfCachedFields =
263+ fieldsPostCollapseExpand . length ;
264+ const expectedCachedFields = 30 ;
265+ assert (
266+ amountOfCachedFields === expectedCachedFields ,
267+ `Expected a cached ${ expectedCachedFields } fields to be returned, found ${ amountOfCachedFields } `
268+ ) ;
269+
270+ const testerObjectField = fieldsPostCollapseExpand . find (
271+ ( field ) => field . fieldName === 'testerObject'
272+ ) ;
273+
274+ assert (
275+ ! ! testerObjectField ,
276+ 'Expected the subdocument field to still be in the schema cache.'
277+ ) ;
278+ assert (
279+ testerObjectField . isExpanded ,
280+ 'Expected the subdocument field to still be expanded.'
281+ ) ;
282+ assert (
283+ testerObjectField . collapsibleState ===
284+ vscode . TreeItemCollapsibleState . Expanded ,
285+ `Expected the subdocument field to have an expanded state (2), found ${ postCollapseSchemaTreeItem . childrenCache . testerObject . collapsibleState } .`
286+ ) ;
306287 } ) ;
307288 } ) ;
308289} ) ;
0 commit comments