Skip to content

Commit c9288ed

Browse files
crisbetozarend
authored andcommitted
test: clean up IE/Edge test workarounds (#24364)
The workarounds shouldn't be necessary since we don't run tests against IE and legacy Edge anymore. (cherry picked from commit ad03673)
1 parent 5485d12 commit c9288ed

File tree

9 files changed

+34
-182
lines changed

9 files changed

+34
-182
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {Platform, PlatformModule} from '@angular/cdk/platform';
21
import {dispatchFakeEvent, wrappedErrorMessage} from '../../cdk/testing/private';
32
import {
43
ChangeDetectionStrategy,
@@ -38,6 +37,7 @@ import {MatIconModule} from '@angular/material/icon';
3837
import {By} from '@angular/platform-browser';
3938
import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
4039
import {MAT_INPUT_VALUE_ACCESSOR, MatInput, MatInputModule} from './index';
40+
import {getSupportedInputTypes} from '@angular/cdk/platform';
4141

4242
describe('MatMdcInput without forms', () => {
4343
it('should default to floating labels', fakeAsync(() => {
@@ -69,24 +69,21 @@ describe('MatMdcInput without forms', () => {
6969

7070
it('should not be treated as empty if type is date', fakeAsync(() => {
7171
const fixture = createComponent(MatInputDateTestController);
72-
const platform = TestBed.inject(Platform);
7372
fixture.detectChanges();
7473

75-
if (!(platform.TRIDENT || (platform.SAFARI && !platform.IOS))) {
74+
if (getSupportedInputTypes().has('date')) {
7675
const formField = fixture.debugElement.query(By.directive(MatFormField))!
7776
.componentInstance as MatFormField;
7877
expect(formField).toBeTruthy();
7978
expect(formField!._control.empty).toBe(false);
8079
}
8180
}));
8281

83-
// Safari Desktop and IE don't support type="date" and fallback to type="text".
84-
it('should be treated as empty if type is date in Safari Desktop or IE', fakeAsync(() => {
82+
it('should be treated as empty if type is date on unsupported browser', fakeAsync(() => {
8583
const fixture = createComponent(MatInputDateTestController);
86-
const platform = TestBed.inject(Platform);
8784
fixture.detectChanges();
8885

89-
if (platform.TRIDENT || (platform.SAFARI && !platform.IOS)) {
86+
if (!getSupportedInputTypes().has('date')) {
9087
const formField = fixture.debugElement.query(By.directive(MatFormField))!
9188
.componentInstance as MatFormField;
9289
expect(formField).toBeTruthy();
@@ -1486,7 +1483,6 @@ function configureTestingModule(
14861483
MatIconModule,
14871484
MatInputModule,
14881485
animations ? BrowserAnimationsModule : NoopAnimationsModule,
1489-
PlatformModule,
14901486
ReactiveFormsModule,
14911487
...imports,
14921488
],

src/material/button/testing/shared.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function runHarnessTests(
9393
// cancel dispatched click events on disabled buttons. We skip this check on Edge and Firefox.
9494
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1582570 and:
9595
// https://stackoverflow.com/questions/32377026/disabled-button-is-clickable-on-edge-browser
96-
if (platform.EDGE || platform.FIREFOX) {
96+
if (platform.FIREFOX) {
9797
return;
9898
}
9999

src/material/grid-list/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ ng_test_library(
4949
deps = [
5050
":grid-list",
5151
"//src/cdk/bidi",
52-
"//src/cdk/platform",
5352
"@npm//@angular/platform-browser",
5453
],
5554
)

src/material/grid-list/grid-list.spec.ts

Lines changed: 2 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,20 @@
1-
import {TestBed, ComponentFixture, inject} from '@angular/core/testing';
1+
import {TestBed, ComponentFixture} from '@angular/core/testing';
22
import {Component, DebugElement, Type, ViewChild} from '@angular/core';
33
import {By} from '@angular/platform-browser';
44
import {MatGridList, MatGridListModule} from './index';
55
import {MatGridTile, MatGridTileText} from './grid-tile';
66
import {Directionality} from '@angular/cdk/bidi';
7-
import {Platform} from '@angular/cdk/platform';
87

98
describe('MatGridList', () => {
10-
let disableComputedStyleTests = false;
11-
129
function createComponent<T>(componentType: Type<T>): ComponentFixture<T> {
1310
TestBed.configureTestingModule({
1411
imports: [MatGridListModule],
1512
declarations: [componentType],
1613
}).compileComponents();
1714

18-
const fixture = TestBed.createComponent<T>(componentType);
19-
20-
inject([Platform], (platform: Platform) => {
21-
// IE and Edge aren't consistent in the values that they return from `getComputedStyle`.
22-
// In some cases they return the computed values, and in others the passed-in ones. We use
23-
// this flag to disable the tests that depend on `getComputedStyle` in order to avoid flakes.
24-
// TODO: we can re-enable them when we start testing against the Chromium-based Edge.
25-
disableComputedStyleTests = platform.EDGE || platform.TRIDENT;
26-
})();
27-
28-
return fixture;
15+
return TestBed.createComponent<T>(componentType);
2916
}
3017

31-
afterEach(() => (disableComputedStyleTests = false));
32-
3318
it('should throw error if cols is not defined', () => {
3419
const fixture = createComponent(GridListWithoutCols);
3520

@@ -86,10 +71,6 @@ describe('MatGridList', () => {
8671
it('should default to 1:1 row height if undefined ', () => {
8772
const fixture = createComponent(GridListWithUnspecifiedRowHeight);
8873

89-
if (disableComputedStyleTests) {
90-
return;
91-
}
92-
9374
fixture.detectChanges();
9475
const tile = fixture.debugElement.query(By.directive(MatGridTile))!;
9576
const inlineStyles = tile.nativeElement.style;
@@ -103,10 +84,6 @@ describe('MatGridList', () => {
10384
it('should use a ratio row height if passed in', () => {
10485
const fixture = createComponent(GirdListWithRowHeightRatio);
10586

106-
if (disableComputedStyleTests) {
107-
return;
108-
}
109-
11087
fixture.componentInstance.rowHeight = '4:1';
11188
fixture.detectChanges();
11289

@@ -128,10 +105,6 @@ describe('MatGridList', () => {
128105
it('should divide row height evenly in "fit" mode', () => {
129106
const fixture = createComponent(GridListWithFitRowHeightMode);
130107

131-
if (disableComputedStyleTests) {
132-
return;
133-
}
134-
135108
fixture.componentInstance.totalHeight = '300px';
136109
fixture.detectChanges();
137110
const tile = fixture.debugElement.query(By.directive(MatGridTile))!;
@@ -149,10 +122,6 @@ describe('MatGridList', () => {
149122
it('should use the fixed row height if passed in', () => {
150123
const fixture = createComponent(GridListWithFixedRowHeightMode);
151124

152-
if (disableComputedStyleTests) {
153-
return;
154-
}
155-
156125
fixture.componentInstance.rowHeight = '100px';
157126
fixture.detectChanges();
158127

@@ -168,10 +137,6 @@ describe('MatGridList', () => {
168137
it('should default to pixels if row height units are missing', () => {
169138
const fixture = createComponent(GridListWithUnitlessFixedRowHeight);
170139

171-
if (disableComputedStyleTests) {
172-
return;
173-
}
174-
175140
fixture.detectChanges();
176141
const tile = fixture.debugElement.query(By.directive(MatGridTile))!;
177142
expect(getDimension(tile, 'height')).toBe(100);
@@ -180,10 +145,6 @@ describe('MatGridList', () => {
180145
it('should default gutter size to 1px', () => {
181146
const fixture = createComponent(GridListWithUnspecifiedGutterSize);
182147

183-
if (disableComputedStyleTests) {
184-
return;
185-
}
186-
187148
fixture.detectChanges();
188149
const tiles = fixture.debugElement.queryAll(By.css('mat-grid-tile'));
189150

@@ -200,10 +161,6 @@ describe('MatGridList', () => {
200161
const fixture = createComponent(GridListWithUnspecifiedGutterSize);
201162
const gridList = fixture.debugElement.query(By.directive(MatGridList))!;
202163

203-
if (disableComputedStyleTests) {
204-
return;
205-
}
206-
207164
gridList.componentInstance.gutterSize = 0;
208165
fixture.detectChanges();
209166

@@ -221,10 +178,6 @@ describe('MatGridList', () => {
221178
it('should lay out the tiles correctly for a nested grid list', () => {
222179
const fixture = createComponent(NestedGridList);
223180

224-
if (disableComputedStyleTests) {
225-
return;
226-
}
227-
228181
fixture.detectChanges();
229182
const innerTiles = fixture.debugElement.queryAll(
230183
By.css('mat-grid-tile mat-grid-list mat-grid-tile'),
@@ -238,10 +191,6 @@ describe('MatGridList', () => {
238191
it('should set the gutter size if passed', () => {
239192
const fixture = createComponent(GridListWithGutterSize);
240193

241-
if (disableComputedStyleTests) {
242-
return;
243-
}
244-
245194
fixture.detectChanges();
246195
const tiles = fixture.debugElement.queryAll(By.css('mat-grid-tile'));
247196

@@ -257,10 +206,6 @@ describe('MatGridList', () => {
257206
it('should use pixels if gutter units are missing', () => {
258207
const fixture = createComponent(GridListWithUnitlessGutterSize);
259208

260-
if (disableComputedStyleTests) {
261-
return;
262-
}
263-
264209
fixture.detectChanges();
265210
const tiles = fixture.debugElement.queryAll(By.css('mat-grid-tile'));
266211

@@ -277,10 +222,6 @@ describe('MatGridList', () => {
277222
const fixture = createComponent(GridListWithUnspecifiedGutterSize);
278223
const gridList = fixture.debugElement.query(By.directive(MatGridList))!;
279224

280-
if (disableComputedStyleTests) {
281-
return;
282-
}
283-
284225
gridList.componentInstance.gutterSize = '10%';
285226
fixture.detectChanges();
286227

@@ -293,10 +234,6 @@ describe('MatGridList', () => {
293234
it('should set the correct list height in ratio mode', () => {
294235
const fixture = createComponent(GridListWithRatioHeightAndMulipleRows);
295236

296-
if (disableComputedStyleTests) {
297-
return;
298-
}
299-
300237
fixture.detectChanges();
301238
const list = fixture.debugElement.query(By.directive(MatGridList))!;
302239
const inlineStyles = list.nativeElement.style;
@@ -309,10 +246,6 @@ describe('MatGridList', () => {
309246
it('should set the correct list height in fixed mode', () => {
310247
const fixture = createComponent(GridListWithFixRowHeightAndMultipleRows);
311248

312-
if (disableComputedStyleTests) {
313-
return;
314-
}
315-
316249
fixture.detectChanges();
317250
const list = fixture.debugElement.query(By.directive(MatGridList))!;
318251
expect(getDimension(list, 'height')).toBe(201);
@@ -321,10 +254,6 @@ describe('MatGridList', () => {
321254
it('should allow adjustment of tile colspan', () => {
322255
const fixture = createComponent(GridListWithColspanBinding);
323256

324-
if (disableComputedStyleTests) {
325-
return;
326-
}
327-
328257
fixture.componentInstance.colspan = 2;
329258
fixture.detectChanges();
330259

@@ -339,10 +268,6 @@ describe('MatGridList', () => {
339268
it('should allow adjustment of tile rowspan', () => {
340269
const fixture = createComponent(GridListWithRowspanBinding);
341270

342-
if (disableComputedStyleTests) {
343-
return;
344-
}
345-
346271
fixture.componentInstance.rowspan = 2;
347272
fixture.detectChanges();
348273

@@ -357,10 +282,6 @@ describe('MatGridList', () => {
357282
it('should lay out tiles correctly for a complex layout', () => {
358283
const fixture = createComponent(GridListWithComplexLayout);
359284

360-
if (disableComputedStyleTests) {
361-
return;
362-
}
363-
364285
fixture.componentInstance.tiles = [
365286
{cols: 3, rows: 1},
366287
{cols: 1, rows: 2},
@@ -395,10 +316,6 @@ describe('MatGridList', () => {
395316
it('should lay out tiles correctly', () => {
396317
const fixture = createComponent(GridListWithLayout);
397318

398-
if (disableComputedStyleTests) {
399-
return;
400-
}
401-
402319
fixture.detectChanges();
403320
const tiles = fixture.debugElement.queryAll(By.css('mat-grid-tile'));
404321

@@ -431,10 +348,6 @@ describe('MatGridList', () => {
431348
it('should lay out tiles correctly when single cell to be placed at the beginning', () => {
432349
const fixture = createComponent(GridListWithSingleCellAtBeginning);
433350

434-
if (disableComputedStyleTests) {
435-
return;
436-
}
437-
438351
fixture.detectChanges();
439352
const tiles = fixture.debugElement.queryAll(By.css('mat-grid-tile'));
440353

@@ -497,10 +410,6 @@ describe('MatGridList', () => {
497410
it('should reset the old styles when switching to a new tile styler', () => {
498411
const fixture = createComponent(GirdListWithRowHeightRatio);
499412

500-
if (disableComputedStyleTests) {
501-
return;
502-
}
503-
504413
fixture.componentInstance.rowHeight = '4:1';
505414
fixture.detectChanges();
506415

@@ -562,10 +471,6 @@ describe('MatGridList', () => {
562471
it('should lay out the tiles if they are not direct descendants of the list', () => {
563472
const fixture = createComponent(GridListWithIndirectTileDescendants);
564473

565-
if (disableComputedStyleTests) {
566-
return;
567-
}
568-
569474
fixture.detectChanges();
570475
const tile = fixture.debugElement.query(By.directive(MatGridTile))!;
571476
const inlineStyles = tile.nativeElement.style;

src/material/input/input.spec.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Platform, PlatformModule, _supportsShadowDom} from '@angular/cdk/platform';
1+
import {getSupportedInputTypes, _supportsShadowDom} from '@angular/cdk/platform';
22
import {
33
createFakeEvent,
44
dispatchFakeEvent,
@@ -77,23 +77,20 @@ describe('MatInput without forms', () => {
7777

7878
it('should not be treated as empty if type is date', fakeAsync(() => {
7979
const fixture = createComponent(MatInputDateTestController);
80-
const platform = TestBed.inject(Platform);
8180
fixture.detectChanges();
8281

83-
if (!(platform.TRIDENT || (platform.SAFARI && !platform.IOS))) {
82+
if (getSupportedInputTypes().has('date')) {
8483
const el = fixture.debugElement.query(By.css('label'))!.nativeElement;
8584
expect(el).not.toBeNull();
8685
expect(el.classList.contains('mat-form-field-empty')).toBe(false);
8786
}
8887
}));
8988

90-
// Safari Desktop and IE don't support type="date" and fallback to type="text".
91-
it('should be treated as empty if type is date in Safari Desktop or IE', fakeAsync(() => {
89+
it('should be treated as empty if type is date on unsupported browser', fakeAsync(() => {
9290
const fixture = createComponent(MatInputDateTestController);
93-
const platform = TestBed.inject(Platform);
9491
fixture.detectChanges();
9592

96-
if (platform.TRIDENT || (platform.SAFARI && !platform.IOS)) {
93+
if (!getSupportedInputTypes().has('date')) {
9794
const el = fixture.debugElement.query(By.css('label'))!.nativeElement;
9895
expect(el).not.toBeNull();
9996
expect(el.classList.contains('mat-form-field-empty')).toBe(true);
@@ -1862,7 +1859,6 @@ function createComponent<T>(
18621859
MatFormFieldModule,
18631860
MatInputModule,
18641861
BrowserAnimationsModule,
1865-
PlatformModule,
18661862
ReactiveFormsModule,
18671863
...imports,
18681864
],

src/material/select/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ ng_test_library(
6363
"//src/cdk/bidi",
6464
"//src/cdk/keycodes",
6565
"//src/cdk/overlay",
66-
"//src/cdk/platform",
6766
"//src/cdk/scrolling",
6867
"//src/cdk/testing/private",
6968
"//src/material/core",

0 commit comments

Comments
 (0)