Skip to content

Commit 5946f96

Browse files
committed
build: fix test failures and add missing tests
Fixes some CI issues which were caused by older PRs being merged. The PRs were opened, before we had the extra checks for MDC.
1 parent 0484310 commit 5946f96

File tree

6 files changed

+101
-8
lines changed

6 files changed

+101
-8
lines changed

src/material-experimental/mdc-select/select.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,6 +3742,32 @@ describe('MDC-based MatSelect', () => {
37423742
}).not.toThrow();
37433743
}));
37443744

3745+
it('should be able to programmatically set an array with duplicate values', fakeAsync(() => {
3746+
testInstance.foods = [
3747+
{ value: 'steak-0', viewValue: 'Steak' },
3748+
{ value: 'pizza-1', viewValue: 'Pizza' },
3749+
{ value: 'pizza-1', viewValue: 'Pizza' },
3750+
{ value: 'pizza-1', viewValue: 'Pizza' },
3751+
{ value: 'pizza-1', viewValue: 'Pizza' },
3752+
{ value: 'pizza-1', viewValue: 'Pizza' },
3753+
];
3754+
fixture.detectChanges();
3755+
testInstance.control.setValue(['steak-0', 'pizza-1', 'pizza-1', 'pizza-1']);
3756+
fixture.detectChanges();
3757+
3758+
trigger.click();
3759+
fixture.detectChanges();
3760+
3761+
const optionNodes = Array.from(overlayContainerElement.querySelectorAll('mat-option'));
3762+
const optionInstances = testInstance.options.toArray();
3763+
3764+
expect(optionNodes.map(node => node.classList.contains('mdc-list-item--selected')))
3765+
.toEqual([true, true, true, true, false, false]);
3766+
3767+
expect(optionInstances.map(instance => instance.selected))
3768+
.toEqual([true, true, true, true, false, false]);
3769+
}));
3770+
37453771
});
37463772

37473773
it('should be able to provide default values through an injection token', fakeAsync(() => {

src/material-experimental/mdc-tabs/tab-body.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
params: {animationDuration: animationDuration}
55
}"
66
(@translateTab.start)="_onTranslateTabStarted($event)"
7-
(@translateTab.done)="_translateTabComplete.next($event)">
7+
(@translateTab.done)="_translateTabComplete.next($event)"
8+
cdkScrollable>
89
<ng-template matTabBodyHost></ng-template>
910
</div>

src/material-experimental/mdc-tabs/tab-body.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {AfterContentInit, Component, TemplateRef, ViewChild, ViewContainerRef} f
55
import {waitForAsync, ComponentFixture, TestBed} from '@angular/core/testing';
66
import {MatRippleModule} from '@angular/material-experimental/mdc-core';
77
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
8+
import {CdkScrollable, ScrollingModule} from '@angular/cdk/scrolling';
89
import {MatTabBody, MatTabBodyPortal} from './tab-body';
10+
import {By} from '@angular/platform-browser';
911
import {Subject} from 'rxjs';
1012

1113

@@ -178,6 +180,33 @@ describe('MDC-based MatTabBody', () => {
178180

179181
expect(fixture.componentInstance.tabBody._position).toBe('left');
180182
});
183+
184+
it('should mark the tab body content as a scrollable container', () => {
185+
TestBed
186+
.resetTestingModule()
187+
.configureTestingModule({
188+
imports: [
189+
CommonModule,
190+
PortalModule,
191+
MatRippleModule,
192+
NoopAnimationsModule,
193+
ScrollingModule
194+
],
195+
declarations: [
196+
MatTabBody,
197+
MatTabBodyPortal,
198+
SimpleTabBodyApp,
199+
]
200+
})
201+
.compileComponents();
202+
203+
const fixture = TestBed.createComponent(SimpleTabBodyApp);
204+
const tabBodyContent = fixture.nativeElement.querySelector('.mat-mdc-tab-body-content');
205+
const scrollable = fixture.debugElement.query(By.directive(CdkScrollable));
206+
207+
expect(scrollable).toBeTruthy();
208+
expect(scrollable.nativeElement).toBe(tabBodyContent);
209+
});
181210
});
182211

183212

