11/* eslint-disable no-loop-func */
2- import { test , expect , Page , BrowserContext } from '@playwright/test' ;
3- import { chartsListWithErrors , testMatrix } from './test-matrix' ;
4-
2+ import { test , expect } from '@playwright/test' ;
3+ import { chartsListWithErrorsV9 , testMatrix } from './test-matrix' ;
54
65for ( const testConfig of testMatrix ) {
76 const theme = testConfig . theme ;
@@ -10,8 +9,8 @@ for (const testConfig of testMatrix) {
109 const testLocaleName = locale ? `-${ locale } ` : '' ;
1110 const highContrast = testConfig . highContrast ? '-HighContrast' : '' ;
1211 test . describe ( '' , ( ) => {
13- let context : BrowserContext ;
14- let page : Page ;
12+ let context ;
13+ let page ;
1514
1615 test . beforeAll ( async ( { browser } ) => {
1716 if ( testConfig . highContrast ) {
@@ -28,8 +27,9 @@ for (const testConfig of testMatrix) {
2827 test . afterAll ( async ( ) => {
2928 await context ?. close ( ) ;
3029 } ) ;
30+ //test.describe(`Declarative chart examples in ${theme} mode and ${mode} layout`, () => {
3131 for ( let index = testConfig . startExampleIndex ; index <= testConfig . endExampleIndex ; index ++ ) {
32- test ( `Declarative chart example ${ index + 1 } -${ theme } -${ mode } mode${ testLocaleName } ${ highContrast } ` , async ( ) => {
32+ test ( `Declarative chart example ${ index + 1 } -${ theme } -${ mode } mode${ testLocaleName } ${ highContrast } ` , async ( ) => {
3333 const iframe = page . locator ( '#webpack-dev-server-client-overlay' ) ;
3434 if ( await iframe . count ( ) > 0 ) {
3535 await iframe . evaluate ( ( el ) => el . remove ( ) ) . catch ( ( ) => {
@@ -47,57 +47,17 @@ for (const testConfig of testMatrix) {
4747 const combobox = page . getByRole ( 'combobox' ) ;
4848 await combobox . nth ( 1 ) . click ( ) ;
4949 const listitems = listbox . last ( ) . getByRole ( 'option' ) ;
50-
5150 await listitems . nth ( index ) . scrollIntoViewIfNeeded ( ) ;
5251 await listitems . nth ( index ) . click ( ) ;
53- const chart = page . getByTestId ( 'chart-container' ) ;
52+ const chart = page . getByTestId ( 'chart-container-v9 ' ) ;
5453 await page . mouse . move ( 0 , 0 ) ; // Move mouse to top-left corner
55- if ( ! chartsListWithErrors . includes ( index + 1 ) ) {
54+ if ( ! chartsListWithErrorsV9 . includes ( index + 1 ) ) {
5655 await expect ( chart ) . toHaveScreenshot ( ) ;
5756 await combobox . last ( ) . click ( ) ;
5857 } else {
5958 await expect ( chart ) . not . toHaveScreenshot ( ) ;
6059 }
6160 } ) ;
62-
63- test ( `Declarative chart example ${ index + 1 } -${ theme } -${ mode } mode${ testLocaleName } ${ highContrast } Download V9 Chart Image` , async ( ) => {
64- const iframe = page . locator ( '#webpack-dev-server-client-overlay' ) ;
65- if ( await iframe . count ( ) > 0 ) {
66- await iframe . evaluate ( ( el ) => el . remove ( ) ) . catch ( ( ) => {
67- console . warn ( "Failed to remove overlay iframe." ) ;
68- } ) ;
69- }
70- await page . getByRole ( 'combobox' ) . first ( ) . click ( ) ;
71- const listbox = page . getByRole ( 'listbox' ) ;
72- await listbox . getByRole ( 'option' ) . locator ( `text=${ theme } ` ) . click ( ) ;
73- const rtlSwitch = page . getByTestId ( 'rtl_switch' ) ;
74- const isCurrentlyRTL = await rtlSwitch . isChecked ( ) ;
75- if ( ( mode === 'RTL' && ! isCurrentlyRTL ) || ( mode === 'LTR' && isCurrentlyRTL ) ) {
76- await rtlSwitch . click ( ) ;
77- }
78- const combobox = page . getByRole ( 'combobox' ) ;
79- await combobox . nth ( 1 ) . click ( ) ;
80- const listbox1 = page . getByRole ( 'listbox' ) ;
81- const listitems = listbox1 . last ( ) . getByRole ( 'option' ) ;
82- await listitems . nth ( index ) . scrollIntoViewIfNeeded ( ) ;
83- await listitems . nth ( index ) . click ( ) ;
84- const [ download ] = await Promise . all ( [
85- page . waitForEvent ( 'download' ) ,
86- page . getByRole ( 'button' , { name : "Download V9 Chart as Image" } ) . click ( )
87- ] ) ;
88- const downloadedImageBuffer = await stream2buffer ( await download . createReadStream ( ) )
89- expect ( downloadedImageBuffer ) . toMatchSnapshot ( `downloaded-declarative-chart-example-${ index + 1 } -${ theme } -${ mode } mode${ testLocaleName } ${ highContrast } .png` )
90- await download . delete ( )
91- } ) ;
9261 } ;
9362 } ) ;
94- }
95-
96- async function stream2buffer ( stream : Stream ) {
97- return new Promise < Buffer > ( ( resolve , reject ) => {
98- const _buf = Array < any > ( ) ;
99- stream . on ( "data" , chunk => _buf . push ( chunk ) ) ;
100- stream . on ( "end" , ( ) => resolve ( Buffer . concat ( _buf ) ) ) ;
101- stream . on ( "error" , err => reject ( `error converting stream - ${ err } ` ) ) ;
102- } ) ;
103- }
63+ }
0 commit comments