@@ -9,37 +9,62 @@ test.describe("column-chart-web", () => {
9
9
test . beforeEach ( async ( { page } ) => {
10
10
await page . goto ( "/" ) ;
11
11
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
+ } ) ;
12
20
} ) ;
13
21
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
+
14
47
test . describe ( "column color" , ( ) => {
15
48
test ( "renders column chart with default color and compares with a screenshot baseline" , async ( { page } ) => {
16
49
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` ) ;
20
51
} ) ;
21
52
22
53
test ( "renders column chart with custom color and compares with a screenshot baseline" , async ( { page } ) => {
23
54
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` ) ;
27
56
} ) ;
28
57
} ) ;
29
58
30
59
test . describe ( "column format" , ( ) => {
31
60
test ( "renders column chart with grouped format and compares with a screenshot baseline" , async ( { page } ) => {
32
61
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` ) ;
36
63
} ) ;
37
64
38
65
test ( "renders column chart with stacked format and compares with a screenshot baseline" , async ( { page } ) => {
39
66
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` ) ;
43
68
} ) ;
44
69
} ) ;
45
70
} ) ;
0 commit comments