|
1 | | -import {dispatchMouseEvent} from '@angular/cdk/testing/private'; |
2 | | -import {Component, DebugElement, QueryList, ViewChild, ViewChildren} from '@angular/core'; |
| 1 | +import {dispatchFakeEvent, dispatchMouseEvent} from '@angular/cdk/testing/private'; |
| 2 | +import { |
| 3 | + Component, |
| 4 | + DebugElement, |
| 5 | + Provider, |
| 6 | + QueryList, |
| 7 | + Type, |
| 8 | + ViewChild, |
| 9 | + ViewChildren, |
| 10 | +} from '@angular/core'; |
3 | 11 | import {CommonModule} from '@angular/common'; |
4 | 12 | import {ComponentFixture, fakeAsync, flush, TestBed, tick} from '@angular/core/testing'; |
5 | 13 | import {FormControl, FormsModule, NgModel, ReactiveFormsModule} from '@angular/forms'; |
6 | 14 | import {By} from '@angular/platform-browser'; |
7 | 15 | import { |
| 16 | + MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS, |
8 | 17 | MatButtonToggle, |
9 | 18 | MatButtonToggleChange, |
| 19 | + MatButtonToggleDefaultOptions, |
10 | 20 | MatButtonToggleGroup, |
11 | 21 | MatButtonToggleModule, |
12 | 22 | } from './index'; |
@@ -546,6 +556,13 @@ describe('MatButtonToggle without forms', () => { |
546 | 556 | expect(groupInstance.value).toBeFalsy(); |
547 | 557 | expect(groupInstance.selected).toBeFalsy(); |
548 | 558 | })); |
| 559 | + |
| 560 | + it('should show checkmark indicator by default', () => { |
| 561 | + buttonToggleLabelElements[0].click(); |
| 562 | + fixture.detectChanges(); |
| 563 | + |
| 564 | + expect(document.querySelectorAll('.mat-pseudo-checkbox').length).toBe(1); |
| 565 | + }); |
549 | 566 | }); |
550 | 567 |
|
551 | 568 | describe('with initial value and change event', () => { |
@@ -701,6 +718,14 @@ describe('MatButtonToggle without forms', () => { |
701 | 718 | groupInstance.value = 'not-an-array'; |
702 | 719 | }).toThrowError(/Value must be an array/); |
703 | 720 | }); |
| 721 | + |
| 722 | + it('should show checkmark indicator by default', () => { |
| 723 | + buttonToggleLabelElements[0].click(); |
| 724 | + buttonToggleLabelElements[1].click(); |
| 725 | + fixture.detectChanges(); |
| 726 | + |
| 727 | + expect(document.querySelectorAll('.mat-pseudo-checkbox').length).toBe(2); |
| 728 | + }); |
704 | 729 | }); |
705 | 730 |
|
706 | 731 | describe('as standalone', () => { |
@@ -876,6 +901,52 @@ describe('MatButtonToggle without forms', () => { |
876 | 901 | }); |
877 | 902 | }); |
878 | 903 |
|
| 904 | + describe('with tokens to hide checkmark selection indicators', () => { |
| 905 | + beforeEach(() => { |
| 906 | + TestBed.configureTestingModule({ |
| 907 | + imports: [ |
| 908 | + MatButtonToggleModule, |
| 909 | + ButtonTogglesInsideButtonToggleGroup, |
| 910 | + ButtonTogglesInsideButtonToggleGroupMultiple, |
| 911 | + ], |
| 912 | + providers: [ |
| 913 | + { |
| 914 | + provide: MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS, |
| 915 | + useValue: { |
| 916 | + hideSingleSelectionIndicator: true, |
| 917 | + hideMultipleSelectionIndicator: true, |
| 918 | + }, |
| 919 | + }, |
| 920 | + ], |
| 921 | + }); |
| 922 | + |
| 923 | + TestBed.compileComponents(); |
| 924 | + }); |
| 925 | + |
| 926 | + it('should hide checkmark indicator for single selection', () => { |
| 927 | + const fixture = TestBed.createComponent(ButtonTogglesInsideButtonToggleGroup); |
| 928 | + fixture.detectChanges(); |
| 929 | + |
| 930 | + fixture.debugElement.query(By.css('button')).nativeElement.click(); |
| 931 | + fixture.detectChanges(); |
| 932 | + |
| 933 | + expect(document.querySelectorAll('.mat-pseudo-checkbox').length).toBe(0); |
| 934 | + }); |
| 935 | + |
| 936 | + it('should hide checkmark indicator for multiple selection', () => { |
| 937 | + const fixture = TestBed.createComponent(ButtonTogglesInsideButtonToggleGroupMultiple); |
| 938 | + fixture.detectChanges(); |
| 939 | + |
| 940 | + // Check all button toggles in the group |
| 941 | + fixture.debugElement |
| 942 | + .queryAll(By.css('button')) |
| 943 | + .forEach(toggleButton => toggleButton.nativeElement.click()); |
| 944 | + fixture.detectChanges(); |
| 945 | + |
| 946 | + expect(document.querySelectorAll('.mat-pseudo-checkbox').length).toBe(0); |
| 947 | + }); |
| 948 | + }); |
| 949 | + |
879 | 950 | it('should not throw on init when toggles are repeated and there is an initial value', () => { |
880 | 951 | const fixture = TestBed.createComponent(RepeatedButtonTogglesWithPreselectedValue); |
881 | 952 |
|
|
0 commit comments