@@ -5,6 +5,7 @@ import { FileTrieNode } from "./fileTrie"
55interface TestData {
66 title : string
77 slug : string
8+ filePath : string
89}
910
1011describe ( "FileTrie" , ( ) => {
@@ -26,6 +27,7 @@ describe("FileTrie", () => {
2627 const data = {
2728 title : "Test Title" ,
2829 slug : "test" ,
30+ filePath : "test.md" ,
2931 }
3032
3133 trie . add ( data )
@@ -36,6 +38,7 @@ describe("FileTrie", () => {
3638 const data = {
3739 title : "Test Title" ,
3840 slug : "test" ,
41+ filePath : "test.md" ,
3942 }
4043
4144 trie . add ( data )
@@ -49,6 +52,7 @@ describe("FileTrie", () => {
4952 const data = {
5053 title : "Test" ,
5154 slug : "test" ,
55+ filePath : "test.md" ,
5256 }
5357
5458 trie . add ( data )
@@ -61,6 +65,7 @@ describe("FileTrie", () => {
6165 const data = {
6266 title : "Index" ,
6367 slug : "index" ,
68+ filePath : "index.md" ,
6469 }
6570
6671 trie . add ( data )
@@ -72,11 +77,13 @@ describe("FileTrie", () => {
7277 const data1 = {
7378 title : "Nested" ,
7479 slug : "folder/test" ,
80+ filePath : "folder/test.md" ,
7581 }
7682
7783 const data2 = {
7884 title : "Really nested index" ,
7985 slug : "a/b/c/index" ,
86+ filePath : "a/b/c/index.md" ,
8087 }
8188
8289 trie . add ( data1 )
@@ -103,8 +110,8 @@ describe("FileTrie", () => {
103110
104111 describe ( "filter" , ( ) => {
105112 test ( "should filter nodes based on condition" , ( ) => {
106- const data1 = { title : "Test1" , slug : "test1" }
107- const data2 = { title : "Test2" , slug : "test2" }
113+ const data1 = { title : "Test1" , slug : "test1" , filePath : "test1.md" }
114+ const data2 = { title : "Test2" , slug : "test2" , filePath : "test2.md" }
108115
109116 trie . add ( data1 )
110117 trie . add ( data2 )
@@ -117,8 +124,8 @@ describe("FileTrie", () => {
117124
118125 describe ( "map" , ( ) => {
119126 test ( "should apply function to all nodes" , ( ) => {
120- const data1 = { title : "Test1" , slug : "test1" }
121- const data2 = { title : "Test2" , slug : "test2" }
127+ const data1 = { title : "Test1" , slug : "test1" , filePath : "test1.md" }
128+ const data2 = { title : "Test2" , slug : "test2" , filePath : "test2.md" }
122129
123130 trie . add ( data1 )
124131 trie . add ( data2 )
@@ -134,8 +141,12 @@ describe("FileTrie", () => {
134141 } )
135142
136143 test ( "map over folders should work" , ( ) => {
137- const data1 = { title : "Test1" , slug : "test1" }
138- const data2 = { title : "Test2" , slug : "a/b/test2" }
144+ const data1 = { title : "Test1" , slug : "test1" , filePath : "test1.md" }
145+ const data2 = {
146+ title : "Test2" ,
147+ slug : "a/b-with-space/test2" ,
148+ filePath : "a/b with space/test2.md" ,
149+ }
139150
140151 trie . add ( data1 )
141152 trie . add ( data2 )
@@ -150,15 +161,19 @@ describe("FileTrie", () => {
150161
151162 assert . strictEqual ( trie . children [ 0 ] . displayName , "File: Test1" )
152163 assert . strictEqual ( trie . children [ 1 ] . displayName , "Folder: a" )
153- assert . strictEqual ( trie . children [ 1 ] . children [ 0 ] . displayName , "Folder: b" )
164+ assert . strictEqual ( trie . children [ 1 ] . children [ 0 ] . displayName , "Folder: b with space " )
154165 assert . strictEqual ( trie . children [ 1 ] . children [ 0 ] . children [ 0 ] . displayName , "File: Test2" )
155166 } )
156167 } )
157168
158169 describe ( "entries" , ( ) => {
159170 test ( "should return all entries" , ( ) => {
160- const data1 = { title : "Test1" , slug : "test1" }
161- const data2 = { title : "Test2" , slug : "a/b/test2" }
171+ const data1 = { title : "Test1" , slug : "test1" , filePath : "test1.md" }
172+ const data2 = {
173+ title : "Test2" ,
174+ slug : "a/b-with-space/test2" ,
175+ filePath : "a/b with space/test2.md" ,
176+ }
162177
163178 trie . add ( data1 )
164179 trie . add ( data2 )
@@ -170,8 +185,8 @@ describe("FileTrie", () => {
170185 [ "index" , trie . data ] ,
171186 [ "test1" , data1 ] ,
172187 [ "a/index" , null ] ,
173- [ "a/b/index" , null ] ,
174- [ "a/b/test2" , data2 ] ,
188+ [ "a/b-with-space /index" , null ] ,
189+ [ "a/b-with-space /test2" , data2 ] ,
175190 ] ,
176191 )
177192 } )
@@ -182,14 +197,17 @@ describe("FileTrie", () => {
182197 const data1 = {
183198 title : "Root" ,
184199 slug : "index" ,
200+ filePath : "index.md" ,
185201 }
186202 const data2 = {
187203 title : "Test" ,
188204 slug : "folder/subfolder/test" ,
205+ filePath : "folder/subfolder/test.md" ,
189206 }
190207 const data3 = {
191208 title : "Folder Index" ,
192209 slug : "abc/index" ,
210+ filePath : "abc/index.md" ,
193211 }
194212
195213 trie . add ( data1 )
@@ -208,9 +226,9 @@ describe("FileTrie", () => {
208226
209227 describe ( "sort" , ( ) => {
210228 test ( "should sort nodes according to sort function" , ( ) => {
211- const data1 = { title : "A" , slug : "a" }
212- const data2 = { title : "B" , slug : "b" }
213- const data3 = { title : "C" , slug : "c" }
229+ const data1 = { title : "A" , slug : "a" , filePath : "a.md" }
230+ const data2 = { title : "B" , slug : "b" , filePath : "b.md" }
231+ const data3 = { title : "C" , slug : "c" , filePath : "c.md" }
214232
215233 trie . add ( data3 )
216234 trie . add ( data1 )
0 commit comments