@@ -11,115 +11,113 @@ import type { HierarchyNodeIdentifiersPath } from "@itwin/presentation-hierarchi
11
11
12
12
describe ( "Utils" , ( ) => {
13
13
describe ( "joinHierarchyFilteringPaths" , ( ) => {
14
- const subject = { id : "0x1" , className : "s" , imodelKey : "key" } ;
15
- const model = { id : "0x2" , className : "m" , imodelKey : "key" } ;
16
- const category = { id : "0x3" , className : "c" , imodelKey : "key" } ;
17
- const category2 = { id : "0x3" , className : "c" , imodelKey : "key" } ;
18
- const element = { id : "0x4" , className : "c" , imodelKey : "key" } ;
19
- const element2 = { id : "0x5" , className : "c" , imodelKey : "key" } ;
20
- const element3 = { id : "0x6" , className : "c" , imodelKey : "key" } ;
21
- const element4 = { id : "0x7" , className : "c" , imodelKey : "key" } ;
14
+ const subject = { id : "0x1" , className : "s" , imodelKey : "key" } ;
15
+ const model = { id : "0x2" , className : "m" , imodelKey : "key" } ;
16
+ const category = { id : "0x3" , className : "c" , imodelKey : "key" } ;
17
+ const category2 = { id : "0x3" , className : "c" , imodelKey : "key" } ;
18
+ const element = { id : "0x4" , className : "c" , imodelKey : "key" } ;
19
+ const element2 = { id : "0x5" , className : "c" , imodelKey : "key" } ;
20
+ const element3 = { id : "0x6" , className : "c" , imodelKey : "key" } ;
21
+ const element4 = { id : "0x7" , className : "c" , imodelKey : "key" } ;
22
22
23
- it ( "returns empty when filter and subset paths dont overlap" , ( ) => {
24
- const subsetPaths : HierarchyNodeIdentifiersPath [ ] = [
25
- [ subject , model ] ,
26
- ]
27
- const filterPaths : HierarchyFilteringPath [ ] = [
28
- [ subject , { ...model , imodelKey : "random" } ] ,
29
- [ subject , { ...model , className : "random" } ] ,
30
- [ subject , { ...model , id : "random" } ] ,
31
- [ subject , category ] ,
32
- [ category , model ] ,
33
- [ model ] ,
34
- [ category ] ,
35
- [ ]
36
- ]
37
- const joinedPaths = joinHierarchyFilteringPaths ( subsetPaths , filterPaths ) ;
38
- expect ( joinedPaths ) . to . deep . eq ( [ ] )
39
- } ) ;
23
+ it ( "returns empty when filter and subset paths dont overlap" , ( ) => {
24
+ const subsetPaths : HierarchyNodeIdentifiersPath [ ] = [ [ subject , model ] ] ;
25
+ const filterPaths : HierarchyFilteringPath [ ] = [
26
+ [ subject , { ...model , imodelKey : "random" } ] ,
27
+ [ subject , { ...model , className : "random" } ] ,
28
+ [ subject , { ...model , id : "random" } ] ,
29
+ [ subject , category ] ,
30
+ [ category , model ] ,
31
+ [ model ] ,
32
+ [ category ] ,
33
+ [ ] ,
34
+ ] ;
35
+ const joinedPaths = joinHierarchyFilteringPaths ( subsetPaths , filterPaths ) ;
36
+ expect ( joinedPaths ) . to . deep . eq ( [ ] ) ;
37
+ } ) ;
40
38
41
- it ( "returns subset paths when filter paths are shorter than subset paths" , ( ) => {
42
- const subsetPaths : HierarchyNodeIdentifiersPath [ ] = [
43
- [ subject , model ] ,
44
- [ model , category , element , element2 ] ,
45
- [ model , category , element , element3 ] ,
46
- [ model , category , element2 , element3 ] ,
47
- [ model , category2 , element4 ] ,
48
- ]
49
- const filterPaths : HierarchyFilteringPath [ ] = [
50
- [ subject ] ,
51
- { path : [ model , category , element ] , options : { autoExpand : true } } ,
52
- { path : [ model , category ] , options : { autoExpand : { depth : 1 } } } ,
53
- { path : [ model , category , element2 ] , options : { autoExpand : { depth : 2 } } } ,
54
- { path : [ model , category2 ] , options : { autoExpand : true } } ,
55
- ]
56
- const joinedPaths = joinHierarchyFilteringPaths ( subsetPaths , filterPaths ) ;
57
- const expectedPaths = [
58
- {
59
- path : [ subject , model ] ,
60
- options : undefined
61
- } ,
62
- {
63
- path : [ model , category , element , element2 ] ,
64
- options : { autoExpand : { depth : 2 } }
65
- } ,
66
- {
39
+ it ( "returns subset paths when filter paths are shorter than subset paths" , ( ) => {
40
+ const subsetPaths : HierarchyNodeIdentifiersPath [ ] = [
41
+ [ subject , model ] ,
42
+ [ model , category , element , element2 ] ,
43
+ [ model , category , element , element3 ] ,
44
+ [ model , category , element2 , element3 ] ,
45
+ [ model , category2 , element4 ] ,
46
+ ] ;
47
+ const filterPaths : HierarchyFilteringPath [ ] = [
48
+ [ subject ] ,
49
+ { path : [ model , category , element ] , options : { autoExpand : true } } ,
50
+ { path : [ model , category ] , options : { autoExpand : { depth : 1 } } } ,
51
+ { path : [ model , category , element2 ] , options : { autoExpand : { depth : 2 } } } ,
52
+ { path : [ model , category2 ] , options : { autoExpand : true } } ,
53
+ ] ;
54
+ const joinedPaths = joinHierarchyFilteringPaths ( subsetPaths , filterPaths ) ;
55
+ const expectedPaths = [
56
+ {
57
+ path : [ subject , model ] ,
58
+ options : undefined ,
59
+ } ,
60
+ {
61
+ path : [ model , category , element , element2 ] ,
62
+ options : { autoExpand : { depth : 2 } } ,
63
+ } ,
64
+ {
67
65
path : [ model , category , element , element3 ] ,
68
- options : { autoExpand : { depth : 2 } }
69
- } ,
70
- {
71
- path : [ model , category , element2 , element3 ] ,
72
- options : { autoExpand : { depth : 2 } }
73
- } ,
74
- {
75
- path : [ model , category2 , element4 ] ,
76
- options : { autoExpand : { depth : 1 } }
77
- }
78
- ]
79
- expect ( joinedPaths ) . to . deep . eq ( expectedPaths )
80
- } ) ;
66
+ options : { autoExpand : { depth : 2 } } ,
67
+ } ,
68
+ {
69
+ path : [ model , category , element2 , element3 ] ,
70
+ options : { autoExpand : { depth : 2 } } ,
71
+ } ,
72
+ {
73
+ path : [ model , category2 , element4 ] ,
74
+ options : { autoExpand : { depth : 1 } } ,
75
+ } ,
76
+ ] ;
77
+ expect ( joinedPaths ) . to . deep . eq ( expectedPaths ) ;
78
+ } ) ;
81
79
82
- it ( "returns subset paths and filter paths when filter paths are longer than subset paths" , ( ) => {
83
- const subsetPaths : HierarchyNodeIdentifiersPath [ ] = [
84
- [ subject , model ] ,
85
- [ model , category , element , element2 ] ,
86
- [ model , category , element , element3 ] ,
87
- ]
88
- const filterPaths : HierarchyFilteringPath [ ] = [
89
- [ subject , model , category ] ,
90
- { path : [ model , category , element , element2 , element3 ] , options : { autoExpand : true } } ,
91
- { path : [ model , category , element , element3 , element ] , options : { autoExpand : { depth : 2 } } } ,
92
- ]
93
- const sortFn = ( lhs : HierarchyFilteringPath , rhs : HierarchyFilteringPath ) => {
94
- const lhsStr = JSON . stringify ( lhs ) ;
95
- const rhsStr = JSON . stringify ( rhs ) ;
96
- if ( rhsStr === lhsStr ) {
97
- return 0 ;
98
- }
99
- if ( lhsStr < rhsStr ) {
100
- return - 1 ;
101
- }
102
- return 1 ;
80
+ it ( "returns subset paths and filter paths when filter paths are longer than subset paths" , ( ) => {
81
+ const subsetPaths : HierarchyNodeIdentifiersPath [ ] = [
82
+ [ subject , model ] ,
83
+ [ model , category , element , element2 ] ,
84
+ [ model , category , element , element3 ] ,
85
+ ] ;
86
+ const filterPaths : HierarchyFilteringPath [ ] = [
87
+ [ subject , model , category ] ,
88
+ { path : [ model , category , element , element2 , element3 ] , options : { autoExpand : true } } ,
89
+ { path : [ model , category , element , element3 , element ] , options : { autoExpand : { depth : 2 } } } ,
90
+ ] ;
91
+ const sortFn = ( lhs : HierarchyFilteringPath , rhs : HierarchyFilteringPath ) => {
92
+ const lhsStr = JSON . stringify ( lhs ) ;
93
+ const rhsStr = JSON . stringify ( rhs ) ;
94
+ if ( rhsStr === lhsStr ) {
95
+ return 0 ;
96
+ }
97
+ if ( lhsStr < rhsStr ) {
98
+ return - 1 ;
103
99
}
104
- const joinedPaths = joinHierarchyFilteringPaths ( subsetPaths , filterPaths ) . sort ( sortFn ) ;
105
- const expectedPaths = [
106
- {
107
- path : subsetPaths [ 0 ] ,
108
- options : undefined
109
- } ,
110
- {
111
- path : subsetPaths [ 1 ] ,
112
- options : undefined
113
- } ,
114
- {
115
- path : subsetPaths [ 2 ] ,
116
- options : undefined
117
- } ,
118
- { path : HierarchyFilteringPath . normalize ( filterPaths [ 0 ] ) . path } ,
119
- filterPaths [ 1 ] ,
120
- filterPaths [ 2 ]
121
- ] . sort ( sortFn ) ;
122
- expect ( joinedPaths ) . to . deep . eq ( expectedPaths ) ;
123
- } ) ;
100
+ return 1 ;
101
+ } ;
102
+ const joinedPaths = joinHierarchyFilteringPaths ( subsetPaths , filterPaths ) . sort ( sortFn ) ;
103
+ const expectedPaths = [
104
+ {
105
+ path : subsetPaths [ 0 ] ,
106
+ options : undefined ,
107
+ } ,
108
+ {
109
+ path : subsetPaths [ 1 ] ,
110
+ options : undefined ,
111
+ } ,
112
+ {
113
+ path : subsetPaths [ 2 ] ,
114
+ options : undefined ,
115
+ } ,
116
+ { path : HierarchyFilteringPath . normalize ( filterPaths [ 0 ] ) . path } ,
117
+ filterPaths [ 1 ] ,
118
+ filterPaths [ 2 ] ,
119
+ ] . sort ( sortFn ) ;
120
+ expect ( joinedPaths ) . to . deep . eq ( expectedPaths ) ;
124
121
} ) ;
122
+ } ) ;
125
123
} ) ;
0 commit comments