@@ -21,6 +21,7 @@ class FooComponent { }
2121 <cds-sidenav-menu title="Example Title"></cds-sidenav-menu>
2222 <cds-sidenav-item
2323 [route]="route"
24+ [useRouter]="useRouter"
2425 (navigation)="onNavigation($event)">
2526 </cds-sidenav-item>
2627 </cds-sidenav>
@@ -31,6 +32,7 @@ class SideNavTest {
3132 hidden = false ;
3233 allowExpansion = false ;
3334 statusPromise = null ;
35+ useRouter = false ;
3436 onNavigation ( event ) {
3537 this . statusPromise = event ;
3638 }
@@ -70,54 +72,119 @@ describe("SideNav", () => {
7072 expect ( fixture . componentInstance instanceof SideNav ) . toBe ( true ) ;
7173 } ) ;
7274
73- it ( "should emit the navigation status promise when the link is activated and call onNavigation" , async ( ) => {
74- fixture = TestBed . createComponent ( SideNavTest ) ;
75- wrapper = fixture . componentInstance ;
76- spyOn ( wrapper , "onNavigation" ) . and . callThrough ( ) ;
77- fixture . detectChanges ( ) ;
78- element = fixture . debugElement . query ( By . css ( ".cds--side-nav__link" ) ) ;
79- element . nativeElement . click ( ) ;
80- fixture . detectChanges ( ) ;
81- expect ( wrapper . onNavigation ) . toHaveBeenCalled ( ) ;
82- const status = await wrapper . statusPromise ;
83- expect ( status ) . toBe ( true ) ;
84- } ) ;
75+ describe ( "when useRouter is false" , ( ) => {
76+ let fixture ;
8577
86- it ( "should expand sidenav-menu on click" , ( ) => {
87- fixture = TestBed . createComponent ( SideNavTest ) ;
88- wrapper = fixture . componentInstance ;
89- fixture . detectChanges ( ) ;
90- element = fixture . debugElement . query ( By . css ( ".cds--side-nav__submenu" ) ) ;
91- element . nativeElement . click ( ) ;
92- fixture . detectChanges ( ) ;
93- expect ( element . nativeElement . getAttribute ( "aria-expanded" ) ) . toBe ( "true" ) ;
94- expect ( element . componentInstance . expanded ) . toBe ( true ) ;
95- element . nativeElement . click ( ) ;
96- fixture . detectChanges ( ) ;
97- expect ( element . nativeElement . getAttribute ( "aria-expanded" ) ) . toBe ( "false" ) ;
98- expect ( element . componentInstance . expanded ) . toBe ( false ) ;
99- } ) ;
78+ beforeEach ( ( ) => {
79+ fixture = TestBed . createComponent ( SideNavTest ) ;
80+ fixture . componentInstance . useRouter = false ;
81+ fixture . detectChanges ( ) ;
82+ } ) ;
83+
84+ it ( "should emit the navigation status promise when the link is activated and call onNavigation" , async ( ) => {
85+ wrapper = fixture . componentInstance ;
86+ spyOn ( wrapper , "onNavigation" ) . and . callThrough ( ) ;
87+ fixture . detectChanges ( ) ;
88+ element = fixture . debugElement . query ( By . css ( ".cds--side-nav__link" ) ) ;
89+ element . nativeElement . click ( ) ;
90+ fixture . detectChanges ( ) ;
91+ expect ( wrapper . onNavigation ) . toHaveBeenCalled ( ) ;
92+ const status = await wrapper . statusPromise ;
93+ expect ( status ) . toBe ( true ) ;
94+ } ) ;
10095
101- it ( "should set the sidenav-menu title to Example Title" , ( ) => {
102- fixture = TestBed . createComponent ( SideNavTest ) ;
103- fixture . detectChanges ( ) ;
104- element = fixture . debugElement . query ( By . css ( "cds-sidenav-menu" ) ) ;
105- expect ( element . nativeElement . textContent ) . toEqual ( "Example Title" ) ;
96+ it ( "should expand sidenav-menu on click" , ( ) => {
97+ wrapper = fixture . componentInstance ;
98+ fixture . detectChanges ( ) ;
99+ element = fixture . debugElement . query ( By . css ( ".cds--side-nav__submenu" ) ) ;
100+ element . nativeElement . click ( ) ;
101+ fixture . detectChanges ( ) ;
102+ expect ( element . nativeElement . getAttribute ( "aria-expanded" ) ) . toBe ( "true" ) ;
103+ expect ( element . componentInstance . expanded ) . toBe ( true ) ;
104+ element . nativeElement . click ( ) ;
105+ fixture . detectChanges ( ) ;
106+ expect ( element . nativeElement . getAttribute ( "aria-expanded" ) ) . toBe ( "false" ) ;
107+ expect ( element . componentInstance . expanded ) . toBe ( false ) ;
108+ } ) ;
109+
110+ it ( "should set the sidenav-menu title to Example Title" , ( ) => {
111+ fixture . detectChanges ( ) ;
112+ element = fixture . debugElement . query ( By . css ( "cds-sidenav-menu" ) ) ;
113+ expect ( element . nativeElement . textContent ) . toEqual ( "Example Title" ) ;
114+ } ) ;
115+
116+ it ( "should toggle expanded on click" , ( ) => {
117+ wrapper = fixture . componentInstance ;
118+ wrapper . allowExpansion = true ;
119+ fixture . detectChanges ( ) ;
120+ element = fixture . debugElement . query ( By . css ( "cds-sidenav" ) ) ;
121+ let sidenavButton = element . nativeElement . querySelector (
122+ ".cds--side-nav__toggle" ,
123+ ) ;
124+ element . componentInstance . expanded = false ;
125+ sidenavButton . click ( ) ;
126+ fixture . detectChanges ( ) ;
127+ expect ( element . componentInstance . expanded ) . toBe ( true ) ;
128+ sidenavButton . click ( ) ;
129+ fixture . detectChanges ( ) ;
130+ expect ( element . componentInstance . expanded ) . toBe ( false ) ;
131+ } ) ;
106132 } ) ;
107133
108- it ( "should toggle expanded on click" , ( ) => {
109- fixture = TestBed . createComponent ( SideNavTest ) ;
110- wrapper = fixture . componentInstance ;
111- wrapper . allowExpansion = true ;
112- fixture . detectChanges ( ) ;
113- element = fixture . debugElement . query ( By . css ( "cds-sidenav" ) ) ;
114- let sidenavButton = element . nativeElement . querySelector ( ".cds--side-nav__toggle" ) ;
115- element . componentInstance . expanded = false ;
116- sidenavButton . click ( ) ;
117- fixture . detectChanges ( ) ;
118- expect ( element . componentInstance . expanded ) . toBe ( true ) ;
119- sidenavButton . click ( ) ;
120- fixture . detectChanges ( ) ;
121- expect ( element . componentInstance . expanded ) . toBe ( false ) ;
134+ describe ( "when useRouter is true" , ( ) => {
135+ let fixture ;
136+
137+ beforeEach ( ( ) => {
138+ fixture = TestBed . createComponent ( SideNavTest ) ;
139+ fixture . componentInstance . useRouter = true ;
140+ fixture . detectChanges ( ) ;
141+ } ) ;
142+
143+ it ( "should not emit the navigation status promise when the link is activated and call onNavigation" , async ( ) => {
144+ wrapper = fixture . componentInstance ;
145+ spyOn ( wrapper , "onNavigation" ) . and . callThrough ( ) ;
146+ fixture . detectChanges ( ) ;
147+ element = fixture . debugElement . query ( By . css ( ".cds--side-nav__link" ) ) ;
148+ element . nativeElement . click ( ) ;
149+ fixture . detectChanges ( ) ;
150+ expect ( wrapper . onNavigation ) . not . toHaveBeenCalled ( ) ;
151+ } ) ;
152+
153+ it ( "should expand sidenav-menu on click" , ( ) => {
154+ wrapper = fixture . componentInstance ;
155+ fixture . detectChanges ( ) ;
156+ element = fixture . debugElement . query ( By . css ( ".cds--side-nav__submenu" ) ) ;
157+ element . nativeElement . click ( ) ;
158+ fixture . detectChanges ( ) ;
159+ expect ( element . nativeElement . getAttribute ( "aria-expanded" ) ) . toBe ( "true" ) ;
160+ expect ( element . componentInstance . expanded ) . toBe ( true ) ;
161+ element . nativeElement . click ( ) ;
162+ fixture . detectChanges ( ) ;
163+ expect ( element . nativeElement . getAttribute ( "aria-expanded" ) ) . toBe ( "false" ) ;
164+ expect ( element . componentInstance . expanded ) . toBe ( false ) ;
165+ } ) ;
166+
167+ it ( "should set the sidenav-menu title to Example Title" , ( ) => {
168+ fixture . detectChanges ( ) ;
169+ element = fixture . debugElement . query ( By . css ( "cds-sidenav-menu" ) ) ;
170+ expect ( element . nativeElement . textContent ) . toEqual ( "Example Title" ) ;
171+ } ) ;
172+
173+ it ( "should toggle expanded on click" , ( ) => {
174+ wrapper = fixture . componentInstance ;
175+ wrapper . allowExpansion = true ;
176+ fixture . detectChanges ( ) ;
177+ element = fixture . debugElement . query ( By . css ( "cds-sidenav" ) ) ;
178+ let sidenavButton = element . nativeElement . querySelector (
179+ ".cds--side-nav__toggle" ,
180+ ) ;
181+ element . componentInstance . expanded = false ;
182+ sidenavButton . click ( ) ;
183+ fixture . detectChanges ( ) ;
184+ expect ( element . componentInstance . expanded ) . toBe ( true ) ;
185+ sidenavButton . click ( ) ;
186+ fixture . detectChanges ( ) ;
187+ expect ( element . componentInstance . expanded ) . toBe ( false ) ;
188+ } ) ;
122189 } ) ;
123190} ) ;
0 commit comments