Skip to content

Commit 17566ba

Browse files
test(column-chart-web): improve screenshot comparison
1 parent 0f69360 commit 17566ba

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

packages/pluggableWidgets/column-chart-web/e2e/ColumnChart.spec.js

+37-12
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,62 @@ test.describe("column-chart-web", () => {
99
test.beforeEach(async ({ page }) => {
1010
await page.goto("/");
1111
await page.waitForLoadState("networkidle");
12+
// Disable CSS animations and transitions for stability
13+
await page.addStyleTag({ content: `* { transition: none !important; animation: none !important; }` });
14+
// Wait for all fonts to be loaded
15+
await page.evaluate(async () => {
16+
if (typeof document !== "undefined" && document.fonts) {
17+
await document.fonts.ready;
18+
}
19+
});
1220
});
1321

22+
async function stableScreenshot(locator, screenshotName) {
23+
await locator.scrollIntoViewIfNeeded();
24+
await expect(locator).toBeVisible({ timeout: 10000 });
25+
// Wait for all images to load
26+
await locator.evaluate(async el => {
27+
const images = el.querySelectorAll("img");
28+
await Promise.all(
29+
Array.from(images).map(img => {
30+
if (img.complete) {
31+
return Promise.resolve();
32+
}
33+
return new Promise(resolve => {
34+
img.onload = img.onerror = resolve;
35+
});
36+
})
37+
);
38+
});
39+
// Add a short delay to ensure rendering is complete
40+
await locator.page().waitForTimeout(200);
41+
await expect(locator).toHaveScreenshot(screenshotName, {
42+
animations: "disabled",
43+
fullPage: false
44+
});
45+
}
46+
1447
test.describe("column color", () => {
1548
test("renders column chart with default color and compares with a screenshot baseline", async ({ page }) => {
1649
const defaultColorContainer = page.locator(".mx-name-containerDefaultColor");
17-
await defaultColorContainer.scrollIntoViewIfNeeded();
18-
await expect(defaultColorContainer).toBeVisible({ timeout: 10000 });
19-
await expect(defaultColorContainer).toHaveScreenshot(`columnChartDefaultColor.png`);
50+
await stableScreenshot(defaultColorContainer, `columnChartDefaultColor.png`);
2051
});
2152

2253
test("renders column chart with custom color and compares with a screenshot baseline", async ({ page }) => {
2354
const customColorContainer = page.locator(".mx-name-containerCustomColor");
24-
await customColorContainer.scrollIntoViewIfNeeded();
25-
await expect(customColorContainer).toBeVisible({ timeout: 10000 });
26-
await expect(customColorContainer).toHaveScreenshot(`columnChartCustomColor.png`);
55+
await stableScreenshot(customColorContainer, `columnChartCustomColor.png`);
2756
});
2857
});
2958

3059
test.describe("column format", () => {
3160
test("renders column chart with grouped format and compares with a screenshot baseline", async ({ page }) => {
3261
const groupContainer = page.locator(".mx-name-containerGroup");
33-
await groupContainer.scrollIntoViewIfNeeded();
34-
await expect(groupContainer).toBeVisible({ timeout: 10000 });
35-
await expect(groupContainer).toHaveScreenshot(`columnChartGrouped.png`);
62+
await stableScreenshot(groupContainer, `columnChartGrouped.png`);
3663
});
3764

3865
test("renders column chart with stacked format and compares with a screenshot baseline", async ({ page }) => {
3966
const stackContainer = page.locator(".mx-name-containerStack");
40-
await stackContainer.scrollIntoViewIfNeeded();
41-
await expect(stackContainer).toBeVisible({ timeout: 10000 });
42-
await expect(stackContainer).toHaveScreenshot(`columnChartStacked.png`);
67+
await stableScreenshot(stackContainer, `columnChartStacked.png`);
4368
});
4469
});
4570
});

0 commit comments

Comments
 (0)