@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest'
22import { buildTree , findParentFromId , findItemFromRoute , findItemFromId , findDescendantsFileItemsFromId , getTreeStatus } from '../../../src/utils/tree'
33import { tree } from '../../../test/mocks/tree'
44import type { TreeItem } from '../../../src/types/tree'
5- import { dbItemsList , nestedDbItemsList } from '../../../test/mocks/database'
5+ import { dbItemsList , languagePrefixedDbItemsList , nestedDbItemsList } from '../../../test/mocks/database'
66import type { DraftItem } from '../../../src/types/draft'
77import type { MediaItem } from '../../../src/types'
88import { DraftStatus , TreeRootId , TreeStatus } from '../../../src/types'
@@ -22,10 +22,9 @@ describe('buildTree of documents with one level of depth', () => {
2222 prefix : null ,
2323 } ,
2424 {
25- id : 'docs/ 1.getting-started' ,
25+ id : '1.getting-started' ,
2626 name : 'getting-started' ,
2727 fsPath : '1.getting-started' ,
28- routePath : '/getting-started' ,
2928 type : 'directory' ,
3029 prefix : 1 ,
3130 children : [
@@ -310,10 +309,9 @@ describe('buildTree of documents with one level of depth', () => {
310309describe ( 'buildTree of documents with two levels of depth' , ( ) => {
311310 const result : TreeItem [ ] = [
312311 {
313- id : 'docs/ 1.essentials' ,
312+ id : '1.essentials' ,
314313 name : 'essentials' ,
315314 fsPath : '1.essentials' ,
316- routePath : '/essentials' ,
317315 type : 'directory' ,
318316 prefix : 1 ,
319317 children : [
@@ -326,10 +324,9 @@ describe('buildTree of documents with two levels of depth', () => {
326324 prefix : 2 ,
327325 } ,
328326 {
329- id : 'docs/ 1.essentials/1.nested' ,
327+ id : '1.essentials/1.nested' ,
330328 name : 'nested' ,
331329 fsPath : '1.essentials/1.nested' ,
332- routePath : '/essentials/nested' ,
333330 type : 'directory' ,
334331 prefix : 1 ,
335332 children : [
@@ -460,7 +457,59 @@ describe('buildTree of documents with two levels of depth', () => {
460457 } )
461458} )
462459
463- describe ( 'buildTree od medias' , ( ) => {
460+ describe ( 'buildTree of documents with language prefixed' , ( ) => {
461+ const result : TreeItem [ ] = [
462+ {
463+ id : 'en' ,
464+ name : 'en' ,
465+ fsPath : 'en' ,
466+ type : 'directory' ,
467+ prefix : null ,
468+ children : [
469+ {
470+ id : 'landing_en/en/index.md' ,
471+ name : 'index' ,
472+ fsPath : 'en/index.md' ,
473+ prefix : null ,
474+ type : 'file' ,
475+ routePath : '/en' ,
476+ } ,
477+ {
478+ id : 'en/1.getting-started' ,
479+ name : 'getting-started' ,
480+ fsPath : 'en/1.getting-started' ,
481+ type : 'directory' ,
482+ prefix : 1 ,
483+ children : [
484+ {
485+ id : 'docs_en/en/1.getting-started/2.introduction.md' ,
486+ name : 'introduction' ,
487+ fsPath : 'en/1.getting-started/2.introduction.md' ,
488+ type : 'file' ,
489+ routePath : '/en/getting-started/introduction' ,
490+ prefix : 2 ,
491+ } ,
492+ {
493+ id : 'docs_en/en/1.getting-started/3.installation.md' ,
494+ name : 'installation' ,
495+ fsPath : 'en/1.getting-started/3.installation.md' ,
496+ type : 'file' ,
497+ routePath : '/en/getting-started/installation' ,
498+ prefix : 3 ,
499+ } ,
500+ ] ,
501+ } ,
502+ ] ,
503+ } ,
504+ ]
505+
506+ it ( 'Without draft' , ( ) => {
507+ const tree = buildTree ( languagePrefixedDbItemsList , null )
508+ expect ( tree ) . toStrictEqual ( result )
509+ } )
510+ } )
511+
512+ describe ( 'buildTree of medias' , ( ) => {
464513 it ( 'With .gitkeep file in directory (file is marked as hidden)' , ( ) => {
465514 const mediaFolderName = 'media-folder'
466515 const gitKeepId = joinURL ( TreeRootId . Media , mediaFolderName , '.gitkeep' )
@@ -493,7 +542,7 @@ describe('buildTree od medias', () => {
493542 const tree = buildTree ( [ gitkeepDbItem , mediaDbItem ] , draftList )
494543
495544 expect ( tree ) . toHaveLength ( 1 )
496- expect ( tree [ 0 ] ) . toHaveProperty ( 'id' , joinURL ( TreeRootId . Media , mediaFolderName ) )
545+ expect ( tree [ 0 ] ) . toHaveProperty ( 'id' , mediaFolderName )
497546 expect ( tree [ 0 ] . children ) . toHaveLength ( 2 )
498547
499548 const gitkeepFile = tree [ 0 ] . children ! . find ( item => item . id === gitKeepId )
@@ -566,13 +615,13 @@ describe('findParentFromId', () => {
566615 it ( 'should find direct parent of a child' , ( ) => {
567616 const parent = findParentFromId ( tree , 'docs/1.getting-started/2.introduction.md' )
568617 expect ( parent ) . toBeDefined ( )
569- expect ( parent ?. id ) . toBe ( 'docs/ 1.getting-started' )
618+ expect ( parent ?. id ) . toBe ( '1.getting-started' )
570619 } )
571620
572621 it ( 'should find nested parent' , ( ) => {
573622 const parent = findParentFromId ( tree , 'docs/1.getting-started/1.advanced/1.studio.md' )
574623 expect ( parent ) . toBeDefined ( )
575- expect ( parent ?. id ) . toBe ( 'docs/ 1.getting-started/1.advanced' )
624+ expect ( parent ?. id ) . toBe ( '1.getting-started/1.advanced' )
576625 } )
577626
578627 it ( 'should return null for root level items' , ( ) => {
@@ -649,9 +698,9 @@ describe('findItemFromId', () => {
649698 } )
650699
651700 it ( 'should find directory by id' , ( ) => {
652- const item = findItemFromId ( tree , 'docs/ 1.getting-started' )
701+ const item = findItemFromId ( tree , '1.getting-started' )
653702 expect ( item ) . toBeDefined ( )
654- expect ( item ?. id ) . toBe ( 'docs/ 1.getting-started' )
703+ expect ( item ?. id ) . toBe ( '1.getting-started' )
655704 expect ( item ?. name ) . toBe ( 'getting-started' )
656705 expect ( item ?. type ) . toBe ( 'directory' )
657706 expect ( item ?. children ) . toBeDefined ( )
@@ -666,9 +715,9 @@ describe('findItemFromId', () => {
666715 } )
667716
668717 it ( 'should find nested directory by id' , ( ) => {
669- const item = findItemFromId ( tree , 'docs/ 1.getting-started/1.advanced' )
718+ const item = findItemFromId ( tree , '1.getting-started/1.advanced' )
670719 expect ( item ) . toBeDefined ( )
671- expect ( item ?. id ) . toBe ( 'docs/ 1.getting-started/1.advanced' )
720+ expect ( item ?. id ) . toBe ( '1.getting-started/1.advanced' )
672721 expect ( item ?. name ) . toBe ( 'advanced' )
673722 expect ( item ?. type ) . toBe ( 'directory' )
674723 } )
@@ -707,7 +756,7 @@ describe('findDescendantsFileItemsFromId', () => {
707756 } )
708757
709758 it ( 'returns all descendants files for directory id' , ( ) => {
710- const descendants = findDescendantsFileItemsFromId ( tree , 'docs/ 1.getting-started' )
759+ const descendants = findDescendantsFileItemsFromId ( tree , '1.getting-started' )
711760
712761 expect ( descendants ) . toHaveLength ( 3 )
713762
@@ -717,7 +766,7 @@ describe('findDescendantsFileItemsFromId', () => {
717766 } )
718767
719768 it ( 'returns all descendants files for nested directory id' , ( ) => {
720- const descendants = findDescendantsFileItemsFromId ( tree , 'docs/ 1.getting-started/1.advanced' )
769+ const descendants = findDescendantsFileItemsFromId ( tree , '1.getting-started/1.advanced' )
721770
722771 expect ( descendants ) . toHaveLength ( 1 )
723772
0 commit comments