Browse Source

test: playwright test corrections

pull/7569/head
Pranav C 5 months ago
parent
commit
f90cf260e5
  1. 12
      packages/nocodb/src/middlewares/global/global.middleware.ts
  2. 1
      packages/nocodb/src/types/express.d.ts
  3. 8
      tests/playwright/pages/SsoIdpPage/OpenIDLoginPage.ts
  4. 8
      tests/playwright/pages/SsoIdpPage/SAMLLoginPage.ts
  5. 5
      tests/playwright/setup/index.ts

12
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<AppConfig>) {}
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();
}
}

1
packages/nocodb/src/types/express.d.ts vendored

@ -10,5 +10,6 @@ declare module 'express-serve-static-core' {
};
ncSiteUrl: string;
clientIp: string;
dashboardUrl: string;
}
}

8
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]}")`);
}
}

8
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]}")`);
}
}

5
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({

Loading…
Cancel
Save