Skip to content

Commit 96683fc

Browse files
committed
chore: more test failures
1 parent 214c203 commit 96683fc

File tree

1 file changed

+75
-63
lines changed

1 file changed

+75
-63
lines changed

src/lib/select/select.spec.ts

Lines changed: 75 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,20 +1162,22 @@ describe('MatSelect', () => {
11621162
fixture.componentInstance.control.setValue('chips-4');
11631163
fixture.detectChanges();
11641164

1165-
trigger.click();
1166-
fixture.detectChanges();
1165+
fixture.whenStable().then(() => {
1166+
trigger.click();
1167+
fixture.detectChanges();
11671168

1168-
const scrollContainer = document.querySelector('.cdk-overlay-pane .mat-select-panel')!;
1169+
const scrollContainer = document.querySelector('.cdk-overlay-pane .mat-select-panel')!;
11691170

1170-
fixture.whenStable().then(() => {
1171-
// The selected option should be scrolled to the center of the panel.
1172-
// This will be its original offset from the scrollTop - half the panel height + half the
1173-
// option height. 4 (index) * 48 (option height) = 192px offset from scrollTop
1174-
// 192 - 256/2 + 48/2 = 88px
1175-
expect(scrollContainer.scrollTop)
1176-
.toEqual(88, `Expected overlay panel to be scrolled to center the selected option.`);
1171+
fixture.whenStable().then(() => {
1172+
// The selected option should be scrolled to the center of the panel.
1173+
// This will be its original offset from the scrollTop - half the panel height + half
1174+
// the option height. 4 (index) * 48 (option height) = 192px offset from scrollTop
1175+
// 192 - 256/2 + 48/2 = 88px
1176+
expect(scrollContainer.scrollTop)
1177+
.toEqual(88, `Expected overlay panel to be scrolled to center the selected option.`);
11771178

1178-
checkTriggerAlignedWithOption(4);
1179+
checkTriggerAlignedWithOption(4);
1180+
});
11791181
});
11801182
}));
11811183

@@ -1184,19 +1186,21 @@ describe('MatSelect', () => {
11841186
fixture.componentInstance.control.setValue('sushi-7');
11851187
fixture.detectChanges();
11861188

1187-
trigger.click();
1188-
fixture.detectChanges();
1189+
fixture.whenStable().then(() => {
1190+
trigger.click();
1191+
fixture.detectChanges();
11891192

1190-
const scrollContainer = document.querySelector('.cdk-overlay-pane .mat-select-panel')!;
1193+
const scrollContainer = document.querySelector('.cdk-overlay-pane .mat-select-panel')!;
11911194

1192-
fixture.whenStable().then(() => {
1193-
// The selected option should be scrolled to the max scroll position.
1194-
// This will be the height of the scrollContainer - the panel height.
1195-
// 8 options * 48px = 384 scrollContainer height, 384 - 256 = 128px max scroll
1196-
expect(scrollContainer.scrollTop)
1197-
.toEqual(128, `Expected overlay panel to be scrolled to its maximum position.`);
1195+
fixture.whenStable().then(() => {
1196+
// The selected option should be scrolled to the max scroll position.
1197+
// This will be the height of the scrollContainer - the panel height.
1198+
// 8 options * 48px = 384 scrollContainer height, 384 - 256 = 128px max scroll
1199+
expect(scrollContainer.scrollTop)
1200+
.toEqual(128, `Expected overlay panel to be scrolled to its maximum position.`);
11981201

1199-
checkTriggerAlignedWithOption(7);
1202+
checkTriggerAlignedWithOption(7);
1203+
});
12001204
});
12011205
}));
12021206

@@ -1279,17 +1283,19 @@ describe('MatSelect', () => {
12791283
fixture.componentInstance.control.setValue('chips-4');
12801284
fixture.detectChanges();
12811285

1282-
trigger.click();
1283-
fixture.detectChanges();
1286+
fixture.whenStable().then(() => {
1287+
trigger.click();
1288+
fixture.detectChanges();
12841289

1285-
const scrollContainer = document.querySelector('.cdk-overlay-pane .mat-select-panel')!;
1290+
const scrollContainer = document.querySelector('.cdk-overlay-pane .mat-select-panel')!;
12861291

1287-
fixture.whenStable().then(() => {
1288-
expect(Math.ceil(scrollContainer.scrollTop))
1289-
.toEqual(Math.ceil(idealScrollTop + 5),
1290-
`Expected panel to adjust scroll position to fit in viewport.`);
1292+
fixture.whenStable().then(() => {
1293+
expect(Math.ceil(scrollContainer.scrollTop))
1294+
.toEqual(Math.ceil(idealScrollTop + 5),
1295+
`Expected panel to adjust scroll position to fit in viewport.`);
12911296

1292-
checkTriggerAlignedWithOption(4);
1297+
checkTriggerAlignedWithOption(4);
1298+
});
12931299
});
12941300
}));
12951301

@@ -1402,23 +1408,25 @@ describe('MatSelect', () => {
14021408
fixture.componentInstance.control.setValue('sushi-7');
14031409
fixture.detectChanges();
14041410

1405-
trigger.click();
1406-
fixture.detectChanges();
1407-
14081411
fixture.whenStable().then(() => {
1409-
const overlayPane = document.querySelector('.cdk-overlay-pane')!;
1410-
const triggerTop = trigger.getBoundingClientRect().top;
1411-
const overlayTop = overlayPane.getBoundingClientRect().top;
1412-
const scrollContainer = overlayPane.querySelector('.mat-select-panel')!;
1412+
trigger.click();
1413+
fixture.detectChanges();
1414+
1415+
fixture.whenStable().then(() => {
1416+
const overlayPane = document.querySelector('.cdk-overlay-pane')!;
1417+
const triggerTop = trigger.getBoundingClientRect().top;
1418+
const overlayTop = overlayPane.getBoundingClientRect().top;
1419+
const scrollContainer = overlayPane.querySelector('.mat-select-panel')!;
14131420

1414-
// Expect scroll to remain at the max scroll position
1415-
expect(scrollContainer.scrollTop).toEqual(128, `Expected panel to be at max scroll.`);
1421+
// Expect scroll to remain at the max scroll position
1422+
expect(scrollContainer.scrollTop).toEqual(128, `Expected panel to be at max scroll.`);
14161423

1417-
expect(Math.floor(overlayTop))
1418-
.toEqual(Math.floor(triggerTop), `Expected trigger top to align with overlay top.`);
1424+
expect(Math.floor(overlayTop))
1425+
.toEqual(Math.floor(triggerTop), `Expected trigger top to align with overlay top.`);
14191426

1420-
expect(fixture.componentInstance.select._transformOrigin)
1421-
.toContain(`top`, `Expected panel animation to originate at the top.`);
1427+
expect(fixture.componentInstance.select._transformOrigin)
1428+
.toContain(`top`, `Expected panel animation to originate at the top.`);
1429+
});
14221430
});
14231431
}));
14241432

@@ -1574,23 +1582,25 @@ describe('MatSelect', () => {
15741582
fixture.componentInstance.control.setValue('chips-4');
15751583
fixture.detectChanges();
15761584

1577-
// Scroll the select into view
1578-
setScrollTop(1700);
1579-
1580-
// In the iOS simulator (BrowserStack & SauceLabs), adding the content to the
1581-
// body causes karma's iframe for the test to stretch to fit that content once we attempt to
1582-
// scroll the page. Setting width / height / maxWidth / maxHeight on the iframe does not
1583-
// successfully constrain its size. As such, skip assertions in environments where the
1584-
// window size has changed since the start of the test.
1585-
if (window.innerHeight > startingWindowHeight) {
1586-
return;
1587-
}
1585+
fixture.whenStable().then(() => {
1586+
// Scroll the select into view
1587+
setScrollTop(1700);
1588+
1589+
// In the iOS simulator (BrowserStack & SauceLabs), adding the content to the
1590+
// body causes karma's iframe for the test to stretch to fit that content once we attempt
1591+
// to scroll the page. Setting width / height / maxWidth / maxHeight on the iframe does
1592+
// not successfully constrain its size. As such, skip assertions in environments where the
1593+
// window size has changed since the start of the test.
1594+
if (window.innerHeight > startingWindowHeight) {
1595+
return;
1596+
}
15881597

1589-
trigger.click();
1590-
fixture.detectChanges();
1598+
trigger.click();
1599+
fixture.detectChanges();
15911600

1592-
fixture.whenStable().then(() => {
1593-
checkTriggerAlignedWithOption(4);
1601+
fixture.whenStable().then(() => {
1602+
checkTriggerAlignedWithOption(4);
1603+
});
15941604
});
15951605
}));
15961606

@@ -1601,15 +1611,17 @@ describe('MatSelect', () => {
16011611
fixture.componentInstance.control.setValue('chips-4');
16021612
fixture.detectChanges();
16031613

1604-
trigger.click();
1605-
fixture.detectChanges();
1606-
16071614
fixture.whenStable().then(() => {
1608-
setScrollTop(100);
1609-
scrolledSubject.next();
1615+
trigger.click();
16101616
fixture.detectChanges();
16111617

1612-
checkTriggerAlignedWithOption(4);
1618+
fixture.whenStable().then(() => {
1619+
setScrollTop(100);
1620+
scrolledSubject.next();
1621+
fixture.detectChanges();
1622+
1623+
checkTriggerAlignedWithOption(4);
1624+
});
16131625
});
16141626
}));
16151627

0 commit comments

Comments
 (0)