Skip to content

Commit 3cc2bb3

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 3cc2bb3

File tree

6 files changed

+87
-8
lines changed

6 files changed

+87
-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: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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 {waitForAsync, ComponentFixture, fakeAsync, TestBed, tick, flush} from '@angular/core/testing';
55
import {By} from '@angular/platform-browser';
66
import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
77
import {CommonModule} from '@angular/common';
@@ -300,6 +300,26 @@ describe('MDC-based MatTabGroup', () => {
300300
.toBe(true);
301301
});
302302

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

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

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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 {waitForAsync, ComponentFixture, fakeAsync, TestBed, tick, flush} from '@angular/core/testing';
55
import {By} from '@angular/platform-browser';
66
import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
77
import {CommonModule} from '@angular/common';
@@ -299,7 +299,7 @@ describe('MatTabGroup', () => {
299299
.toBe(true);
300300
});
301301

302-
it('should emit focusChange when a tab receives focus', () => {
302+
it('should emit focusChange when a tab receives focus', fakeAsync(() => {
303303
spyOn(fixture.componentInstance, 'handleFocus');
304304
fixture.detectChanges();
305305

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

310310
// In order to verify that the `focusChange` event also fires with the correct
311311
// index, we focus the second tab before testing the keyboard navigation.
312-
dispatchFakeEvent(tabLabels[1].nativeElement, 'focus');
312+
dispatchFakeEvent(tabLabels[2].nativeElement, 'focus');
313+
fixture.detectChanges();
314+
flush();
313315
fixture.detectChanges();
314316

315317
expect(fixture.componentInstance.handleFocus).toHaveBeenCalledTimes(1);
316318
expect(fixture.componentInstance.handleFocus)
317-
.toHaveBeenCalledWith(jasmine.objectContaining({index: 1}));
318-
});
319+
.toHaveBeenCalledWith(jasmine.objectContaining({index: 2}));
320+
}));
319321

320322
});
321323

0 commit comments

Comments
 (0)