Browse Source

Merge pull request #5942 from nocodb/test/demo-table

test: add demo table as sub routine
pull/5950/head
Raju Udava 2 years ago committed by GitHub
parent
commit
f82aa588ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 207
      tests/playwright/setup/demoTable.ts
  2. 218
      tests/playwright/tests/db/filters.spec.ts

207
tests/playwright/setup/demoTable.ts

@ -0,0 +1,207 @@
import { Api, UITypes } from 'nocodb-sdk';
import { rowMixedValue } from './xcdb-records';
let api: Api<any>;
const columns = {
selectBased: [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
},
{
column_name: 'SingleSelect',
title: 'SingleSelect',
uidt: UITypes.SingleSelect,
dtxp: "'jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'",
},
{
column_name: 'MultiSelect',
title: 'MultiSelect',
uidt: UITypes.MultiSelect,
dtxp: "'jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'",
},
],
dateTimeBased: [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
},
{
column_name: 'Date',
title: 'Date',
uidt: UITypes.Date,
},
],
textBased: [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
},
{
column_name: 'SingleLineText',
title: 'SingleLineText',
uidt: UITypes.SingleLineText,
},
{
column_name: 'MultiLineText',
title: 'MultiLineText',
uidt: UITypes.LongText,
},
{
column_name: 'Email',
title: 'Email',
uidt: UITypes.Email,
},
{
column_name: 'PhoneNumber',
title: 'PhoneNumber',
uidt: UITypes.PhoneNumber,
},
{
column_name: 'URL',
title: 'URL',
uidt: UITypes.URL,
},
],
numberBased: [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
},
{
column_name: 'Number',
title: 'Number',
uidt: UITypes.Number,
},
{
column_name: 'Decimal',
title: 'Decimal',
uidt: UITypes.Decimal,
},
{
column_name: 'Currency',
title: 'Currency',
uidt: UITypes.Currency,
},
{
column_name: 'Percent',
title: 'Percent',
uidt: UITypes.Percent,
},
{
column_name: 'Duration',
title: 'Duration',
uidt: UITypes.Duration,
},
{
column_name: 'Rating',
title: 'Rating',
uidt: UITypes.Rating,
},
{
column_name: 'Year',
title: 'Year',
uidt: UITypes.Year,
},
{
column_name: 'Time',
title: 'Time',
uidt: UITypes.Time,
},
],
};
async function createDemoTable({
context: context,
recordCnt: recordCnt,
type: type,
}: {
context: any;
recordCnt: number;
type: string;
}) {
api = new Api({
baseURL: `http://localhost:8080/`,
headers: {
'xc-auth': context.token,
},
});
const project = await api.project.read(context.project.id);
const table = await api.base.tableCreate(context.project.id, project.bases?.[0].id, {
table_name: type,
title: type,
columns: columns[type],
});
if (recordCnt === 0) return table;
const rowAttributes = [];
switch (type) {
case 'selectBased':
try {
for (let i = 0; i < recordCnt; i++) {
const row = {
SingleSelect: rowMixedValue(columns.selectBased[1], i),
MultiSelect: rowMixedValue(columns.selectBased[2], i),
};
rowAttributes.push(row);
}
} catch (e) {
console.error(e);
}
break;
case 'textBased':
for (let i = 0; i < recordCnt; i++) {
const row = {
SingleLineText: rowMixedValue(columns.textBased[1], i),
MultiLineText: rowMixedValue(columns.textBased[2], i),
Email: rowMixedValue(columns.textBased[3], i),
PhoneNumber: rowMixedValue(columns.textBased[4], i),
URL: rowMixedValue(columns.textBased[5], i),
};
rowAttributes.push(row);
}
break;
case 'numberBased':
for (let i = 0; i < 400; i++) {
const row = {
Number: rowMixedValue(columns.numberBased[1], i),
Decimal: rowMixedValue(columns.numberBased[2], i),
Currency: rowMixedValue(columns.numberBased[3], i),
Percent: rowMixedValue(columns.numberBased[4], i),
Duration: rowMixedValue(columns.numberBased[5], i),
Rating: rowMixedValue(columns.numberBased[6], i),
Year: rowMixedValue(columns.numberBased[7], i),
Time: rowMixedValue(columns.numberBased[8], i, context.dbType),
};
rowAttributes.push(row);
}
break;
case 'dateTimeBased':
try {
for (let i = 0; i < recordCnt; i++) {
const row = {
Date: rowMixedValue(columns.dateTimeBased[1], i),
};
rowAttributes.push(row);
}
} catch (e) {
console.error(e);
}
break;
}
await api.dbTableRow.bulkCreate('noco', context.project.id, table.id, rowAttributes);
return table;
}
export { createDemoTable };

218
tests/playwright/tests/db/filters.spec.ts

