@@ -16,15 +16,7 @@ describe('The Sam Radio Buttons component', () => {
1616 component = new SamRadioButtonComponent ( cdr ) ;
1717 } ) ;
1818
19- it ( 'should implement controlvalueaccessor' , ( ) => {
20- component . onChange ( ) ;
21- component . onTouched ( ) ;
22- component . registerOnChange ( ( _ ) => undefined ) ;
23- component . registerOnTouched ( ( ) => undefined ) ;
24- component . setDisabledState ( false ) ;
25- component . writeValue ( 'test' ) ;
26- expect ( component . model ) . toBe ( 'test' ) ;
27- } ) ;
19+
2820
2921 it ( 'should process radio changes' , ( ) => {
3022 component . onRadioChange ( 'newval' ) ;
@@ -43,54 +35,54 @@ describe('The Sam Radio Buttons component', () => {
4335 describe ( 'rendered tests' , ( ) => {
4436 let component : SamRadioButtonComponent ;
4537 let fixture : any ;
46-
38+
4739 const options : any [ ] = [
48- { value : 'dc' , label : 'Washington DC' , name : 'dc' } ,
49- { value : 'ma' , label : 'Maryland' , name : 'dc' } ,
50- { value : 'va' , label : 'Virginia' , name : 'virginia' } ,
40+ { value : 'dc' , label : 'Washington DC' , name : 'dc' } ,
41+ { value : 'ma' , label : 'Maryland' , name : 'dc' } ,
42+ { value : 'va' , label : 'Virginia' , name : 'virginia' } ,
5143 ] ;
52-
44+
5345 const defaultOptions = {
5446 options : options ,
5547 label : 'Radio buttons' ,
5648 name : 'my-radio-buttons'
5749 } ;
58-
50+
5951 // provide our implementations or mocks to the dependency injector
6052 beforeEach ( ( ) => {
6153 TestBed . configureTestingModule ( {
6254 declarations : [ SamRadioButtonComponent ] ,
6355 imports : [ SamWrapperModule , FormsModule ] ,
6456 providers : [ SamFormService ]
6557 } ) ;
66-
58+
6759 fixture = TestBed . createComponent ( SamRadioButtonComponent ) ;
6860 component = fixture . componentInstance ;
6961 component . options = defaultOptions . options ;
7062 component . label = defaultOptions . label ;
7163 component . name = defaultOptions . name ;
7264 } ) ;
73-
65+
7466 it ( 'should display 3 radiobuttons if 3 options are specified by the config' ,
7567 function ( ) {
76- fixture . detectChanges ( ) ;
68+ fixture . detectChanges ( ) ;
7769
78- expect ( fixture . nativeElement . getElementsByTagName ( 'input' ) . length )
79- . toBe ( options . length ) ;
80- } ) ;
81-
82- it ( 'should allow an initial value to be set by the model input' ,
70+ expect ( fixture . nativeElement . getElementsByTagName ( 'input' ) . length )
71+ . toBe ( options . length ) ;
72+ } ) ;
73+
74+ it ( 'should allow an initial value to be set by the model input' ,
8375 async ( ( ) => {
84- component . model = 'ma' ;
85- fixture . detectChanges ( ) ;
76+ component . model = 'ma' ;
77+ fixture . detectChanges ( ) ;
8678
87- const checkedElement =
88- fixture . debugElement . query ( By . css ( ':checked + label' ) ) ;
79+ const checkedElement =
80+ fixture . debugElement . query ( By . css ( ':checked + label' ) ) ;
81+
82+ expect ( checkedElement . nativeElement . innerHTML ) . toContain ( 'Maryland' ) ;
83+ expect ( checkedElement . nativeElement . innerHTML ) . not . toContain ( 'DC' ) ;
84+ } ) ) ;
8985
90- expect ( checkedElement . nativeElement . innerHTML ) . toContain ( 'Maryland' ) ;
91- expect ( checkedElement . nativeElement . innerHTML ) . not . toContain ( 'DC' ) ;
92- } ) ) ;
93-
9486 it ( 'should deselect one radio button when another is clicked' , function ( ) {
9587 component . model = 'ma' ;
9688 fixture . detectChanges ( ) ;
@@ -108,21 +100,21 @@ describe('The Sam Radio Buttons component', () => {
108100
109101 expect ( label1 ) . not . toEqual ( label2 ) ;
110102 } ) ;
111-
103+
112104 it ( 'should show a hint message' , function ( ) {
113105 const hint = 'Life pro tip: eat vegetables' ;
114106 component . hint = hint ;
115107 fixture . detectChanges ( ) ;
116108 expect ( fixture . nativeElement . innerHTML ) . toContain ( hint ) ;
117109 } ) ;
118-
110+
119111 it ( 'should show an error message' , function ( ) {
120112 const errorMessage = 'Uh-oh, something went wrong' ;
121113 component . errorMessage = errorMessage ;
122114 fixture . detectChanges ( ) ;
123115 expect ( fixture . nativeElement . innerHTML ) . toContain ( errorMessage ) ;
124116 } ) ;
125-
117+
126118 it ( 'should show a label' , function ( ) {
127119 const labelText = 'Pick from the following options' ;
128120 component . label = labelText ;
0 commit comments