From af9aab98b4266a2011aaec156191bbe084ef2889 Mon Sep 17 00:00:00 2001
From: Raju Udava <86527202+dstala@users.noreply.github.com>
Date: Wed, 7 Jun 2023 15:15:06 +0530
Subject: [PATCH] test- temporary
Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
---
.run/test-debug.run.xml | 6 +-
tests/playwright/setup/xcdb.ts | 40 +++++++
tests/playwright/tests/db/test.spec.ts | 143 +++++++++++++++++++++++++
3 files changed, 187 insertions(+), 2 deletions(-)
create mode 100644 tests/playwright/setup/xcdb.ts
create mode 100644 tests/playwright/tests/db/test.spec.ts
diff --git a/.run/test-debug.run.xml b/.run/test-debug.run.xml
index b6cd6887cb..6e8425ddd2 100644
--- a/.run/test-debug.run.xml
+++ b/.run/test-debug.run.xml
@@ -3,10 +3,12 @@
-
+
-
+
+
+
\ No newline at end of file
diff --git a/tests/playwright/setup/xcdb.ts b/tests/playwright/setup/xcdb.ts
new file mode 100644
index 0000000000..7123e80b2c
--- /dev/null
+++ b/tests/playwright/setup/xcdb.ts
@@ -0,0 +1,40 @@
+import { Api } from 'nocodb-sdk';
+let api: Api;
+async function createXcdb(token?: string) {
+ api = new Api({
+ baseURL: `http://localhost:8080/`,
+ headers: {
+ 'xc-auth': token,
+ },
+ });
+
+ const projectList = await api.project.list();
+ for (const project of projectList.list) {
+ // delete project with title 'xcdb' if it exists
+ if (project.title === 'xcdb') {
+ await api.project.delete(project.id);
+ }
+ }
+
+ const project = await api.project.create({ title: 'xcdb' });
+ return project;
+}
+
+async function deleteXcdb(token?: string) {
+ api = new Api({
+ baseURL: `http://localhost:8080/`,
+ headers: {
+ 'xc-auth': token,
+ },
+ });
+
+ const projectList = await api.project.list();
+ for (const project of projectList.list) {
+ // delete project with title 'xcdb' if it exists
+ if (project.title === 'xcdb') {
+ await api.project.delete(project.id);
+ }
+ }
+}
+
+export { createXcdb, deleteXcdb };
diff --git a/tests/playwright/tests/db/test.spec.ts b/tests/playwright/tests/db/test.spec.ts
new file mode 100644
index 0000000000..2354e2a580
--- /dev/null
+++ b/tests/playwright/tests/db/test.spec.ts
@@ -0,0 +1,143 @@
+/*
+ *
+ * Meta projects, additional provision for deleting of rows, columns and tables with Link to another record field type
+ *
+ * Pre-requisite:
+ * TableA TableB TableC
+ * TableA TableD TableE
+ * TableA TableA : self relation
+ * TableA TableA : self relation
+ * Insert some records in TableA, TableB, TableC, TableD, TableE, add some links between them
+ *
+ *
+ * Tests:
+ * 1. Delete a row from TableA : Verify record status in adjacent tables
+ * 2. Delete hm link from TableA to TableB : Verify record status in adjacent tables
+ * 3. Delete mm link from TableA to TableD : Verify record status in adjacent tables
+ * 4. Delete a self link column from TableA : Verify
+ * 5. Delete TableA : Verify record status in adjacent tables
+ *
+ */
+
+import { test } from '@playwright/test';
+import setup from '../../setup';
+import { Api, UITypes } from 'nocodb-sdk';
+import { DashboardPage } from '../../pages/Dashboard';
+import { GridPage } from '../../pages/Dashboard/Grid';
+import { createXcdb, deleteXcdb } from '../../setup/xcdb';
+import { ProjectsPage } from '../../pages/ProjectsPage';
+import { isSqlite } from '../../setup/db';
+let api: Api;
+const recordCount = 10;
+
+test.describe.only('Test table', () => {
+ let context: any;
+ let dashboard: DashboardPage;
+ let grid: GridPage;
+ const tables = [];
+
+ test.afterEach(async () => {
+ try {
+ if (context) {
+ await deleteXcdb(context.token);
+ }
+ } catch (e) {
+ console.log(e);
+ }
+
+ // reset tables array
+ tables.length = 0;
+ });
+
+ test.beforeEach(async ({ page }) => {
+ context = await setup({ page, isEmptyProject: true });
+ dashboard = new DashboardPage(page, context.project);
+ grid = dashboard.grid;
+
+ // create a new xcdb project
+ const xcdb = await createXcdb(context.token);
+ await dashboard.clickHome();
+ const projectsPage = new ProjectsPage(dashboard.rootPage);
+ await projectsPage.openProject({ title: 'xcdb', withoutPrefix: true });
+
+ api = new Api({
+ baseURL: `http://localhost:8080/`,
+ headers: {
+ 'xc-auth': context.token,
+ },
+ });
+
+ const columns = [
+ {
+ column_name: 'Id',
+ title: 'Id',
+ uidt: UITypes.ID,
+ },
+ {
+ column_name: 'Title',
+ title: 'Title',
+ uidt: UITypes.SingleLineText,
+ pv: true,
+ },
+ ];
+
+ const rows = [];
+ for (let i = 0; i < recordCount * 10; i++) {
+ rows.push({
+ Id: i + 1,
+ Title: `${i + 1}`,
+ });
+ }
+
+ // Create tables
+ // const project = await api.project.read(xcdb.id);
+
+ for (let i = 0; i < 5; i++) {
+ const table = await api.base.tableCreate(xcdb.id, xcdb.bases?.[0].id, {
+ table_name: `Table${i}`,
+ title: `Table${i}`,
+ columns: columns,
+ });
+ tables.push(table);
+ await api.dbTableRow.bulkCreate('noco', xcdb.id, tables[i].id, rows);
+ }
+
+ // Create links
+ // TableA TableB TableC
+ await api.dbTableColumn.create(tables[0].id, {
+ uidt: UITypes.LinkToAnotherRecord,
+ title: `TableA:hm:TableB`,
+ column_name: `TableA:hm:TableB`,
+ parentId: tables[0].id,
+ childId: tables[1].id,
+ type: 'hm',
+ });
+
+ // refresh page
+ await page.reload();
+ });
+
+ test('Delete record - single, over UI', async () => {
+ if (isSqlite(context)) {
+ return;
+ }
+ });
+
+ test('Delete record - bulk, over UI', async () => {
+ if (isSqlite(context)) {
+ return;
+ }
+ });
+
+ test('Delete column', async () => {
+ if (isSqlite(context)) {
+ return;
+ }
+ });
+
+ test('Delete table', async () => {
+ if (isSqlite(context)) {
+ return;
+ }
+ });
+});