Skip to content

Commit f15dea8

Browse files
authored
Improve e2e stability (#722)
1 parent d702149 commit f15dea8

File tree

4 files changed

+150
-126
lines changed

4 files changed

+150
-126
lines changed

e2e/VGrid.spec.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
scrollToBottom,
66
scrollToRight,
77
getScrollable,
8+
relativeTop,
9+
relativeLeft,
810
} from "./utils";
911

1012
test.describe("smoke", () => {
@@ -42,17 +44,14 @@ test("check if scrollToIndex works", async ({ page }) => {
4244

4345
await button.click();
4446

45-
await (await component.elementHandle())!.waitForElementState("stable");
46-
4747
// Check if scrolled precisely
48-
const firstItem = await getFirstItem(component);
49-
expect(firstItem.text).toEqual(
50-
`${await colInput.evaluate(
51-
(e) => (e as HTMLInputElement).value
52-
)} / ${await rowInput.evaluate((e) => (e as HTMLInputElement).value)}`
53-
);
54-
expect(firstItem.top).toEqual(0);
55-
expect(firstItem.left).toEqual(0);
48+
const text = `${await colInput.evaluate(
49+
(e) => (e as HTMLInputElement).value
50+
)} / ${await rowInput.evaluate((e) => (e as HTMLInputElement).value)}`;
51+
const firstItem = component.getByText(text, { exact: true });
52+
await expect(firstItem).toBeVisible();
53+
expect(await relativeTop(component, firstItem)).toEqual(0);
54+
expect(await relativeLeft(component, firstItem)).toEqual(0);
5655

5756
// Check if unnecessary items are not rendered
5857
await expect(component.getByText("650", { exact: true })).not.toBeVisible();

e2e/VList.spec.ts

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ import {
1414
getScrollRight,
1515
expectInRange,
1616
scrollWithTouch,
17-
getFirstItemRtl,
1817
scrollToLeft,
1918
getVirtualizer,
2019
getScrollable,
2120
clearTimer,
2221
scrollTo,
2322
listenScrollCount,
23+
relativeRight,
24+
relativeTop,
25+
relativeBottom,
2426
} from "./utils";
2527

2628
test.describe("smoke", () => {
@@ -578,12 +580,10 @@ test.describe("check if scrollToIndex works", () => {
578580
await input.fill("700");
579581
await button.click();
580582

581-
await (await component.elementHandle())!.waitForElementState("stable");
582-
583583
// Check if scrolled precisely
584-
const firstItem = await getFirstItem(component);
585-
expect(firstItem.text).toEqual("700");
586-
expect(firstItem.top).toEqual(0);
584+
const firstItem = component.getByText("700", { exact: true });
585+
await expect(firstItem).toBeVisible();
586+
expect(await relativeTop(component, firstItem)).toEqual(0);
587587

588588
// Check if unnecessary items are not rendered
589589
await expect(
@@ -609,24 +609,20 @@ test.describe("check if scrollToIndex works", () => {
609609
await input.fill("500");
610610
await button.click();
611611

612-
await (await component.elementHandle())!.waitForElementState("stable");
613-
614612
await expect(component.getByText("500", { exact: true })).toBeVisible();
615613

616614
await clearInput(input);
617615
await input.fill("0");
618616
await button.click();
619617

620-
await (await component.elementHandle())!.waitForElementState("stable");
621-
622618
// Check if scrolled precisely
623-
const firstItem = await getFirstItem(component);
624-
expect(firstItem.text).toEqual("0");
625-
expect(firstItem.top).toEqual(0);
619+
const firstItem = component.getByText("0", { exact: true });
620+
await expect(firstItem).toBeVisible();
621+
expect(await relativeTop(component, firstItem)).toEqual(0);
626622

627623
// Check if unnecessary items are not rendered
628624
await expect(
629-
component.getByText("50\n", { exact: true })
625+
component.getByText("50", { exact: true })
630626
).not.toBeVisible();
631627
});
632628

@@ -645,12 +641,13 @@ test.describe("check if scrollToIndex works", () => {
645641
await input.fill("999");
646642
await button.click();
647643

648-
await (await component.elementHandle())!.waitForElementState("stable");
649-
650644
// Check if scrolled precisely
651-
const lastItem = await getLastItem(component);
652-
expect(lastItem.text).toEqual("999");
653-
expectInRange(lastItem.bottom, { min: -0.9, max: 1 });
645+
const lastItem = component.getByText("999", { exact: true });
646+
await expect(lastItem).toBeVisible();
647+
expectInRange(await relativeBottom(component, lastItem), {
648+
min: -0.9,
649+
max: 1,
650+
});
654651

655652
// Check if unnecessary items are not rendered
656653
await expect(
@@ -722,12 +719,13 @@ test.describe("check if scrollToIndex works", () => {
722719
await input.fill("700");
723720
await button.click();
724721

725-
await (await component.elementHandle())!.waitForElementState("stable");
726-
727722
// Check if scrolled precisely
728-
const lastItem = await getLastItem(component);
729-
expect(lastItem.text).toEqual("700");
730-
expectInRange(lastItem.bottom, { min: 0, max: 1 });
723+
const lastItem = component.getByText("700", { exact: true });
724+
await expect(lastItem).toBeVisible();
725+
expectInRange(await relativeBottom(component, lastItem), {
726+
min: 0,
727+
max: 1,
728+
});
731729

732730
// Check if unnecessary items are not rendered
733731
await expect(
@@ -753,24 +751,20 @@ test.describe("check if scrollToIndex works", () => {
753751
await input.fill("500");
754752
await button.click();
755753

756-
await (await component.elementHandle())!.waitForElementState("stable");
757-
758754
await expect(component.getByText("500", { exact: true })).toBeVisible();
759755

760756
await clearInput(input);
761757
await input.fill("0");
762758
await button.click();
763759

764-
await (await component.elementHandle())!.waitForElementState("stable");
765-
766760
// Check if scrolled precisely
767-
const firstItem = await getFirstItem(component);
768-
expect(firstItem.text).toEqual("0");
769-
expect(firstItem.top).toEqual(0);
761+
const firstItem = component.getByText("0", { exact: true });
762+
await expect(firstItem).toBeVisible();
763+
expect(await relativeTop(component, firstItem)).toEqual(0);
770764

771765
// Check if unnecessary items are not rendered
772766
await expect(
773-
component.getByText("50\n", { exact: true })
767+
component.getByText("50", { exact: true })
774768
).not.toBeVisible();
775769
});
776770

@@ -789,12 +783,13 @@ test.describe("check if scrollToIndex works", () => {
789783
await input.fill("999");
790784
await button.click();
791785

792-
await (await component.elementHandle())!.waitForElementState("stable");
793-
794786
// Check if scrolled precisely
795-
const lastItem = await getLastItem(component);
796-
expect(lastItem.text).toEqual("999");
797-
expectInRange(lastItem.bottom, { min: -0.5, max: 1 });
787+
const lastItem = component.getByText("999", { exact: true });
788+
await expect(lastItem).toBeVisible();
789+
expectInRange(await relativeBottom(component, lastItem), {
790+
min: -0.5,
791+
max: 1,
792+
});
798793

799794
// Check if unnecessary items are not rendered
800795
await expect(
@@ -1258,9 +1253,9 @@ test.describe("RTL", () => {
12581253
const component = await getScrollable(page);
12591254

12601255
// check if start is displayed
1261-
const first = await getFirstItemRtl(component);
1262-
expect(first.text).toEqual("Column 0");
1263-
expect(first.right).toEqual(0);
1256+
const first = component.getByText("Column 0", { exact: true });
1257+
await expect(first).toBeVisible();
1258+
expect(await relativeRight(component, first)).toEqual(0);
12641259

12651260
// scroll to the end
12661261
await scrollToLeft(component);

0 commit comments

Comments
 (0)