@@ -8,7 +8,7 @@ import { DbManager } from '../../../databases/db-manager';
88import { DbConfigStore } from '../../../databases/config/db-config-store' ;
99import { DbTreeDataProvider } from '../../../databases/ui/db-tree-data-provider' ;
1010import { DbPanel } from '../../../databases/ui/db-panel' ;
11- import { DbItemKind } from '../../../databases/db-item' ;
11+ import { DbItemKind , LocalDatabaseDbItem } from '../../../databases/db-item' ;
1212import { DbTreeViewItem } from '../../../databases/ui/db-tree-view-item' ;
1313import { ExtensionApp } from '../../../common/vscode/vscode-app' ;
1414import { createMockExtensionContext } from '../../factories/extension-context' ;
@@ -235,6 +235,151 @@ describe('db panel', async () => {
235235 checkRemoteRepoItem ( repoItems [ 1 ] , 'owner1/repo2' ) ;
236236 } ) ;
237237
238+ it ( 'should render local list nodes' , async ( ) => {
239+ const dbConfig : DbConfig = {
240+ databases : {
241+ remote : {
242+ repositoryLists : [ ] ,
243+ owners : [ ] ,
244+ repositories : [ ]
245+ } ,
246+ local : {
247+ lists : [
248+ {
249+ name : 'my-list-1' ,
250+ databases : [
251+ {
252+ name : 'db1' ,
253+ dateAdded : 1668428293677 ,
254+ language : 'cpp' ,
255+ storagePath : '/path/to/db1/' ,
256+ } ,
257+ {
258+ name : 'db2' ,
259+ dateAdded : 1668428472731 ,
260+ language : 'cpp' ,
261+ storagePath : '/path/to/db2/' ,
262+ } ,
263+ ] ,
264+ } ,
265+ {
266+ name : 'my-list-2' ,
267+ databases : [
268+ {
269+ name : 'db3' ,
270+ dateAdded : 1668428472731 ,
271+ language : 'ruby' ,
272+ storagePath : '/path/to/db3/' ,
273+ } ,
274+ ] ,
275+ } ,
276+ ] ,
277+ databases : [ ]
278+ } ,
279+ } ,
280+ } ;
281+
282+ await saveDbConfig ( dbConfig ) ;
283+
284+ const dbTreeItems = await dbTreeDataProvider . getChildren ( ) ;
285+
286+ expect ( dbTreeItems ) . to . be . ok ;
287+ const items = dbTreeItems ! ;
288+ expect ( items . length ) . to . equal ( 2 ) ;
289+
290+ const localRootNode = items [ 1 ] ;
291+ expect ( localRootNode . dbItem ) . to . be . ok ;
292+ expect ( localRootNode . collapsibleState ) . to . equal ( vscode . TreeItemCollapsibleState . Collapsed ) ;
293+ expect ( localRootNode . children ) . to . be . ok ;
294+ expect ( localRootNode . children . length ) . to . equal ( 2 ) ;
295+
296+ const localListItems = localRootNode . children . filter ( item => item . dbItem ?. kind === DbItemKind . LocalList ) ;
297+ expect ( localListItems . length ) . to . equal ( 2 ) ;
298+ checkLocalListItem ( localListItems [ 0 ] , 'my-list-1' , [ {
299+ kind : DbItemKind . LocalDatabase ,
300+ databaseName : 'db1' ,
301+ dateAdded : 1668428293677 ,
302+ language : 'cpp' ,
303+ storagePath : '/path/to/db1/' ,
304+ } ,
305+ {
306+ kind : DbItemKind . LocalDatabase ,
307+ databaseName : 'db2' ,
308+ dateAdded : 1668428472731 ,
309+ language : 'cpp' ,
310+ storagePath : '/path/to/db2/' ,
311+ } ] ) ;
312+ checkLocalListItem ( localListItems [ 1 ] , 'my-list-2' , [
313+ {
314+ kind : DbItemKind . LocalDatabase ,
315+ databaseName : 'db3' ,
316+ dateAdded : 1668428472731 ,
317+ language : 'ruby' ,
318+ storagePath : '/path/to/db3/' ,
319+ } ,
320+ ] ) ;
321+ } ) ;
322+
323+ it ( 'should render local database nodes' , async ( ) => {
324+ const dbConfig : DbConfig = {
325+ databases : {
326+ remote : {
327+ repositoryLists : [ ] ,
328+ owners : [ ] ,
329+ repositories : [ ]
330+ } ,
331+ local : {
332+ lists : [ ] ,
333+ databases : [
334+ {
335+ name : 'db1' ,
336+ dateAdded : 1668428293677 ,
337+ language : 'csharp' ,
338+ storagePath : '/path/to/db1/' ,
339+ } ,
340+ {
341+ name : 'db2' ,
342+ dateAdded : 1668428472731 ,
343+ language : 'go' ,
344+ storagePath : '/path/to/db2/' ,
345+ }
346+ ]
347+ }
348+ }
349+ } ;
350+
351+ await saveDbConfig ( dbConfig ) ;
352+
353+ const dbTreeItems = await dbTreeDataProvider . getChildren ( ) ;
354+
355+ expect ( dbTreeItems ) . to . be . ok ;
356+ const items = dbTreeItems ! ;
357+ expect ( items . length ) . to . equal ( 2 ) ;
358+
359+ const localRootNode = items [ 1 ] ;
360+ expect ( localRootNode . dbItem ) . to . be . ok ;
361+ expect ( localRootNode . collapsibleState ) . to . equal ( vscode . TreeItemCollapsibleState . Collapsed ) ;
362+ expect ( localRootNode . children ) . to . be . ok ;
363+ expect ( localRootNode . children . length ) . to . equal ( 2 ) ;
364+
365+ const localDatabaseItems = localRootNode . children . filter ( item => item . dbItem ?. kind === DbItemKind . LocalDatabase ) ;
366+ expect ( localDatabaseItems . length ) . to . equal ( 2 ) ;
367+ checkLocalDatabaseItem ( localDatabaseItems [ 0 ] , {
368+ kind : DbItemKind . LocalDatabase ,
369+ databaseName : 'db1' ,
370+ dateAdded : 1668428293677 ,
371+ language : 'csharp' ,
372+ storagePath : '/path/to/db1/' ,
373+ } ) ;
374+ checkLocalDatabaseItem ( localDatabaseItems [ 1 ] , {
375+ kind : DbItemKind . LocalDatabase ,
376+ databaseName : 'db2' ,
377+ dateAdded : 1668428472731 ,
378+ language : 'go' ,
379+ storagePath : '/path/to/db2/' ,
380+ } ) ;
381+ } ) ;
382+
238383 async function saveDbConfig ( dbConfig : DbConfig ) : Promise < void > {
239384 await fs . writeJson ( dbConfigFilePath , dbConfig ) ;
240385
@@ -294,4 +439,31 @@ describe('db panel', async () => {
294439 expect ( item . iconPath ) . to . deep . equal ( new vscode . ThemeIcon ( 'database' ) ) ;
295440 expect ( item . collapsibleState ) . to . equal ( vscode . TreeItemCollapsibleState . None ) ;
296441 }
442+
443+ function checkLocalListItem (
444+ item : DbTreeViewItem ,
445+ listName : string ,
446+ databases : LocalDatabaseDbItem [ ]
447+ ) : void {
448+ expect ( item . label ) . to . equal ( listName ) ;
449+ expect ( item . tooltip ) . to . be . undefined ;
450+ expect ( item . iconPath ) . to . be . undefined ;
451+ expect ( item . collapsibleState ) . to . equal ( vscode . TreeItemCollapsibleState . Collapsed ) ;
452+ expect ( item . children ) . to . be . ok ;
453+ expect ( item . children . length ) . to . equal ( databases . length ) ;
454+
455+ for ( let i = 0 ; i < databases . length ; i ++ ) {
456+ checkLocalDatabaseItem ( item . children [ i ] , databases [ i ] ) ;
457+ }
458+ }
459+
460+ function checkLocalDatabaseItem (
461+ item : DbTreeViewItem ,
462+ database : LocalDatabaseDbItem ,
463+ ) : void {
464+ expect ( item . label ) . to . equal ( database . databaseName ) ;
465+ expect ( item . tooltip ) . to . equal ( `Language: ${ database . language } ` ) ;
466+ expect ( item . iconPath ) . to . deep . equal ( new vscode . ThemeIcon ( 'database' ) ) ;
467+ expect ( item . collapsibleState ) . to . equal ( vscode . TreeItemCollapsibleState . None ) ;
468+ }
297469} ) ;
0 commit comments