Browse Source

fix(test): Added project deletion logic which was created by a test on reset and disabled page transition in front end build for test env

pull/4278/head
Muhammed Mustafa 2 years ago
parent
commit
0a06d30c61
  1. 20
      packages/nc-gui/nuxt.config.ts
  2. 2
      packages/nc-gui/package.json
  3. 27
      packages/nocodb/src/lib/services/test/TestResetService/index.ts
  4. 3
      scripts/playwright/pages/Dashboard/index.ts
  5. 10
      scripts/playwright/pages/ProjectsPage/index.ts

20
packages/nc-gui/nuxt.config.ts

@ -14,14 +14,18 @@ export default defineNuxtConfig({
ssr: false,
app: {
pageTransition: {
name: 'page',
mode: 'out-in',
},
layoutTransition: {
name: 'layout',
mode: 'out-in',
},
pageTransition: process.env.NUXT_PAGE_TRANSITION_DISABLE
? false
: {
name: 'page',
mode: 'out-in',
},
layoutTransition: process.env.NUXT_PAGE_TRANSITION_DISABLE
? false
: {
name: 'layout',
mode: 'out-in',
},
/** In production build we need to load assets using relative path, to achieve the result we are using cdnURL */
cdnURL: process.env.NODE_ENV === 'production' ? '.' : undefined,

2
packages/nc-gui/package.json

@ -28,7 +28,7 @@
"build:copy": "npm run generate; rm -rf ../nc-lib-gui/lib/dist/; rsync -rvzh ./dist/ ../nc-lib-gui/lib/dist/",
"build:copy:publish": "npm run generate; rm -rf ../nc-lib-gui/lib/dist/; rsync -rvzh ./dist/ ../nc-lib-gui/lib/dist/; npm publish ../nc-lib-gui",
"postinstall": "node scripts/updateNuxtRouting.js",
"ci:run": "export NODE_OPTIONS=\"--max_old_space_size=16384\"; npm install; npm run build; NUXT_PUBLIC_NC_BACKEND_URL=http://localhost:8080 npm run start &"
"ci:run": "export NODE_OPTIONS=\"--max_old_space_size=16384\"; npm install; NUXT_PAGE_TRANSITION_DISABLE=true npm run build; NUXT_PUBLIC_NC_BACKEND_URL=http://localhost:8080 npm run start &"
},
"dependencies": {
"@ckpack/vue-color": "^1.2.0",

27
packages/nocodb/src/lib/services/test/TestResetService/index.ts

@ -1,12 +1,8 @@
import Noco from '../../../Noco';
import { Knex } from 'knex';
import axios from 'axios';
import Project from '../../../models/Project';
import NcConnectionMgrv2 from '../../../utils/common/NcConnectionMgrv2';
import resetMetaSakilaSqliteProject from './resetMetaSakilaSqliteProject';
import resetMysqlSakilaProject from './resetMysqlSakilaProject';
import Model from '../../../models/Model';
import resetPgSakilaProject from './resetPgSakilaProject';
import User from '../../../models/User';
import NocoCache from '../../../cache/NocoCache';
@ -29,7 +25,6 @@ const projectTitleByType = {
};
export class TestResetService {
private knex: Knex | null = null;
private readonly parallelId;
private readonly dbType;
private readonly isEmptyProject: boolean;
@ -43,7 +38,6 @@ export class TestResetService {
dbType: string;
isEmptyProject: boolean;
}) {
this.knex = Noco.ncMeta.knex;
this.parallelId = parallelId;
this.dbType = dbType;
this.isEmptyProject = isEmptyProject;
@ -54,12 +48,12 @@ export class TestResetService {
const token = await loginRootUser();
const { project } = await this.resetProject({
metaKnex: this.knex,
token,
dbType: this.dbType,
parallelId: this.parallelId,
});
await removeAllProjectCreatedByTheTest(this.parallelId);
await removeAllPrefixedUsersExceptSuper(this.parallelId);
return { token, project };
@ -70,12 +64,10 @@ export class TestResetService {
}
async resetProject({
metaKnex,
token,
dbType,
parallelId,
}: {
metaKnex: Knex;
token: string;
dbType: string;
parallelId: string;
@ -87,7 +79,7 @@ export class TestResetService {
await removeProjectUsersFromCache(project);
const bases = await project.getBases();
if (dbType == 'sqlite') await dropTablesOfProject(metaKnex, project);
await Project.delete(project.id);
if (bases.length > 0) await NcConnectionMgrv2.deleteAwait(bases[0]);
@ -124,17 +116,12 @@ export class TestResetService {
}
}
const dropTablesOfProject = async (knex: Knex, project: Project) => {
const tables = await Model.list({
project_id: project.id,
base_id: (await project.getBases())[0].id,
});
const removeAllProjectCreatedByTheTest = async (parallelId: string) => {
const projects = await Project.list({});
for (const table of tables) {
if (table.type == 'table') {
await knex.raw(`DROP TABLE IF EXISTS ${table.table_name}`);
} else {
await knex.raw(`DROP VIEW IF EXISTS ${table.table_name}`);
for (const project of projects) {
if (project.title.startsWith(`nc_test_${parallelId}_`)) {
await Project.delete(project.id);
}
}
};

3
scripts/playwright/pages/Dashboard/index.ts

@ -79,6 +79,9 @@ export class DashboardPage extends BasePage {
}
async clickHome() {
// todo: Fast page transition breaks the vue router
await this.rootPage.waitForTimeout(2000);
await this.rootPage.locator('[data-cy="nc-noco-brand-icon"]').click();
const projectsPage = new ProjectsPage(this.rootPage);
await projectsPage.waitToBeRendered();

10
scripts/playwright/pages/ProjectsPage/index.ts

@ -9,7 +9,7 @@ export class ProjectsPage extends BasePage {
prefixTitle(title: string) {
const parallelId = process.env.TEST_PARALLEL_INDEX ?? '0';
return `${title}${parallelId}`;
return `nc_test_${parallelId}_${title}`;
}
get() {
@ -31,6 +31,7 @@ export class ProjectsPage extends BasePage {
await this.rootPage.locator('.nc-new-project-menu').click();
const createProjectMenu = await this.rootPage.locator('.nc-dropdown-create-project');
if (type === 'xcdb') {
await createProjectMenu.locator(`.ant-dropdown-menu-title-content`).nth(0).click();
} else {
@ -42,7 +43,12 @@ export class ProjectsPage extends BasePage {
await this.rootPage.locator(`.nc-metadb-project-name`).waitFor();
await this.rootPage.locator(`input.nc-metadb-project-name`).fill(name);
await this.rootPage.locator(`input.nc-metadb-project-name`).press('Enter');
await this.rootPage.waitForTimeout(2000);
await this.rootPage.locator(`button:has-text("Create")`).click({
delay: 2000,
});
// fix me! wait for page to be rendered completely
await this.rootPage.waitForTimeout(2000);

Loading…
Cancel
Save