From f90cf260e5ab47354eb8d43bb8ef6d2e1a0bb3f4 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 7 Feb 2024 12:26:50 +0000 Subject: [PATCH] test: playwright test corrections --- .../src/middlewares/global/global.middleware.ts | 12 ++++++++++++ packages/nocodb/src/types/express.d.ts | 1 + tests/playwright/pages/SsoIdpPage/OpenIDLoginPage.ts | 8 ++------ tests/playwright/pages/SsoIdpPage/SAMLLoginPage.ts | 8 ++------ tests/playwright/setup/index.ts | 5 ++++- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/nocodb/src/middlewares/global/global.middleware.ts b/packages/nocodb/src/middlewares/global/global.middleware.ts index 8fc3cdf7cd..c201d21121 100644 --- a/packages/nocodb/src/middlewares/global/global.middleware.ts +++ b/packages/nocodb/src/middlewares/global/global.middleware.ts @@ -1,15 +1,27 @@ import { Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import type { NestMiddleware } from '@nestjs/common'; +import type { AppConfig } from '~/interface/config'; import Noco from '~/Noco'; @Injectable() export class GlobalMiddleware implements NestMiddleware { + constructor(protected readonly config: ConfigService) {} + use(req: any, res: any, next: () => void) { req.ncSiteUrl = Noco.config?.envs?.[Noco.env]?.publicUrl || Noco.config?.publicUrl || req.protocol + '://' + req.get('host'); req.ncFullUrl = req.protocol + '://' + req.get('host') + req.originalUrl; + + const dashboardPath = this.config.get('dashboardPath', { + infer: true, + }); + + // used for playwright tests so env is not documented + req.dashboardUrl = + process.env.NC_DASHBOARD_URL || req.ncSiteUrl + dashboardPath; next(); } } diff --git a/packages/nocodb/src/types/express.d.ts b/packages/nocodb/src/types/express.d.ts index a0748427d3..5da805283a 100644 --- a/packages/nocodb/src/types/express.d.ts +++ b/packages/nocodb/src/types/express.d.ts @@ -10,5 +10,6 @@ declare module 'express-serve-static-core' { }; ncSiteUrl: string; clientIp: string; + dashboardUrl: string; } } diff --git a/tests/playwright/pages/SsoIdpPage/OpenIDLoginPage.ts b/tests/playwright/pages/SsoIdpPage/OpenIDLoginPage.ts index 540469af62..df9560d69e 100644 --- a/tests/playwright/pages/SsoIdpPage/OpenIDLoginPage.ts +++ b/tests/playwright/pages/SsoIdpPage/OpenIDLoginPage.ts @@ -33,14 +33,10 @@ export class OpenIDLoginPage extends BasePage { const authorize = this.get(); await Promise.all([ - this.rootPage.waitForNavigation({ url: /localhost:8080/ }), + this.rootPage.waitForNavigation({ url: /localhost:3000/ }), authorize.locator(`[type="submit"]`).click(), ]); - await this.rootPage.goto(`http://localhost:3000?` + this.rootPage.url().split('?')[1]); - - await this.projectsPage.waitToBeRendered(); - - console.log('111'); + await this.rootPage.locator(`[data-testid="nc-sidebar-userinfo"]:has-text("${email.split('@')[0]}")`); } } diff --git a/tests/playwright/pages/SsoIdpPage/SAMLLoginPage.ts b/tests/playwright/pages/SsoIdpPage/SAMLLoginPage.ts index 6d0192411d..710e29e61b 100644 --- a/tests/playwright/pages/SsoIdpPage/SAMLLoginPage.ts +++ b/tests/playwright/pages/SsoIdpPage/SAMLLoginPage.ts @@ -30,14 +30,10 @@ export class SAMLLoginPage extends BasePage { await signIn.locator(`#userName`).fill(email); await signIn.locator(`#email`).fill(email); await Promise.all([ - this.rootPage.waitForNavigation({ url: /localhost:8080/ }), + this.rootPage.waitForNavigation({ url: /localhost:3000/ }), signIn.locator(`#btn-sign-in`).click(), ]); - await this.rootPage.goto(`http://localhost:3000?` + this.rootPage.url().split('?')[1]); - - await this.projectsPage.waitToBeRendered(); - - console.log('111'); + await this.rootPage.locator(`[data-testid="nc-sidebar-userinfo"]:has-text("${email.split('@')[0]}")`); } } diff --git a/tests/playwright/setup/index.ts b/tests/playwright/setup/index.ts index df3221734c..b066962eee 100644 --- a/tests/playwright/setup/index.ts +++ b/tests/playwright/setup/index.ts @@ -410,9 +410,9 @@ const setup = async ({ // ignore error: some roles will not have permission for license reset // console.error(`Error resetting base: ${process.env.TEST_PARALLEL_INDEX}`, e); } - await page.addInitScript( async ({ token }) => { + if (location.search?.match(/code=|short-token=/)) return; try { let initialLocalStorage = {}; try { @@ -420,6 +420,9 @@ const setup = async ({ } catch (e) { console.error('Failed to parse local storage', e); } + + if (initialLocalStorage?.token) return; + window.localStorage.setItem( 'nocodb-gui-v2', JSON.stringify({