@@ -5,6 +5,7 @@ import { FileTrieNode } from "./fileTrie"
5
5
interface TestData {
6
6
title : string
7
7
slug : string
8
+ filePath : string
8
9
}
9
10
10
11
describe ( "FileTrie" , ( ) => {
@@ -26,6 +27,7 @@ describe("FileTrie", () => {
26
27
const data = {
27
28
title : "Test Title" ,
28
29
slug : "test" ,
30
+ filePath : "test.md" ,
29
31
}
30
32
31
33
trie . add ( data )
@@ -36,6 +38,7 @@ describe("FileTrie", () => {
36
38
const data = {
37
39
title : "Test Title" ,
38
40
slug : "test" ,
41
+ filePath : "test.md" ,
39
42
}
40
43
41
44
trie . add ( data )
@@ -49,6 +52,7 @@ describe("FileTrie", () => {
49
52
const data = {
50
53
title : "Test" ,
51
54
slug : "test" ,
55
+ filePath : "test.md" ,
52
56
}
53
57
54
58
trie . add ( data )
@@ -61,6 +65,7 @@ describe("FileTrie", () => {
61
65
const data = {
62
66
title : "Index" ,
63
67
slug : "index" ,
68
+ filePath : "index.md" ,
64
69
}
65
70
66
71
trie . add ( data )
@@ -72,11 +77,13 @@ describe("FileTrie", () => {
72
77
const data1 = {
73
78
title : "Nested" ,
74
79
slug : "folder/test" ,
80
+ filePath : "folder/test.md" ,
75
81
}
76
82
77
83
const data2 = {
78
84
title : "Really nested index" ,
79
85
slug : "a/b/c/index" ,
86
+ filePath : "a/b/c/index.md" ,
80
87
}
81
88
82
89
trie . add ( data1 )
@@ -103,8 +110,8 @@ describe("FileTrie", () => {
103
110
104
111
describe ( "filter" , ( ) => {
105
112
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" }
108
115
109
116
trie . add ( data1 )
110
117
trie . add ( data2 )
@@ -117,8 +124,8 @@ describe("FileTrie", () => {
117
124
118
125
describe ( "map" , ( ) => {
119
126
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" }
122
129
123
130
trie . add ( data1 )
124
131
trie . add ( data2 )
@@ -134,8 +141,12 @@ describe("FileTrie", () => {
134
141
} )
135
142
136
143
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
+ }
139
150
140
151
trie . add ( data1 )
141
152
trie . add ( data2 )
@@ -150,15 +161,19 @@ describe("FileTrie", () => {
150
161
151
162
assert . strictEqual ( trie . children [ 0 ] . displayName , "File: Test1" )
152
163
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 " )
154
165
assert . strictEqual ( trie . children [ 1 ] . children [ 0 ] . children [ 0 ] . displayName , "File: Test2" )
155
166
} )
156
167
} )
157
168
158
169
describe ( "entries" , ( ) => {
159
170
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
+ }
162
177
163
178
trie . add ( data1 )
164
179
trie . add ( data2 )
@@ -170,8 +185,8 @@ describe("FileTrie", () => {
170
185
[ "index" , trie . data ] ,
171
186
[ "test1" , data1 ] ,
172
187
[ "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 ] ,
175
190
] ,
176
191
)
177
192
} )
@@ -182,14 +197,17 @@ describe("FileTrie", () => {
182
197
const data1 = {
183
198
title : "Root" ,
184
199
slug : "index" ,
200
+ filePath : "index.md" ,
185
201
}
186
202
const data2 = {
187
203
title : "Test" ,
188
204
slug : "folder/subfolder/test" ,
205
+ filePath : "folder/subfolder/test.md" ,
189
206
}
190
207
const data3 = {
191
208
title : "Folder Index" ,
192
209
slug : "abc/index" ,
210
+ filePath : "abc/index.md" ,
193
211
}
194
212
195
213
trie . add ( data1 )
@@ -208,9 +226,9 @@ describe("FileTrie", () => {
208
226
209
227
describe ( "sort" , ( ) => {
210
228
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" }
214
232
215
233
trie . add ( data3 )
216
234
trie . add ( data1 )
0 commit comments