@@ -284,36 +284,52 @@ describe('checkbox', () => {
284284 describe ( 'checkbox group form' , ( ) => {
285285 let fixture : ComponentFixture < NzTestCheckboxGroupFormComponent > ;
286286 let testComponent : NzTestCheckboxGroupFormComponent ;
287- let checkboxGroup : DebugElement ;
288- let inputElement : HTMLInputElement ;
289-
290287 beforeEach ( fakeAsync ( ( ) => {
291288 fixture = TestBed . createComponent ( NzTestCheckboxGroupFormComponent ) ;
292- fixture . detectChanges ( ) ;
293- flush ( ) ;
294- fixture . detectChanges ( ) ;
295- testComponent = fixture . debugElement . componentInstance ;
296- checkboxGroup = fixture . debugElement . query ( By . directive ( NzCheckboxGroupComponent ) ) ;
297- inputElement = checkboxGroup . nativeElement . querySelector ( 'input' ) as HTMLInputElement ;
289+ testComponent = fixture . componentInstance ;
298290 } ) ) ;
299291 it ( 'should be in pristine, untouched, and valid states initially' , fakeAsync ( ( ) => {
292+ fixture . detectChanges ( ) ;
300293 flush ( ) ;
294+ const checkboxGroupComponent : NzCheckboxGroupComponent = fixture . debugElement . query (
295+ By . directive ( NzCheckboxGroupComponent )
296+ ) . componentInstance ;
301297 expect ( testComponent . formGroup . get ( 'checkboxGroup' ) ! . valid ) . toBe ( true ) ;
302298 expect ( testComponent . formGroup . get ( 'checkboxGroup' ) ! . pristine ) . toBe ( true ) ;
303299 expect ( testComponent . formGroup . get ( 'checkboxGroup' ) ! . touched ) . toBe ( false ) ;
300+ expect ( checkboxGroupComponent . nzDisabled ) . toBeFalsy ( ) ;
301+ } ) ) ;
302+ it ( 'should be disable if form is disable and nzDisable set to false initially' , fakeAsync ( ( ) => {
303+ testComponent . formGroup . disable ( ) ;
304+ fixture . detectChanges ( ) ;
305+ flush ( ) ;
306+ const checkboxGroup = fixture . debugElement . query ( By . directive ( NzCheckboxGroupComponent ) ) ;
307+ expect ( checkboxGroup . componentInstance . nzDisabled ) . toBeTruthy ( ) ;
304308 } ) ) ;
305309 it ( 'should set disabled work' , fakeAsync ( ( ) => {
310+ testComponent . nzDisabled = true ;
311+ fixture . detectChanges ( ) ;
306312 flush ( ) ;
313+ const checkboxGroup = fixture . debugElement . query ( By . directive ( NzCheckboxGroupComponent ) ) ;
314+ const inputElement = checkboxGroup . nativeElement . querySelector ( 'input' ) as HTMLInputElement ;
315+ expect ( checkboxGroup . componentInstance . nzDisabled ) . toBeTruthy ( ) ;
316+
317+ inputElement . click ( ) ;
318+ fixture . detectChanges ( ) ;
307319 expect ( JSON . stringify ( testComponent . formGroup . get ( 'checkboxGroup' ) ! . value ) ) . toBe (
308320 JSON . stringify ( [
309321 { label : 'Apple' , value : 'Apple' , checked : true } ,
310322 { label : 'Pear' , value : 'Pear' , disabled : true } ,
311323 { label : 'Orange' , value : 'Orange' }
312324 ] )
313325 ) ;
314- inputElement . click ( ) ;
326+
327+ testComponent . enable ( ) ;
315328 fixture . detectChanges ( ) ;
316329 flush ( ) ;
330+ expect ( checkboxGroup . componentInstance . nzDisabled ) . toBeFalsy ( ) ;
331+
332+ inputElement . click ( ) ;
317333 fixture . detectChanges ( ) ;
318334 expect ( JSON . stringify ( testComponent . formGroup . get ( 'checkboxGroup' ) ! . value ) ) . toBe (
319335 JSON . stringify ( [
@@ -322,12 +338,13 @@ describe('checkbox', () => {
322338 { label : 'Orange' , value : 'Orange' }
323339 ] )
324340 ) ;
341+
325342 testComponent . disable ( ) ;
326343 fixture . detectChanges ( ) ;
327344 flush ( ) ;
328- fixture . detectChanges ( ) ;
345+ expect ( checkboxGroup . componentInstance . nzDisabled ) . toBeTruthy ( ) ;
346+
329347 inputElement . click ( ) ;
330- flush ( ) ;
331348 fixture . detectChanges ( ) ;
332349 expect ( JSON . stringify ( testComponent . formGroup . get ( 'checkboxGroup' ) ! . value ) ) . toBe (
333350 JSON . stringify ( [
@@ -479,12 +496,13 @@ export class NzTestCheckboxFormComponent {
479496@Component ( {
480497 template : `
481498 <form [formGroup]="formGroup">
482- <nz-checkbox-group formControlName="checkboxGroup"></nz-checkbox-group>
499+ <nz-checkbox-group formControlName="checkboxGroup" [nzDisabled]="nzDisabled" ></nz-checkbox-group>
483500 </form>
484501 `
485502} )
486503export class NzTestCheckboxGroupFormComponent {
487504 formGroup : UntypedFormGroup ;
505+ nzDisabled = false ;
488506
489507 constructor ( private formBuilder : UntypedFormBuilder ) {
490508 this . formGroup = this . formBuilder . group ( {
@@ -501,6 +519,10 @@ export class NzTestCheckboxGroupFormComponent {
501519 disable ( ) : void {
502520 this . formGroup . disable ( ) ;
503521 }
522+
523+ enable ( ) : void {
524+ this . formGroup . enable ( ) ;
525+ }
504526}
505527
506528@Component ( {
0 commit comments