@ -6,6 +6,7 @@ import { UITypes } from 'nocodb-sdk';
import { Api } from 'nocodb-sdk';
import { rowMixedValue } from '../../setup/xcdb-records';
import dayjs from 'dayjs';
import { createDemoTable } from '../../setup/demoTable';
let dashboard: DashboardPage, toolbar: ToolbarPage;
let context: any;
@ -227,83 +228,8 @@ test.describe('Filter Tests: Numerical', () => {
},
});
const columns = [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
},
{
column_name: 'Number',
title: 'Number',
uidt: UITypes.Number,
},
{
column_name: 'Decimal',
title: 'Decimal',
uidt: UITypes.Decimal,
},
{
column_name: 'Currency',
title: 'Currency',
uidt: UITypes.Currency,
},
{
column_name: 'Percent',
title: 'Percent',
uidt: UITypes.Percent,
},
{
column_name: 'Duration',
title: 'Duration',
uidt: UITypes.Duration,
},
{
column_name: 'Rating',
title: 'Rating',
uidt: UITypes.Rating,
},
{
column_name: 'Year',
title: 'Year',
uidt: UITypes.Year,
},
{
column_name: 'Time',
title: 'Time',
uidt: UITypes.Time,
},
];
try {
const project = await api.project.read(context.project.id);
const table = await api.base.tableCreate(context.project.id, project.bases?.[0].id, {
table_name: 'numberBased',
title: 'numberBased',
columns: columns,
});
const rowAttributes = [];
for (let i = 0; i < 400; i++) {
const row = {
Number: rowMixedValue(columns[1], i),
Decimal: rowMixedValue(columns[2], i),
Currency: rowMixedValue(columns[3], i),
Percent: rowMixedValue(columns[4], i),
Duration: rowMixedValue(columns[5], i),
Rating: rowMixedValue(columns[6], i),
Year: rowMixedValue(columns[7], i),
Time: rowMixedValue(columns[8], i, context.dbType),
};
rowAttributes.push(row);
}
await api.dbTableRow.bulkCreate('noco', context.project.id, table.id, rowAttributes);
records = await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 400 });
} catch (e) {
console.error(e);
}
const table = await createDemoTable({ context, type: 'numberBased', recordCnt: 400 });
records = await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 400 });
await page.reload();
});
@ -453,64 +379,8 @@ test.describe('Filter Tests: Text based', () => {
},
});
const columns = [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
},
{
column_name: 'SingleLineText',
title: 'SingleLineText',
uidt: UITypes.SingleLineText,
},
{
column_name: 'MultiLineText',
title: 'MultiLineText',
uidt: UITypes.LongText,
},
{
column_name: 'Email',
title: 'Email',
uidt: UITypes.Email,
},
{
column_name: 'PhoneNumber',
title: 'PhoneNumber',
uidt: UITypes.PhoneNumber,
},
{
column_name: 'URL',
title: 'URL',
uidt: UITypes.URL,
},
];
try {
const project = await api.project.read(context.project.id);
const table = await api.base.tableCreate(context.project.id, project.bases?.[0].id, {
table_name: 'textBased',
title: 'textBased',
columns: columns,
});
const rowAttributes = [];
for (let i = 0; i < 400; i++) {
const row = {
SingleLineText: rowMixedValue(columns[1], i),
MultiLineText: rowMixedValue(columns[2], i),
Email: rowMixedValue(columns[3], i),
PhoneNumber: rowMixedValue(columns[4], i),
URL: rowMixedValue(columns[5], i),
};
rowAttributes.push(row);
}
await api.dbTableRow.bulkCreate('noco', context.project.id, table.id, rowAttributes);
records = await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 400 });
} catch (e) {
console.error(e);
}
const table = await createDemoTable({ context, type: 'textBased', recordCnt: 400 });
records = await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 400 });
await page.reload();
});
@ -629,48 +499,9 @@ test.describe('Filter Tests: Select based', () => {
},
});
const columns = [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
},
{
column_name: 'SingleSelect',
title: 'SingleSelect',
uidt: UITypes.SingleSelect,
dtxp: "'jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'",
},
{
column_name: 'MultiSelect',
title: 'MultiSelect',
uidt: UITypes.MultiSelect,
dtxp: "'jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'",
},
];
try {
const project = await api.project.read(context.project.id);
const table = await api.base.tableCreate(context.project.id, project.bases?.[0].id, {
table_name: 'selectBased',
title: 'selectBased',
columns: columns,
});
const rowAttributes = [];
for (let i = 0; i < 400; i++) {
const row = {
SingleSelect: rowMixedValue(columns[1], i),
MultiSelect: rowMixedValue(columns[2], i),
};
rowAttributes.push(row);
}
const table = await createDemoTable({ context, type: 'selectBased', recordCnt: 400 });
records = await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 400 });
await api.dbTableRow.bulkCreate('noco', context.project.id, table.id, rowAttributes);
records = await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 400 });
} catch (e) {
console.error(e);
}
await page.reload();
});
@ -976,40 +807,9 @@ test.describe('Filter Tests: Date based', () => {
},
});
const columns = [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
},
{
column_name: 'Date',
title: 'Date',
uidt: UITypes.Date,
},
];
try {
const project = await api.project.read(context.project.id);
const table = await api.base.tableCreate(context.project.id, project.bases?.[0].id, {
table_name: 'dateTimeBased',
title: 'dateTimeBased',
columns: columns,
});
const table = await createDemoTable({ context, type: 'dateTimeBased', recordCnt: 800 });
records = await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 800 });
const rowAttributes = [];
for (let i = 0; i < 800; i++) {
const row = {
Date: rowMixedValue(columns[1], i),
};
rowAttributes.push(row);
}
await api.dbTableRow.bulkCreate('noco', context.project.id, table.id, rowAttributes);
records = await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 800 });
} catch (e) {
console.error(e);
}
await page.reload();
});

Loading…
Cancel
Save