Skip to content

feat(material/*) Focus indicator unit tests #18150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/material/button-toggle/button-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,14 @@ describe('MatButtonToggle without forms', () => {
}).not.toThrow();
});

it('should have a focus indicator', () => {
const fixture = TestBed.createComponent(ButtonTogglesInsideButtonToggleGroup);
const buttonNativeElements = [...fixture.debugElement.nativeElement.querySelectorAll('button')];

expect(buttonNativeElements.every(element => element.classList.contains('mat-focus-indicator')))
.toBe(true);
});

});

@Component({
Expand Down
7 changes: 7 additions & 0 deletions src/material/button/button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ describe('MatButton', () => {
);
});
});

it('should have a focus indicator', () => {
const fixture = TestBed.createComponent(TestApp);
const buttonNativeElement = fixture.debugElement.nativeElement.querySelector('button');

expect(buttonNativeElement.classList.contains('mat-focus-indicator')).toBe(true);
});
});

/** Test component that contains an MatButton. */
Expand Down
7 changes: 7 additions & 0 deletions src/material/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,13 @@ describe('MatCheckbox', () => {
expect(checkboxNativeElement.classList).toContain('mat-checkbox-indeterminate');
}));
});

it('should have a focus indicator', () => {
const checkboxRippleNativeElement =
checkboxNativeElement.querySelector('.mat-checkbox-ripple')!;

expect(checkboxRippleNativeElement.classList.contains('mat-focus-indicator')).toBe(true);
});
});

describe('with change event and no initial value', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/material/chips/chip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ describe('MatChip', () => {
});

});

it('should have a focus indicator', () => {
expect(chipNativeElement.classList.contains('mat-focus-indicator')).toBe(true);
});
});
});

Expand Down
7 changes: 7 additions & 0 deletions src/material/core/option/option.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ describe('MatOption component', () => {

});

it('should have a focus indicator', () => {
const fixture = TestBed.createComponent(BasicOption);
const optionNativeElement = fixture.debugElement.query(By.directive(MatOption))!.nativeElement;

expect(optionNativeElement.classList.contains('mat-focus-indicator')).toBe(true);
});

});

@Component({
Expand Down
5 changes: 5 additions & 0 deletions src/material/datepicker/calendar-body.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ describe('MatCalendarBody', () => {
expect(cellEls[1].classList).toContain('even');
});

it('should have a focus indicator', () => {
expect(cellEls.every(element => element.classList.contains('mat-focus-indicator')))
.toBe(true);
});

});

});
Expand Down
8 changes: 8 additions & 0 deletions src/material/expansion/expansion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@ describe('MatExpansionPanel', () => {
});

});

it('should have a focus indicator', () => {
const fixture = TestBed.createComponent(PanelWithContent);
const headerNativeElement =
fixture.debugElement.query(By.directive(MatExpansionPanelHeader))!.nativeElement;

expect(headerNativeElement.classList.contains('mat-focus-indicator')).toBe(true);
});
});


Expand Down
2 changes: 2 additions & 0 deletions src/material/list/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe('MatList', () => {
fixture.detectChanges();
expect(listItem.nativeElement.classList.length).toBe(2);
expect(listItem.nativeElement.classList).toContain('mat-list-item');

// This spec also ensures the focus indicator is present.
expect(listItem.nativeElement.classList).toContain('mat-focus-indicator');
});

Expand Down
7 changes: 7 additions & 0 deletions src/material/list/selection-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,13 @@ describe('MatSelectionList without forms', () => {
expect(option.classList).toContain('mat-2-line');
});

it('should have a focus indicator', () => {
const optionNativeElements = listOptions.map(option => option.nativeElement);

expect(optionNativeElements
.every(element => element.classList.contains('mat-focus-indicator'))).toBe(true);
});

});

describe('with list option selected', () => {
Expand Down
11 changes: 11 additions & 0 deletions src/material/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,17 @@ describe('MatMenu', () => {

});

it('should have a focus indicator', () => {
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
fixture.detectChanges();
fixture.componentInstance.trigger.openMenu();
fixture.detectChanges();
const menuItemNativeElements =
Array.from(overlayContainerElement.querySelectorAll('.mat-menu-item'));

expect(menuItemNativeElements
.every(element => element.classList.contains('mat-focus-indicator'))).toBe(true);
});
});

