1
- import {
2
- inject ,
3
- async ,
4
- fakeAsync ,
5
- TestComponentBuilder ,
6
- ComponentFixture ,
7
- TestBed ,
8
- } from '@angular/core/testing' ;
1
+ import { async , fakeAsync , ComponentFixture , TestBed } from '@angular/core/testing' ;
9
2
import { NgControl , FormsModule } from '@angular/forms' ;
10
3
import { Component , DebugElement } from '@angular/core' ;
11
4
import { By } from '@angular/platform-browser' ;
12
5
import { MdRadioGroup , MdRadioButton , MdRadioChange , MdRadioModule } from './radio' ;
13
- import {
14
- MdUniqueSelectionDispatcher
15
- } from '@angular2-material/core/coordination/unique-selection-dispatcher' ;
16
6
17
7
18
8
describe ( 'MdRadio' , ( ) => {
19
- let builder : TestComponentBuilder ;
20
- let dispatcher : MdUniqueSelectionDispatcher ;
21
9
22
10
beforeEach ( async ( ( ) => {
23
11
TestBed . configureTestingModule ( {
@@ -32,12 +20,6 @@ describe('MdRadio', () => {
32
20
TestBed . compileComponents ( ) ;
33
21
} ) ) ;
34
22
35
- let injectDeps = [ TestComponentBuilder , MdUniqueSelectionDispatcher ] ;
36
- beforeEach ( inject ( injectDeps , ( tcb : TestComponentBuilder , d : MdUniqueSelectionDispatcher ) => {
37
- builder = tcb ;
38
- dispatcher = d ;
39
- } ) ) ;
40
-
41
23
describe ( 'inside of a group' , ( ) => {
42
24
let fixture : ComponentFixture < RadiosInsideRadioGroup > ;
43
25
let groupDebugElement : DebugElement ;
@@ -50,23 +32,21 @@ describe('MdRadio', () => {
50
32
let testComponent : RadiosInsideRadioGroup ;
51
33
52
34
beforeEach ( async ( ( ) => {
53
- builder . createAsync ( RadiosInsideRadioGroup ) . then ( f => {
54
- fixture = f ;
55
- fixture . detectChanges ( ) ;
35
+ fixture = TestBed . createComponent ( RadiosInsideRadioGroup ) ;
36
+ fixture . detectChanges ( ) ;
56
37
57
- testComponent = fixture . debugElement . componentInstance ;
38
+ testComponent = fixture . debugElement . componentInstance ;
58
39
59
- groupDebugElement = fixture . debugElement . query ( By . directive ( MdRadioGroup ) ) ;
60
- groupNativeElement = groupDebugElement . nativeElement ;
61
- groupInstance = groupDebugElement . injector . get ( MdRadioGroup ) ;
40
+ groupDebugElement = fixture . debugElement . query ( By . directive ( MdRadioGroup ) ) ;
41
+ groupNativeElement = groupDebugElement . nativeElement ;
42
+ groupInstance = groupDebugElement . injector . get ( MdRadioGroup ) ;
62
43
63
- radioDebugElements = fixture . debugElement . queryAll ( By . directive ( MdRadioButton ) ) ;
64
- radioNativeElements = radioDebugElements . map ( debugEl => debugEl . nativeElement ) ;
65
- radioInstances = radioDebugElements . map ( debugEl => debugEl . componentInstance ) ;
44
+ radioDebugElements = fixture . debugElement . queryAll ( By . directive ( MdRadioButton ) ) ;
45
+ radioNativeElements = radioDebugElements . map ( debugEl => debugEl . nativeElement ) ;
46
+ radioInstances = radioDebugElements . map ( debugEl => debugEl . componentInstance ) ;
66
47
67
- radioLabelElements = radioDebugElements
68
- . map ( debugEl => debugEl . query ( By . css ( 'label' ) ) . nativeElement ) ;
69
- } ) ;
48
+ radioLabelElements = radioDebugElements
49
+ . map ( debugEl => debugEl . query ( By . css ( 'label' ) ) . nativeElement ) ;
70
50
} ) ) ;
71
51
72
52
it ( 'should set individual radio names based on the group name' , ( ) => {
@@ -250,26 +230,24 @@ describe('MdRadio', () => {
250
230
let testComponent : RadioGroupWithNgModel ;
251
231
let groupNgControl : NgControl ;
252
232
253
- beforeEach ( async ( ( ) => {
254
- builder . createAsync ( RadioGroupWithNgModel ) . then ( f => {
255
- fixture = f ;
256
- fixture . detectChanges ( ) ;
233
+ beforeEach ( ( ) => {
234
+ fixture = TestBed . createComponent ( RadioGroupWithNgModel ) ;
235
+ fixture . detectChanges ( ) ;
257
236
258
- testComponent = fixture . debugElement . componentInstance ;
237
+ testComponent = fixture . debugElement . componentInstance ;
259
238
260
- groupDebugElement = fixture . debugElement . query ( By . directive ( MdRadioGroup ) ) ;
261
- groupNativeElement = groupDebugElement . nativeElement ;
262
- groupInstance = groupDebugElement . injector . get ( MdRadioGroup ) ;
263
- groupNgControl = groupDebugElement . injector . get ( NgControl ) ;
239
+ groupDebugElement = fixture . debugElement . query ( By . directive ( MdRadioGroup ) ) ;
240
+ groupNativeElement = groupDebugElement . nativeElement ;
241
+ groupInstance = groupDebugElement . injector . get ( MdRadioGroup ) ;
242
+ groupNgControl = groupDebugElement . injector . get ( NgControl ) ;
264
243
265
- radioDebugElements = fixture . debugElement . queryAll ( By . directive ( MdRadioButton ) ) ;
266
- radioNativeElements = radioDebugElements . map ( debugEl => debugEl . nativeElement ) ;
267
- radioInstances = radioDebugElements . map ( debugEl => debugEl . componentInstance ) ;
244
+ radioDebugElements = fixture . debugElement . queryAll ( By . directive ( MdRadioButton ) ) ;
245
+ radioNativeElements = radioDebugElements . map ( debugEl => debugEl . nativeElement ) ;
246
+ radioInstances = radioDebugElements . map ( debugEl => debugEl . componentInstance ) ;
268
247
269
- radioLabelElements = radioDebugElements
270
- . map ( debugEl => debugEl . query ( By . css ( 'label' ) ) . nativeElement ) ;
271
- } ) ;
272
- } ) ) ;
248
+ radioLabelElements = radioDebugElements
249
+ . map ( debugEl => debugEl . query ( By . css ( 'label' ) ) . nativeElement ) ;
250
+ } ) ;
273
251
274
252
it ( 'should set individual radio names based on the group name' , ( ) => {
275
253
expect ( groupInstance . name ) . toBeTruthy ( ) ;
@@ -327,37 +305,6 @@ describe('MdRadio', () => {
327
305
328
306
expect ( testComponent . modelValue ) . toBe ( 'chocolate' ) ;
329
307
} ) ) ;
330
- } ) ;
331
-
332
- describe ( 'group with ngModel and change event' , ( ) => {
333
- let fixture : ComponentFixture < RadioGroupWithNgModel > ;
334
- let groupDebugElement : DebugElement ;
335
- let groupNativeElement : HTMLElement ;
336
- let radioDebugElements : DebugElement [ ] ;
337
- let radioNativeElements : HTMLElement [ ] ;
338
- let groupInstance : MdRadioGroup ;
339
- let radioInstances : MdRadioButton [ ] ;
340
- let testComponent : RadioGroupWithNgModel ;
341
- let groupNgControl : NgControl ;
342
-
343
- beforeEach ( async ( ( ) => {
344
- builder . createAsync ( RadioGroupWithNgModel ) . then ( f => {
345
- fixture = f ;
346
-
347
- testComponent = fixture . componentInstance ;
348
-
349
- groupDebugElement = fixture . debugElement . query ( By . directive ( MdRadioGroup ) ) ;
350
- groupNativeElement = groupDebugElement . nativeElement ;
351
- groupInstance = groupDebugElement . injector . get ( MdRadioGroup ) ;
352
- groupNgControl = groupDebugElement . injector . get ( NgControl ) ;
353
-
354
- radioDebugElements = fixture . debugElement . queryAll ( By . directive ( MdRadioButton ) ) ;
355
- radioNativeElements = radioDebugElements . map ( debugEl => debugEl . nativeElement ) ;
356
- radioInstances = radioDebugElements . map ( debugEl => debugEl . componentInstance ) ;
357
-
358
- fixture . detectChanges ( ) ;
359
- } ) ;
360
- } ) ) ;
361
308
362
309
it ( 'should update the model before firing change event' , fakeAsync ( ( ) => {
363
310
expect ( testComponent . modelValue ) . toBeUndefined ( ) ;
@@ -386,36 +333,32 @@ describe('MdRadio', () => {
386
333
let fruitRadioNativeInputs : HTMLElement [ ] ;
387
334
let testComponent : StandaloneRadioButtons ;
388
335
389
- beforeEach ( async ( ( ) => {
390
- builder . createAsync ( StandaloneRadioButtons ) . then ( f => {
391
- let fruitRadioNativeElements : HTMLElement [ ] ;
392
-
393
- fixture = f ;
394
- fixture . detectChanges ( ) ;
395
-
396
- testComponent = fixture . debugElement . componentInstance ;
397
-
398
- radioDebugElements = fixture . debugElement . queryAll ( By . directive ( MdRadioButton ) ) ;
399
- seasonRadioInstances = radioDebugElements
400
- . filter ( debugEl => debugEl . componentInstance . name == 'season' )
401
- . map ( debugEl => debugEl . componentInstance ) ;
402
- weatherRadioInstances = radioDebugElements
403
- . filter ( debugEl => debugEl . componentInstance . name == 'weather' )
404
- . map ( debugEl => debugEl . componentInstance ) ;
405
- fruitRadioInstances = radioDebugElements
406
- . filter ( debugEl => debugEl . componentInstance . name == 'fruit' )
407
- . map ( debugEl => debugEl . componentInstance ) ;
408
-
409
- fruitRadioNativeElements = radioDebugElements
410
- . filter ( debugEl => debugEl . componentInstance . name == 'fruit' )
411
- . map ( debugEl => debugEl . nativeElement ) ;
412
-
413
- fruitRadioNativeInputs = [ ] ;
414
- for ( let element of fruitRadioNativeElements ) {
415
- fruitRadioNativeInputs . push ( < HTMLElement > element . querySelector ( 'input' ) ) ;
416
- }
417
- } ) ;
418
- } ) ) ;
336
+ beforeEach ( ( ) => {
337
+ fixture = TestBed . createComponent ( StandaloneRadioButtons ) ;
338
+ fixture . detectChanges ( ) ;
339
+
340
+ testComponent = fixture . debugElement . componentInstance ;
341
+
342
+ radioDebugElements = fixture . debugElement . queryAll ( By . directive ( MdRadioButton ) ) ;
343
+ seasonRadioInstances = radioDebugElements
344
+ . filter ( debugEl => debugEl . componentInstance . name == 'season' )
345
+ . map ( debugEl => debugEl . componentInstance ) ;
346
+ weatherRadioInstances = radioDebugElements
347
+ . filter ( debugEl => debugEl . componentInstance . name == 'weather' )
348
+ . map ( debugEl => debugEl . componentInstance ) ;
349
+ fruitRadioInstances = radioDebugElements
350
+ . filter ( debugEl => debugEl . componentInstance . name == 'fruit' )
351
+ . map ( debugEl => debugEl . componentInstance ) ;
352
+
353
+ let fruitRadioNativeElements = radioDebugElements
354
+ . filter ( debugEl => debugEl . componentInstance . name == 'fruit' )
355
+ . map ( debugEl => debugEl . nativeElement ) ;
356
+
357
+ fruitRadioNativeInputs = [ ] ;
358
+ for ( let element of fruitRadioNativeElements ) {
359
+ fruitRadioNativeInputs . push ( < HTMLElement > element . querySelector ( 'input' ) ) ;
360
+ }
361
+ } ) ;
419
362
420
363
it ( 'should uniquely select radios by a name' , ( ) => {
421
364
seasonRadioInstances [ 0 ] . checked = true ;
0 commit comments