File tree Expand file tree Collapse file tree 2 files changed +71
-1
lines changed Expand file tree Collapse file tree 2 files changed +71
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { findDirectoryNode } from '../findDirectoryNode' ;
2
+
3
+ jest . mock (
4
+ '@/directory/directory.json' ,
5
+ ( ) => {
6
+ const mockDirectory = {
7
+ route : '/' ,
8
+ children : [
9
+ {
10
+ route : '/route1/route2' ,
11
+ children : [
12
+ {
13
+ route : '/route1/route2/child1' ,
14
+ children : [
15
+ {
16
+ route : '/route1/route2/child1/child1'
17
+ } ,
18
+ {
19
+ route : '/route1/route2/child1/child2'
20
+ } ,
21
+ {
22
+ route : '/route1/route2/child1/child3'
23
+ }
24
+ ]
25
+ } ,
26
+ {
27
+ route : '/route1/route2/child2'
28
+ } ,
29
+ {
30
+ route : '/route1/route2/child3'
31
+ }
32
+ ]
33
+ }
34
+ ]
35
+ } ;
36
+
37
+ return mockDirectory ;
38
+ } ,
39
+ { virtual : true }
40
+ ) ;
41
+
42
+ describe ( 'findDirectoryNode' , ( ) => {
43
+ it ( 'should return directory page node if it exists' , ( ) => {
44
+ const result = findDirectoryNode ( '/route1/route2/child1' ) ;
45
+
46
+ expect ( result ) . toEqual ( {
47
+ route : '/route1/route2/child1' ,
48
+ children : [
49
+ {
50
+ route : '/route1/route2/child1/child1'
51
+ } ,
52
+ {
53
+ route : '/route1/route2/child1/child2'
54
+ } ,
55
+ {
56
+ route : '/route1/route2/child1/child3'
57
+ }
58
+ ]
59
+ } ) ;
60
+ } ) ;
61
+
62
+ it ( 'should return undefined if page not is not found' , ( ) => {
63
+ const result = findDirectoryNode ( '/route1/route2/child4' ) ;
64
+
65
+ expect ( result ) . toEqual ( undefined ) ;
66
+ } ) ;
67
+ } ) ;
Original file line number Diff line number Diff line change 1
1
import directory from '@/directory/directory.json' ;
2
+ import { PageNode } from '@/directory/directory' ;
2
3
3
- export const findDirectoryNode = ( route , dir = directory ) => {
4
+ const directoryCast = directory as PageNode ;
5
+
6
+ export const findDirectoryNode = ( route : string , dir = directoryCast ) => {
4
7
if ( dir . route === route ) {
5
8
return dir ;
6
9
} else if ( dir . children && dir . children . length ) {
You can’t perform that action at this time.
0 commit comments