describe('MatMenu default overrides', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/material/radio/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ describe('MatRadio', () => {
expect(radioNativeElements[2].classList).toContain('mat-warn');
});

it('should have a focus indicator', () => {
const radioRippleNativeElements =
radioNativeElements.map(element => element.querySelector('.mat-radio-ripple')!);

expect(radioRippleNativeElements
.every(element => element.classList.contains('mat-focus-indicator'))).toBe(true);
});

});

describe('group with ngModel', () => {
Expand Down
7 changes: 7 additions & 0 deletions src/material/slide-toggle/slide-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ describe('MatSlideToggle without forms', () => {

expect(slideToggleElement.querySelectorAll(rippleSelector).length).toBe(0);
});

it('should have a focus indicator', () => {
const slideToggleRippleNativeElement =
slideToggleElement.querySelector('.mat-slide-toggle-ripple')!;

expect(slideToggleRippleNativeElement.classList.contains('mat-focus-indicator')).toBe(true);
});
});

describe('custom template', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/material/slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ describe('MatSlider', () => {
expect(event.defaultPrevented).toBe(true);
});

it('should have a focus indicator', () => {
expect(sliderNativeElement.classList.contains('mat-focus-indicator')).toBe(true);
});

});

describe('disabled slider', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/material/sort/sort.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ describe('MatSort', () => {
expect(sortHeaderElement.querySelector('.mat-sort-header-arrow')).toBeTruthy();
}));

it('should have a focus indicator', () => {
const headerNativeElement =
fixture.debugElement.query(By.directive(MatSortHeader))!.nativeElement;
const buttonNativeElement = headerNativeElement.querySelector('.mat-sort-header-button');

expect(buttonNativeElement.classList.contains('mat-focus-indicator')).toBe(true);
});

});

/**
Expand Down
8 changes: 8 additions & 0 deletions src/material/stepper/stepper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,14 @@ describe('MatStepper', () => {
expect(secondStepContentEl.getAttribute('tabindex')).toBe('0');
});

it('should have a focus indicator', () => {
const stepHeaderNativeElements =
[...fixture.debugElement.nativeElement.querySelectorAll('.mat-vertical-stepper-header')];

expect(stepHeaderNativeElements
.every(element => element.classList.contains('mat-focus-indicator'))).toBe(true);
});

});

describe('basic stepper when attempting to set the selected step too early', () => {
Expand Down
7 changes: 7 additions & 0 deletions src/material/tabs/tab-group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ describe('MatTabGroup', () => {
subscription.unsubscribe();
});

it('should have a focus indicator', () => {
const tabLabelNativeElements =
[...fixture.debugElement.nativeElement.querySelectorAll('.mat-tab-label')];

expect(tabLabelNativeElements.every(el => el.classList.contains('mat-focus-indicator')))
.toBe(true);
});
});

describe('aria labelling', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/material/tabs/tab-nav-bar/tab-nav-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ describe('MatTabNavBar', () => {
expect(fixture.componentInstance.tabLinks.toArray().every(tabLink => tabLink.rippleDisabled))
.toBe(true, 'Expected every tab link to have ripples disabled');
});

it('should have a focus indicator', () => {
const tabLinkNativeElements =
[...fixture.debugElement.nativeElement.querySelectorAll('.mat-tab-link')];

expect(tabLinkNativeElements
.every(element => element.classList.contains('mat-focus-indicator'))).toBe(true);
});
});
});

Expand Down
1 change: 0 additions & 1 deletion src/material/tree/tree.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ $mat-node-height: 48px;
align-items: center;
min-height: $mat-node-height;
flex: 1;
overflow: hidden;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to see if this changes any screenshots in Google by running a global presubmit with just this line changed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed 2 screenshots, but one was an improvement in my opinion and the other was a very nit box-shadow diff of some kind. Nothing major.

word-wrap: break-word;
}

Expand Down