@@ -65,6 +65,118 @@ describe('component: Group', () => {
6565 expect ( ( wrapper . vm as any ) . hasActiveRoute ( ) ) . toBe ( true ) ;
6666 } ) ;
6767
68+ it ( 'hasActiveRoute stays true on a route for a resource a child claims via navResources' , ( ) => {
69+ const group = {
70+ name : 'cluster' ,
71+ children : [
72+ {
73+ name : 'projects-namespaces' ,
74+ route : { name : 'c-cluster-product-projectsnamespaces' , params : { cluster : 'local' , product : 'explorer' } } ,
75+ navResources : [ 'management.cattle.io.project' ]
76+ }
77+ ]
78+ } ;
79+
80+ const wrapper = shallowMount ( Group as any , {
81+ props : {
82+ group, canCollapse : true , idPrefix : ''
83+ } ,
84+ global : {
85+ mocks : {
86+ // Creating a project uses the generic resource create route, which no nav item links to
87+ $route : {
88+ params : {
89+ cluster : 'local' , product : 'explorer' , resource : 'management.cattle.io.project'
90+ } ,
91+ path : '/c/local/explorer/management.cattle.io.project/create' ,
92+ fullPath : '/c/local/explorer/management.cattle.io.project/create' ,
93+ matched : [ ]
94+ } ,
95+ $router : {
96+ resolve : jest . fn ( ) . mockReturnValue ( { path : '/c/local/explorer/projectsnamespaces' } ) ,
97+ getRoutes : jest . fn ( ) . mockReturnValue ( [ ] )
98+ } ,
99+ t : ( key : string ) => key
100+ }
101+ }
102+ } ) ;
103+
104+ expect ( ( wrapper . vm as any ) . hasActiveRoute ( ) ) . toBe ( true ) ;
105+ } ) ;
106+
107+ it ( 'hasActiveRoute is false on a route for a resource no child claims' , ( ) => {
108+ const group = {
109+ name : 'cluster' ,
110+ children : [
111+ {
112+ name : 'projects-namespaces' ,
113+ route : { name : 'c-cluster-product-projectsnamespaces' , params : { cluster : 'local' , product : 'explorer' } } ,
114+ navResources : [ 'management.cattle.io.project' ]
115+ }
116+ ]
117+ } ;
118+
119+ const wrapper = shallowMount ( Group as any , {
120+ props : {
121+ group, canCollapse : true , idPrefix : ''
122+ } ,
123+ global : {
124+ mocks : {
125+ $route : {
126+ params : {
127+ cluster : 'local' , product : 'explorer' , resource : 'apps.deployment'
128+ } ,
129+ path : '/c/local/explorer/apps.deployment/create' ,
130+ fullPath : '/c/local/explorer/apps.deployment/create' ,
131+ matched : [ ]
132+ } ,
133+ $router : {
134+ resolve : jest . fn ( ) . mockReturnValue ( { path : '/c/local/explorer/projectsnamespaces' } ) ,
135+ getRoutes : jest . fn ( ) . mockReturnValue ( [ ] )
136+ } ,
137+ t : ( key : string ) => key
138+ }
139+ }
140+ } ) ;
141+
142+ expect ( ( wrapper . vm as any ) . hasActiveRoute ( ) ) . toBe ( false ) ;
143+ } ) ;
144+
145+ it ( 'hasActiveRoute stays true on a page nested under a child route' , ( ) => {
146+ // The Providers group in Cluster Management. There is no current cluster under /c/_, so nav items
147+ // resolve without a cluster param and the nav level check can't match on its own
148+ const group = {
149+ name : 'providers' ,
150+ children : [
151+ { name : 'rke-kontainer-providers' , route : { name : 'c-cluster-manager-driver-kontainerdriver' , params : { } } } ,
152+ { name : 'rke-node-providers' , route : { name : 'c-cluster-manager-driver-nodedriver' , params : { } } }
153+ ]
154+ } ;
155+
156+ const mountOnPath = ( path : string ) => shallowMount ( Group as any , {
157+ props : {
158+ group, canCollapse : true , idPrefix : ''
159+ } ,
160+ global : {
161+ mocks : {
162+ $route : {
163+ params : { cluster : '_' } , path, matched : [ ]
164+ } ,
165+ $router : {
166+ resolve : jest . fn ( ( route : any ) => ( { path : route . name === 'c-cluster-manager-driver-kontainerdriver' ? '/c/_/manager/kontainerDriver' : '/c/_/manager/nodeDriver' } ) ) ,
167+ getRoutes : jest . fn ( ) . mockReturnValue ( [ ] )
168+ } ,
169+ t : ( key : string ) => key
170+ }
171+ }
172+ } ) ;
173+
174+ expect ( ( mountOnPath ( '/c/_/manager/kontainerDriver' ) . vm as any ) . hasActiveRoute ( ) ) . toBe ( true ) ;
175+ // Clicking Create must not collapse the group out from under the highlighted child
176+ expect ( ( mountOnPath ( '/c/_/manager/kontainerDriver/create' ) . vm as any ) . hasActiveRoute ( ) ) . toBe ( true ) ;
177+ expect ( ( mountOnPath ( '/c/_/manager/hostedprovider' ) . vm as any ) . hasActiveRoute ( ) ) . toBe ( false ) ;
178+ } ) ;
179+
68180 describe ( 'group header label' , ( ) => {
69181 const mountGroup = ( group : any ) => shallowMount ( Group as any , {
70182 props : {
0 commit comments