mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
273 lines
8.0 KiB
273 lines
8.0 KiB
2 years ago
|
import { test } from '@playwright/test';
|
||
|
import { DashboardPage } from '../pages/Dashboard';
|
||
|
import { SettingsPage, SettingTab } from '../pages/Dashboard/Settings';
|
||
|
import setup, { NcContext } from '../setup';
|
||
2 years ago
|
import { isMysql, isPg, isSqlite, mysqlExec, pgExec, sqliteExec } from '../setup/db';
|
||
2 years ago
|
|
||
|
// todo: Enable when view bug is fixed
|
||
2 years ago
|
test.describe('Meta sync', () => {
|
||
2 years ago
|
let dashboard: DashboardPage;
|
||
|
let settings: SettingsPage;
|
||
|
let context: NcContext;
|
||
|
let dbExec;
|
||
|
|
||
2 years ago
|
test.beforeEach(async ({ page }) => {
|
||
2 years ago
|
context = await setup({ page });
|
||
|
dashboard = new DashboardPage(page, context.project);
|
||
|
settings = dashboard.settings;
|
||
|
|
||
|
switch (context.dbType) {
|
||
2 years ago
|
case 'sqlite':
|
||
2 years ago
|
dbExec = sqliteExec;
|
||
|
break;
|
||
2 years ago
|
case 'mysql':
|
||
2 years ago
|
dbExec = mysqlExec;
|
||
|
break;
|
||
2 years ago
|
case 'pg':
|
||
|
dbExec = pgExec;
|
||
|
break;
|
||
2 years ago
|
}
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
2 years ago
|
test('Meta sync', async () => {
|
||
2 years ago
|
test.setTimeout(process.env.CI ? 100000 : 70000);
|
||
|
|
||
2 years ago
|
await dashboard.gotoSettings();
|
||
2 years ago
|
await settings.selectTab({ tab: SettingTab.ProjectMetadata });
|
||
2 years ago
|
|
||
2 years ago
|
await dbExec(`CREATE TABLE table1 (id INT NOT NULL, col1 INT NULL, PRIMARY KEY (id))`);
|
||
|
await dbExec(`CREATE TABLE table2 (id INT NOT NULL, col1 INT NULL, PRIMARY KEY (id))`);
|
||
2 years ago
|
|
||
|
await settings.metaData.clickReload();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: `table1`,
|
||
2 years ago
|
state: 'New table',
|
||
2 years ago
|
});
|
||
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 22 : 17,
|
||
2 years ago
|
model: `table2`,
|
||
2 years ago
|
state: 'New table',
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
|
await settings.metaData.sync();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: 'Table1',
|
||
|
state: 'No change identified',
|
||
2 years ago
|
});
|
||
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 22 : 17,
|
||
2 years ago
|
model: 'Table2',
|
||
|
state: 'No change identified',
|
||
2 years ago
|
});
|
||
|
|
||
|
if (!isSqlite(context)) {
|
||
2 years ago
|
// Add relation
|
||
2 years ago
|
if (isPg(context)) {
|
||
|
await dbExec(`ALTER TABLE table1 ADD CONSTRAINT fk_idx FOREIGN KEY (id) REFERENCES table2 (id);`);
|
||
|
} else {
|
||
|
await dbExec(`ALTER TABLE table1 ADD INDEX fk1_idx (col1 ASC) VISIBLE`);
|
||
|
await dbExec(
|
||
|
`ALTER TABLE table1 ADD CONSTRAINT fk1 FOREIGN KEY (col1) REFERENCES table2 (id) ON DELETE NO ACTION ON UPDATE NO ACTION`
|
||
|
);
|
||
|
}
|
||
2 years ago
|
await settings.metaData.clickReload();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: 'Table1',
|
||
|
state: 'New relation added',
|
||
2 years ago
|
});
|
||
|
|
||
2 years ago
|
//verify after sync
|
||
|
await settings.metaData.sync();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: 'Table1',
|
||
|
state: 'No change identified',
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
|
// Remove relation
|
||
2 years ago
|
if (isPg(context)) {
|
||
|
await dbExec(`ALTER TABLE table1 DROP CONSTRAINT fk_idx`);
|
||
|
} else {
|
||
|
await dbExec(`ALTER TABLE table1 DROP FOREIGN KEY fk1`);
|
||
|
await dbExec(`ALTER TABLE table1 DROP INDEX fk1_idx`);
|
||
|
}
|
||
2 years ago
|
await settings.metaData.clickReload();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: 'Table1',
|
||
|
state: 'Relation removed',
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
|
//verify after sync
|
||
|
await settings.metaData.sync();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: 'Table1',
|
||
|
state: 'No change identified',
|
||
2 years ago
|
});
|
||
2 years ago
|
}
|
||
|
|
||
|
// Add column
|
||
2 years ago
|
if (isSqlite(context)) {
|
||
|
await dbExec(`ALTER TABLE table1 ADD COLUMN newCol TEXT NULL`);
|
||
|
} else if (isMysql(context)) {
|
||
|
await dbExec(`ALTER TABLE table1 ADD COLUMN newCol VARCHAR(45) NULL AFTER id`);
|
||
|
} else if (isPg(context)) {
|
||
|
await dbExec(`ALTER TABLE table1 ADD COLUMN newCol INT`);
|
||
|
}
|
||
|
|
||
2 years ago
|
await settings.metaData.clickReload();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: `Table1`,
|
||
2 years ago
|
state: 'New column(newCol)',
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
|
//verify after sync
|
||
|
await settings.metaData.sync();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: 'Table1',
|
||
|
state: 'No change identified',
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
|
// Edit column
|
||
2 years ago
|
if (isSqlite(context)) {
|
||
|
await dbExec(`ALTER TABLE table1 RENAME COLUMN newCol TO newColName`);
|
||
|
} else if (isMysql(context)) {
|
||
|
await dbExec(`ALTER TABLE table1 CHANGE COLUMN newCol newColName VARCHAR(45) NULL DEFAULT NULL`);
|
||
|
} else if (isPg(context)) {
|
||
|
await dbExec(`ALTER TABLE table1 RENAME COLUMN newCol TO newColName`);
|
||
|
}
|
||
|
|
||
2 years ago
|
await settings.metaData.clickReload();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: `Table1`,
|
||
2 years ago
|
state: 'New column(newColName), Column removed(newCol)',
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
|
//verify after sync
|
||
|
await settings.metaData.sync();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: 'Table1',
|
||
|
state: 'No change identified',
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
|
// Delete column
|
||
|
// todo: Add for sqlite
|
||
2 years ago
|
if (!isSqlite(context)) {
|
||
2 years ago
|
await dbExec(`ALTER TABLE table1 DROP COLUMN newColName`);
|
||
2 years ago
|
await settings.metaData.clickReload();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: `Table1`,
|
||
2 years ago
|
state: 'Column removed(newColName)',
|
||
2 years ago
|
});
|
||
|
|
||
2 years ago
|
//verify after sync
|
||
|
await settings.metaData.sync();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: 'Table1',
|
||
|
state: 'No change identified',
|
||
2 years ago
|
});
|
||
2 years ago
|
}
|
||
|
|
||
|
// Delete table
|
||
2 years ago
|
await dbExec(`DROP TABLE table1`);
|
||
|
await dbExec(`DROP TABLE table2`);
|
||
2 years ago
|
await settings.metaData.clickReload();
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 21 : 16,
|
||
2 years ago
|
model: `table1`,
|
||
2 years ago
|
state: 'Table removed',
|
||
2 years ago
|
});
|
||
|
await settings.metaData.verifyRow({
|
||
2 years ago
|
index: isPg(context) ? 22 : 17,
|
||
2 years ago
|
model: `table2`,
|
||
2 years ago
|
state: 'Table removed',
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
|
//verify after sync
|
||
|
await settings.metaData.sync();
|
||
|
|
||
2 years ago
|
if (isSqlite(context)) {
|
||
|
await settings.metaData.verifyRow({
|
||
|
index: 16,
|
||
2 years ago
|
model: 'CustomerList',
|
||
|
state: 'No change identified',
|
||
2 years ago
|
});
|
||
|
await settings.metaData.verifyRow({
|
||
|
index: 17,
|
||
2 years ago
|
model: 'FilmList',
|
||
|
state: 'No change identified',
|
||
2 years ago
|
});
|
||
2 years ago
|
}
|
||
|
if (isPg(context)) {
|
||
|
await settings.metaData.verifyRow({
|
||
|
index: 21,
|
||
|
model: 'ActorInfo',
|
||
|
state: 'No change identified',
|
||
|
});
|
||
|
await settings.metaData.verifyRow({
|
||
|
index: 22,
|
||
|
model: 'CustomerList',
|
||
|
state: 'No change identified',
|
||
|
});
|
||
|
} else if (isMysql(context)) {
|
||
2 years ago
|
await settings.metaData.verifyRow({
|
||
|
index: 16,
|
||
2 years ago
|
model: 'ActorInfo',
|
||
|
state: 'No change identified',
|
||
2 years ago
|
});
|
||
|
await settings.metaData.verifyRow({
|
||
|
index: 17,
|
||
2 years ago
|
model: 'CustomerList',
|
||
|
state: 'No change identified',
|
||
2 years ago
|
});
|
||
2 years ago
|
}
|
||
|
});
|
||
|
|
||
2 years ago
|
test('Hide, filter, sort', async () => {
|
||
2 years ago
|
await dbExec(
|
||
2 years ago
|
`CREATE TABLE table1 (id INT NOT NULL, col1 INT NULL, col2 INT NULL, col3 INT NULL, col4 INT NULL, PRIMARY KEY (id))`
|
||
2 years ago
|
);
|
||
|
await dbExec(
|
||
2 years ago
|
`INSERT INTO table1 (id, col1, col2, col3, col4) VALUES (1,1,1,1,1), (2,2,2,2,2), (3,3,3,3,3), (4,4,4,4,4), (5,5,5,5,5), (6,6,6,6,6), (7,7,7,7,7), (8,8,8,8,8), (9,9,9,9,9);`
|
||
2 years ago
|
);
|
||
2 years ago
|
|
||
|
await dashboard.gotoSettings();
|
||
2 years ago
|
await settings.selectTab({ tab: SettingTab.ProjectMetadata });
|
||
2 years ago
|
|
||
|
await settings.metaData.clickReload();
|
||
|
await settings.metaData.sync();
|
||
|
await settings.close();
|
||
|
|
||
2 years ago
|
await dashboard.treeView.openTable({ title: 'Table1' });
|
||
2 years ago
|
|
||
2 years ago
|
await dashboard.grid.toolbar.clickFields();
|
||
2 years ago
|
await dashboard.grid.toolbar.fields.click({ title: 'Col1' });
|
||
2 years ago
|
await dashboard.grid.toolbar.clickFields();
|
||
2 years ago
|
|
||
2 years ago
|
await dashboard.grid.toolbar.sort.addSort({
|
||
2 years ago
|
columnTitle: 'Col1',
|
||
2 years ago
|
isAscending: false,
|
||
2 years ago
|
isLocallySaved: false,
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
2 years ago
|
await dashboard.grid.toolbar.filter.addNew({
|
||
2 years ago
|
columnTitle: 'Col1',
|
||
|
opType: '>=',
|
||
|
value: '5',
|
||
|
isLocallySaved: false,
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
2 years ago
|
await dashboard.grid.verifyRowCount({ count: 5 });
|
||
|
});
|
||
2 years ago
|
});
|