@@ -18,7 +18,6 @@ async function login(page: Page) {
1818 await sel ( page , 'Password input field' ) . fill ( 'admin' ) ;
1919 await sel ( page , 'Login button' ) . click ( ) ;
2020 await sel ( page , 'Skip change password button' ) . click ( ) ;
21- await page . waitForLoadState ( 'networkidle' ) ;
2221}
2322
2423async function goToTrinoSettings ( page : Page ) {
@@ -32,6 +31,15 @@ async function goToTrinoSettings(page: Page) {
3231 }
3332}
3433
34+ // Wait for Save & Test response: "Data source is working" or any error text
35+ async function waitForSaveTestResult ( page : Page ) : Promise < boolean > {
36+ const success = page . getByText ( 'Data source is working' ) ;
37+ const error = page . getByText ( 'Data source is not working' ) ;
38+ // Wait for either success or failure message
39+ await success . or ( error ) . waitFor ( { timeout : 30000 } ) ;
40+ return await success . isVisible ( ) ;
41+ }
42+
3543async function setupDataSourceWithAccessToken ( page : Page ) {
3644 await sel ( page , 'Datasource HTTP settings url' ) . fill ( 'http://trino:8080' ) ;
3745 if ( isNewGrafana ) {
@@ -41,7 +49,6 @@ async function setupDataSourceWithAccessToken(page: Page) {
4149 }
4250 await page . locator ( 'div' ) . filter ( { hasText : / ^ A c c e s s t o k e n $ / } ) . locator ( 'input[type="password"]' ) . fill ( 'aaa' ) ;
4351 await sel ( page , 'Data source settings page Save and Test button' ) . click ( ) ;
44- await page . waitForSelector ( '[role="alert"]' , { timeout : 10000 } ) ;
4552}
4653
4754async function setupDataSourceWithClientCredentials ( page : Page , clientId : string ) {
@@ -51,7 +58,6 @@ async function setupDataSourceWithClientCredentials(page: Page, clientId: string
5158 await page . locator ( 'div' ) . filter ( { hasText : / ^ C l i e n t s e c r e t $ / } ) . locator ( 'input[type="password"]' ) . fill ( 'grafana-secret' ) ;
5259 await page . locator ( 'div' ) . filter ( { hasText : / ^ I m p e r s o n a t i o n u s e r $ / } ) . locator ( 'input' ) . fill ( 'service-account-grafana-client' ) ;
5360 await sel ( page , 'Data source settings page Save and Test button' ) . click ( ) ;
54- await page . waitForSelector ( '[role="alert"]' , { timeout : 10000 } ) ;
5561}
5662
5763async function runQueryAndCheckResults ( page : Page ) {
@@ -80,33 +86,33 @@ test('test with access token', async ({ page }) => {
8086 await login ( page ) ;
8187 await goToTrinoSettings ( page ) ;
8288 await setupDataSourceWithAccessToken ( page ) ;
89+ const ok = await waitForSaveTestResult ( page ) ;
90+ expect ( ok ) . toBe ( true ) ;
8391 await runQueryAndCheckResults ( page ) ;
8492} ) ;
8593
8694test ( 'test client credentials flow' , async ( { page } ) => {
8795 await login ( page ) ;
8896 await goToTrinoSettings ( page ) ;
8997 await setupDataSourceWithClientCredentials ( page , GRAFANA_CLIENT ) ;
98+ const ok = await waitForSaveTestResult ( page ) ;
99+ expect ( ok ) . toBe ( true ) ;
90100 await runQueryAndCheckResults ( page ) ;
91101} ) ;
92102
93103test ( 'test client credentials flow with wrong credentials' , async ( { page } ) => {
94104 await login ( page ) ;
95105 await goToTrinoSettings ( page ) ;
96106 await setupDataSourceWithClientCredentials ( page , "some-wrong-client" ) ;
97- // Alert is already visible (setupDataSourceWithClientCredentials waits for it).
98- // Verify it is NOT the success message.
99- await expect ( page . locator ( '[role="alert"]' ) . first ( ) ) . toBeVisible ( { timeout : 10000 } ) ;
100- await expect ( page . locator ( '[role="alert"]' ) . filter ( { hasText : 'Data source is working' } ) ) . toHaveCount ( 0 ) ;
107+ const ok = await waitForSaveTestResult ( page ) ;
108+ expect ( ok ) . toBe ( false ) ;
101109} ) ;
102110
103111test ( 'test client credentials flow with configured access token' , async ( { page } ) => {
104112 await login ( page ) ;
105113 await goToTrinoSettings ( page ) ;
106114 await page . locator ( 'div' ) . filter ( { hasText : / ^ A c c e s s t o k e n $ / } ) . locator ( 'input[type="password"]' ) . fill ( 'aaa' ) ;
107115 await setupDataSourceWithClientCredentials ( page , GRAFANA_CLIENT ) ;
108- // Alert is already visible (setupDataSourceWithClientCredentials waits for it).
109- // Verify it is NOT the success message.
110- await expect ( page . locator ( '[role="alert"]' ) . first ( ) ) . toBeVisible ( { timeout : 10000 } ) ;
111- await expect ( page . locator ( '[role="alert"]' ) . filter ( { hasText : 'Data source is working' } ) ) . toHaveCount ( 0 ) ;
116+ const ok = await waitForSaveTestResult ( page ) ;
117+ expect ( ok ) . toBe ( false ) ;
112118} ) ;
0 commit comments