src/material-experimental/mdc-tabs/tab-group.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
[class.mdc-tab--active]="selectedIndex == i"
2222
[disabled]="tab.disabled"
2323
[fitInkBarToContent]="fitInkBarToContent"
24-
(click)="_handleClick(tab, tabHeader, i)">
24+
(click)="_handleClick(tab, tabHeader, i)"
25+
(cdkFocusChange)="_tabFocusChanged($event, i)">
2526
<span class="mdc-tab__ripple"></span>
2627

2728
<!-- Needs to be a separate element, because we can't put

src/material-experimental/mdc-tabs/tab-group.spec.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import {LEFT_ARROW} from '@angular/cdk/keycodes';
22
import {dispatchFakeEvent, dispatchKeyboardEvent} from '@angular/cdk/testing/private';
33
import {Component, OnInit, QueryList, ViewChild, ViewChildren} from '@angular/core';
4-
import {waitForAsync, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
4+
import {
5+
waitForAsync,
6+
ComponentFixture,
7+
fakeAsync,
8+
TestBed,
9+
tick,
10+
flush,
11+
} from '@angular/core/testing';
512
import {By} from '@angular/platform-browser';
613
import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
714
import {CommonModule} from '@angular/common';
@@ -300,6 +307,26 @@ describe('MDC-based MatTabGroup', () => {
300307
.toBe(true);
301308
});
302309

310+
it('should emit focusChange when a tab receives focus', fakeAsync(() => {
311+
spyOn(fixture.componentInstance, 'handleFocus');
312+
fixture.detectChanges();
313+
314+
const tabLabels = fixture.debugElement.queryAll(By.css('.mat-mdc-tab'));
315+
316+
expect(fixture.componentInstance.handleFocus).toHaveBeenCalledTimes(0);
317+
318+
// In order to verify that the `focusChange` event also fires with the correct
319+
// index, we focus the second tab before testing the keyboard navigation.
320+
dispatchFakeEvent(tabLabels[2].nativeElement, 'focus');
321+
fixture.detectChanges();
322+
flush();
323+
fixture.detectChanges();
324+
325+
expect(fixture.componentInstance.handleFocus).toHaveBeenCalledTimes(1);
326+
expect(fixture.componentInstance.handleFocus)
327+
.toHaveBeenCalledWith(jasmine.objectContaining({index: 2}));
328+
}));
329+
303330
});
304331

305332
describe('aria labelling', () => {

src/material/tabs/tab-group.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import {LEFT_ARROW} from '@angular/cdk/keycodes';
22
import {dispatchFakeEvent, dispatchKeyboardEvent} from '@angular/cdk/testing/private';
33
import {Component, OnInit, QueryList, ViewChild, ViewChildren} from '@angular/core';
4-
import {waitForAsync, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
4+
import {
5+
waitForAsync,
6+
ComponentFixture,
7+
fakeAsync,
8+
TestBed,
9+
tick,
10+
flush,
11+
} from '@angular/core/testing';
512
import {By} from '@angular/platform-browser';
613
import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
714
import {CommonModule} from '@angular/common';
@@ -299,7 +306,7 @@ describe('MatTabGroup', () => {
299306
.toBe(true);
300307
});
301308

302-
it('should emit focusChange when a tab receives focus', () => {
309+
it('should emit focusChange when a tab receives focus', fakeAsync(() => {
303310
spyOn(fixture.componentInstance, 'handleFocus');
304311
fixture.detectChanges();
305312

@@ -309,13 +316,15 @@ describe('MatTabGroup', () => {
309316

310317
// In order to verify that the `focusChange` event also fires with the correct
311318
// index, we focus the second tab before testing the keyboard navigation.
312-
dispatchFakeEvent(tabLabels[1].nativeElement, 'focus');
319+
dispatchFakeEvent(tabLabels[2].nativeElement, 'focus');
320+
fixture.detectChanges();
321+
flush();
313322
fixture.detectChanges();
314323

315324
expect(fixture.componentInstance.handleFocus).toHaveBeenCalledTimes(1);
316325
expect(fixture.componentInstance.handleFocus)
317-
.toHaveBeenCalledWith(jasmine.objectContaining({index: 1}));
318-
});
326+
.toHaveBeenCalledWith(jasmine.objectContaining({index: 2}));
327+
}));
319328

320329
});
321330

0 commit comments

Comments
 (0)