@@ -12,11 +12,15 @@ import { BottomNavRoutingViewComponentsModule,
12
12
BottomNavRoutingView3Component } from './routing-view-components.spec' ;
13
13
import { Router } from '@angular/router' ;
14
14
import { Location } from '@angular/common' ;
15
+ import { UIInteractions } from '../test-utils/ui-interactions.spec' ;
15
16
16
17
describe ( 'TabBar' , ( ) => {
17
18
configureTestSuite ( ) ;
18
- beforeEach ( async ( ( ) => {
19
19
20
+ const tabItemNormalCssClass = 'igx-bottom-nav__menu-item' ;
21
+ const tabItemSelectedCssClass = 'igx-bottom-nav__menu-item--selected' ;
22
+
23
+ beforeEach ( async ( ( ) => {
20
24
const testRoutes = [
21
25
{ path : 'view1' , component : BottomNavRoutingView1Component } ,
22
26
{ path : 'view2' , component : BottomNavRoutingView2Component } ,
@@ -162,8 +166,6 @@ describe('TabBar', () => {
162
166
} ) ;
163
167
164
168
describe ( 'Routing Navigation Tests' , ( ) => {
165
- configureTestSuite ( ) ;
166
-
167
169
let router ;
168
170
let location ;
169
171
let fixture ;
@@ -184,15 +186,15 @@ describe('TabBar', () => {
184
186
tick ( ) ;
185
187
expect ( location . path ( ) ) . toBe ( '/' ) ;
186
188
187
- fixture . ngZone . run ( ( ) => { theTabs [ 2 ] . elementRef ( ) . nativeElement . dispatchEvent ( new Event ( 'click' ) ) ; } ) ;
189
+ fixture . ngZone . run ( ( ) => { UIInteractions . clickElement ( theTabs [ 2 ] . elementRef ( ) ) ; } ) ;
188
190
tick ( ) ;
189
191
expect ( location . path ( ) ) . toBe ( '/view3' ) ;
190
192
191
- fixture . ngZone . run ( ( ) => { theTabs [ 1 ] . elementRef ( ) . nativeElement . dispatchEvent ( new Event ( 'click' ) ) ; } ) ;
193
+ fixture . ngZone . run ( ( ) => { UIInteractions . clickElement ( theTabs [ 1 ] . elementRef ( ) ) ; } ) ;
192
194
tick ( ) ;
193
195
expect ( location . path ( ) ) . toBe ( '/view2' ) ;
194
196
195
- fixture . ngZone . run ( ( ) => { theTabs [ 0 ] . elementRef ( ) . nativeElement . dispatchEvent ( new Event ( 'click' ) ) ; } ) ;
197
+ fixture . ngZone . run ( ( ) => { UIInteractions . clickElement ( theTabs [ 0 ] . elementRef ( ) ) ; } ) ;
196
198
tick ( ) ;
197
199
expect ( location . path ( ) ) . toBe ( '/view1' ) ;
198
200
} ) ) ;
@@ -208,27 +210,31 @@ describe('TabBar', () => {
208
210
fixture . detectChanges ( ) ;
209
211
expect ( bottomNav . selectedIndex ) . toBe ( 2 ) ;
210
212
expect ( theTabs [ 2 ] . isSelected ) . toBe ( true ) ;
213
+ expect ( theTabs [ 0 ] . isSelected ) . toBe ( false ) ;
214
+ expect ( theTabs [ 1 ] . isSelected ) . toBe ( false ) ;
211
215
212
216
fixture . ngZone . run ( ( ) => { router . navigate ( [ '/view2' ] ) ; } ) ;
213
217
tick ( ) ;
214
218
expect ( location . path ( ) ) . toBe ( '/view2' ) ;
215
219
fixture . detectChanges ( ) ;
216
220
expect ( bottomNav . selectedIndex ) . toBe ( 1 ) ;
217
221
expect ( theTabs [ 1 ] . isSelected ) . toBe ( true ) ;
222
+ expect ( theTabs [ 0 ] . isSelected ) . toBe ( false ) ;
223
+ expect ( theTabs [ 2 ] . isSelected ) . toBe ( false ) ;
218
224
219
225
fixture . ngZone . run ( ( ) => { router . navigate ( [ '/view1' ] ) ; } ) ;
220
226
tick ( ) ;
221
227
expect ( location . path ( ) ) . toBe ( '/view1' ) ;
222
228
fixture . detectChanges ( ) ;
223
229
expect ( bottomNav . selectedIndex ) . toBe ( 0 ) ;
224
230
expect ( theTabs [ 0 ] . isSelected ) . toBe ( true ) ;
231
+ expect ( theTabs [ 1 ] . isSelected ) . toBe ( false ) ;
232
+ expect ( theTabs [ 2 ] . isSelected ) . toBe ( false ) ;
225
233
} ) ) ;
226
234
227
235
} ) ;
228
236
229
237
describe ( 'Tabs-only Mode Tests' , ( ) => {
230
- configureTestSuite ( ) ;
231
-
232
238
let fixture ;
233
239
let bottomNav ;
234
240
let theTabs ;
@@ -242,42 +248,42 @@ describe('TabBar', () => {
242
248
243
249
it ( 'should retain the correct initial selection status' , ( ) => {
244
250
expect ( theTabs [ 0 ] . isSelected ) . toBe ( false ) ;
245
- expect ( theTabs [ 0 ] . elementRef ( ) . nativeElement . classList . contains ( 'igx-bottom-nav__menu-item' ) ) . toBe ( true ) ;
251
+ expect ( theTabs [ 0 ] . elementRef ( ) . nativeElement . classList . contains ( tabItemNormalCssClass ) ) . toBe ( true ) ;
246
252
247
253
expect ( theTabs [ 1 ] . isSelected ) . toBe ( true ) ;
248
- expect ( theTabs [ 1 ] . elementRef ( ) . nativeElement . classList . contains ( 'igx-bottom-nav__menu-item--selected' ) ) . toBe ( true ) ;
254
+ expect ( theTabs [ 1 ] . elementRef ( ) . nativeElement . classList . contains ( tabItemSelectedCssClass ) ) . toBe ( true ) ;
249
255
250
256
expect ( theTabs [ 2 ] . isSelected ) . toBe ( false ) ;
251
- expect ( theTabs [ 2 ] . elementRef ( ) . nativeElement . classList . contains ( 'igx-bottom-nav__menu-item' ) ) . toBe ( true ) ;
257
+ expect ( theTabs [ 2 ] . elementRef ( ) . nativeElement . classList . contains ( tabItemNormalCssClass ) ) . toBe ( true ) ;
252
258
} ) ;
253
259
254
260
it ( 'should have the correct selection set even when no active link is present on the tabs' , ( ) => {
255
261
expect ( theTabs [ 0 ] . isSelected ) . toBe ( false ) ;
256
- expect ( theTabs [ 0 ] . elementRef ( ) . nativeElement . classList . contains ( 'igx-bottom-nav__menu-item' ) ) . toBe ( true ) ;
262
+ expect ( theTabs [ 0 ] . elementRef ( ) . nativeElement . classList . contains ( tabItemNormalCssClass ) ) . toBe ( true ) ;
257
263
expect ( theTabs [ 1 ] . isSelected ) . toBe ( true ) ;
258
- expect ( theTabs [ 1 ] . elementRef ( ) . nativeElement . classList . contains ( 'igx-bottom-nav__menu-item--selected' ) ) . toBe ( true ) ;
264
+ expect ( theTabs [ 1 ] . elementRef ( ) . nativeElement . classList . contains ( tabItemSelectedCssClass ) ) . toBe ( true ) ;
259
265
expect ( theTabs [ 2 ] . isSelected ) . toBe ( false ) ;
260
- expect ( theTabs [ 2 ] . elementRef ( ) . nativeElement . classList . contains ( 'igx-bottom-nav__menu-item' ) ) . toBe ( true ) ;
266
+ expect ( theTabs [ 2 ] . elementRef ( ) . nativeElement . classList . contains ( tabItemNormalCssClass ) ) . toBe ( true ) ;
261
267
262
268
theTabs [ 0 ] . elementRef ( ) . nativeElement . dispatchEvent ( new Event ( 'click' ) ) ;
263
269
fixture . detectChanges ( ) ;
264
270
265
271
expect ( theTabs [ 0 ] . isSelected ) . toBe ( true ) ;
266
- expect ( theTabs [ 0 ] . elementRef ( ) . nativeElement . classList . contains ( 'igx-bottom-nav__menu-item--selected' ) ) . toBe ( true ) ;
272
+ expect ( theTabs [ 0 ] . elementRef ( ) . nativeElement . classList . contains ( tabItemSelectedCssClass ) ) . toBe ( true ) ;
267
273
expect ( theTabs [ 1 ] . isSelected ) . toBe ( false ) ;
268
- expect ( theTabs [ 1 ] . elementRef ( ) . nativeElement . classList . contains ( 'igx-bottom-nav__menu-item' ) ) . toBe ( true ) ;
274
+ expect ( theTabs [ 1 ] . elementRef ( ) . nativeElement . classList . contains ( tabItemNormalCssClass ) ) . toBe ( true ) ;
269
275
expect ( theTabs [ 2 ] . isSelected ) . toBe ( false ) ;
270
- expect ( theTabs [ 2 ] . elementRef ( ) . nativeElement . classList . contains ( 'igx-bottom-nav__menu-item' ) ) . toBe ( true ) ;
276
+ expect ( theTabs [ 2 ] . elementRef ( ) . nativeElement . classList . contains ( tabItemNormalCssClass ) ) . toBe ( true ) ;
271
277
272
278
theTabs [ 2 ] . elementRef ( ) . nativeElement . dispatchEvent ( new Event ( 'click' ) ) ;
273
279
fixture . detectChanges ( ) ;
274
280
275
281
expect ( theTabs [ 0 ] . isSelected ) . toBe ( false ) ;
276
- expect ( theTabs [ 0 ] . elementRef ( ) . nativeElement . classList . contains ( 'igx-bottom-nav__menu-item' ) ) . toBe ( true ) ;
282
+ expect ( theTabs [ 0 ] . elementRef ( ) . nativeElement . classList . contains ( tabItemNormalCssClass ) ) . toBe ( true ) ;
277
283
expect ( theTabs [ 1 ] . isSelected ) . toBe ( false ) ;
278
- expect ( theTabs [ 1 ] . elementRef ( ) . nativeElement . classList . contains ( 'igx-bottom-nav__menu-item' ) ) . toBe ( true ) ;
284
+ expect ( theTabs [ 1 ] . elementRef ( ) . nativeElement . classList . contains ( tabItemNormalCssClass ) ) . toBe ( true ) ;
279
285
expect ( theTabs [ 2 ] . isSelected ) . toBe ( true ) ;
280
- expect ( theTabs [ 2 ] . elementRef ( ) . nativeElement . classList . contains ( 'igx-bottom-nav__menu-item--selected' ) ) . toBe ( true ) ;
286
+ expect ( theTabs [ 2 ] . elementRef ( ) . nativeElement . classList . contains ( tabItemSelectedCssClass ) ) . toBe ( true ) ;
281
287
} ) ;
282
288
283
289
} ) ;
0 commit comments