|
1 | 1 | import {dispatchFakeEvent} from '@angular/cdk/testing'; |
2 | | -import {ChangeDetectionStrategy, Component, DebugElement, Type, ViewChild} from '@angular/core'; |
| 2 | +import {ChangeDetectionStrategy, Component, DebugElement, Type} from '@angular/core'; |
3 | 3 | import { |
4 | 4 | ComponentFixture, |
5 | 5 | fakeAsync, |
@@ -68,6 +68,29 @@ describe('MatCheckbox', () => { |
68 | 68 | expect(inputElement.checked).toBe(false); |
69 | 69 | })); |
70 | 70 |
|
| 71 | + |
| 72 | + it('should toggle checkbox ripple disabledness correctly', fakeAsync(() => { |
| 73 | + const rippleSelector = '.mat-ripple-element:not(.mat-checkbox-persistent-ripple)'; |
| 74 | + const labelElement = checkboxNativeElement.querySelector('label') as HTMLLabelElement; |
| 75 | + |
| 76 | + testComponent.isDisabled = true; |
| 77 | + fixture.detectChanges(); |
| 78 | + dispatchFakeEvent(labelElement, 'mousedown'); |
| 79 | + dispatchFakeEvent(labelElement, 'mouseup'); |
| 80 | + labelElement.click(); |
| 81 | + expect(checkboxNativeElement.querySelectorAll(rippleSelector).length).toBe(0); |
| 82 | + |
| 83 | + flush(); |
| 84 | + testComponent.isDisabled = false; |
| 85 | + fixture.detectChanges(); |
| 86 | + dispatchFakeEvent(labelElement, 'mousedown'); |
| 87 | + dispatchFakeEvent(labelElement, 'mouseup'); |
| 88 | + labelElement.click(); |
| 89 | + expect(checkboxNativeElement.querySelectorAll(rippleSelector).length).toBe(1); |
| 90 | + |
| 91 | + flush(); |
| 92 | + })); |
| 93 | + |
71 | 94 | it('should add and remove indeterminate state', fakeAsync(() => { |
72 | 95 | expect(inputElement.checked).toBe(false); |
73 | 96 | expect(inputElement.indeterminate).toBe(false); |
@@ -689,64 +712,6 @@ describe('MatCheckbox', () => { |
689 | 712 | })); |
690 | 713 | }); |
691 | 714 |
|
692 | | - describe('using ViewChild', () => { |
693 | | - let checkboxDebugElement: DebugElement; |
694 | | - let checkboxNativeElement: HTMLElement; |
695 | | - let testComponent: CheckboxUsingViewChild; |
696 | | - |
697 | | - beforeEach(() => { |
698 | | - fixture = createComponent(CheckboxUsingViewChild); |
699 | | - fixture.detectChanges(); |
700 | | - |
701 | | - checkboxDebugElement = fixture.debugElement.query(By.directive(MatCheckbox)); |
702 | | - checkboxNativeElement = checkboxDebugElement.nativeElement; |
703 | | - testComponent = fixture.debugElement.componentInstance; |
704 | | - }); |
705 | | - |
706 | | - it('should toggle checkbox disabledness correctly', fakeAsync(() => { |
707 | | - const checkboxInstance = checkboxDebugElement.componentInstance; |
708 | | - const inputElement = <HTMLInputElement>checkboxNativeElement.querySelector('input'); |
709 | | - expect(checkboxInstance.disabled).toBe(false); |
710 | | - expect(inputElement.tabIndex).toBe(0); |
711 | | - expect(inputElement.disabled).toBe(false); |
712 | | - |
713 | | - testComponent.isDisabled = true; |
714 | | - fixture.detectChanges(); |
715 | | - |
716 | | - expect(checkboxInstance.disabled).toBe(true); |
717 | | - expect(inputElement.disabled).toBe(true); |
718 | | - |
719 | | - testComponent.isDisabled = false; |
720 | | - fixture.detectChanges(); |
721 | | - |
722 | | - expect(checkboxInstance.disabled).toBe(false); |
723 | | - expect(inputElement.tabIndex).toBe(0); |
724 | | - expect(inputElement.disabled).toBe(false); |
725 | | - })); |
726 | | - |
727 | | - it('should toggle checkbox ripple disabledness correctly', fakeAsync(() => { |
728 | | - const rippleSelector = '.mat-ripple-element:not(.mat-checkbox-persistent-ripple)'; |
729 | | - const labelElement = checkboxNativeElement.querySelector('label') as HTMLLabelElement; |
730 | | - |
731 | | - testComponent.isDisabled = true; |
732 | | - fixture.detectChanges(); |
733 | | - dispatchFakeEvent(labelElement, 'mousedown'); |
734 | | - dispatchFakeEvent(labelElement, 'mouseup'); |
735 | | - labelElement.click(); |
736 | | - expect(checkboxNativeElement.querySelectorAll(rippleSelector).length).toBe(0); |
737 | | - |
738 | | - flush(); |
739 | | - testComponent.isDisabled = false; |
740 | | - fixture.detectChanges(); |
741 | | - dispatchFakeEvent(labelElement, 'mousedown'); |
742 | | - dispatchFakeEvent(labelElement, 'mouseup'); |
743 | | - labelElement.click(); |
744 | | - expect(checkboxNativeElement.querySelectorAll(rippleSelector).length).toBe(1); |
745 | | - |
746 | | - flush(); |
747 | | - })); |
748 | | - }); |
749 | | - |
750 | 715 | describe('with multiple checkboxes', () => { |
751 | 716 | beforeEach(() => { |
752 | 717 | fixture = createComponent(MultipleCheckboxes); |
@@ -1034,21 +999,6 @@ class CheckboxWithTabIndex { |
1034 | 999 | isDisabled: boolean = false; |
1035 | 1000 | } |
1036 | 1001 |
|
1037 | | - |
1038 | | -/** Simple test component that accesses MatCheckbox using ViewChild. */ |
1039 | | -@Component({ |
1040 | | - template: ` |
1041 | | - <mat-checkbox></mat-checkbox>`, |
1042 | | -}) |
1043 | | -class CheckboxUsingViewChild { |
1044 | | - @ViewChild(MatCheckbox, {static: false}) checkbox: MatCheckbox; |
1045 | | - |
1046 | | - set isDisabled(value: boolean) { |
1047 | | - this.checkbox.disabled = value; |
1048 | | - this.checkbox.markForCheck(); |
1049 | | - } |
1050 | | -} |
1051 | | - |
1052 | 1002 | /** Simple test component with an aria-label set. */ |
1053 | 1003 | @Component({template: `<mat-checkbox aria-label="Super effective"></mat-checkbox>`}) |
1054 | 1004 | class CheckboxWithAriaLabel { |
|
0 commit comments