Browse Source

test: filter UT for single line text

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/5029/head
Raju Udava 2 years ago
parent
commit
ab6706d76e
  1. 2
      packages/nocodb/tests/unit/factory/row.ts
  2. 99
      packages/nocodb/tests/unit/rest/tests/filter.test.ts

2
packages/nocodb/tests/unit/factory/row.ts

@ -25,8 +25,6 @@ const rowValue = (column: ColumnType, index: number) => {
}; };
const rowMixedValue = (column: ColumnType, index: number) => { const rowMixedValue = (column: ColumnType, index: number) => {
console.log(column.uidt, index);
// Array of country names // Array of country names
const countries = [ const countries = [
'Afghanistan', 'Afghanistan',

99
packages/nocodb/tests/unit/rest/tests/filter.test.ts

@ -14,6 +14,7 @@ import {
} from '../../factory/row'; } from '../../factory/row';
import Model from '../../../../src/lib/models/Model'; import Model from '../../../../src/lib/models/Model';
import { expect } from 'chai'; import { expect } from 'chai';
import request from 'supertest';
// Test case list // Test case list
@ -21,6 +22,7 @@ function filterTests() {
let context; let context;
let project: Project; let project: Project;
let table: Model; let table: Model;
let columns: any[];
let unfilteredRecords: any[] = []; let unfilteredRecords: any[] = [];
// prepare data for test cases // prepare data for test cases
@ -64,7 +66,7 @@ function filterTests() {
], ],
}); });
const columns = await table.getColumns(); columns = await table.getColumns();
let rowAttributes = []; let rowAttributes = [];
for (let i = 0; i < 400; i++) { for (let i = 0; i < 400; i++) {
@ -89,7 +91,100 @@ function filterTests() {
expect(unfilteredRecords.length).to.equal(400); expect(unfilteredRecords.length).to.equal(400);
}); });
it('Type: Single Line Text', async () => {}); async function retrieveRecordsAndValidate(
filter: {
comparison_op: string;
value: string;
fk_column_id: any;
status: string;
logical_op: string;
},
expectedRecords: any[]
) {
// retrieve filtered records
const response = await request(context.app)
.get(`/api/v1/db/data/noco/${project.id}/${table.id}`)
.set('xc-auth', context.token)
.query({
filterArrJson: JSON.stringify([filter]),
})
.expect(200);
// validate
expect(response.body.pageInfo.totalRows).to.equal(expectedRecords.length);
response.body.list.forEach((row, index) => {
expect(row[columns[1].title] !== expectedRecords[index].SingleLineText);
});
}
it('Type: Single Line Text', async () => {
// filter types to be verified
// eq, neq, null, notnull, empty, notempty, like, nlike
const filter = {
fk_column_id: columns[1].id,
status: 'create',
logical_op: 'and',
comparison_op: 'eq',
value: 'Afghanistan',
};
let expectedRecords = unfilteredRecords.filter(
(record) => record.SingleLineText === 'Afghanistan'
);
await retrieveRecordsAndValidate(filter, expectedRecords);
// filter: neq
filter.comparison_op = 'neq';
expectedRecords = unfilteredRecords.filter(
(record) => record.SingleLineText !== 'Afghanistan'
);
await retrieveRecordsAndValidate(filter, expectedRecords);
// filter: null
filter.comparison_op = 'null';
expectedRecords = unfilteredRecords.filter(
(record) => record.SingleLineText === null
);
await retrieveRecordsAndValidate(filter, expectedRecords);
// filter: notnull
filter.comparison_op = 'notnull';
expectedRecords = unfilteredRecords.filter(
(record) => record.SingleLineText !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords);
// filter: empty
filter.comparison_op = 'empty';
expectedRecords = unfilteredRecords.filter(
(record) => record.SingleLineText === ''
);
await retrieveRecordsAndValidate(filter, expectedRecords);
// filter: notempty
filter.comparison_op = 'notempty';
expectedRecords = unfilteredRecords.filter(
(record) => record.SingleLineText !== ''
);
//TBD await retrieveRecordsAndValidate(filter, expectedRecords);
// filter: like
filter.comparison_op = 'like';
filter.value = 'Au';
expectedRecords = unfilteredRecords.filter((record) =>
record.SingleLineText?.includes('Au')
);
await retrieveRecordsAndValidate(filter, expectedRecords);
// filter: nlike
filter.comparison_op = 'nlike';
filter.value = 'Au';
expectedRecords = unfilteredRecords.filter(
(record) => !record.SingleLineText?.includes('Au')
);
await retrieveRecordsAndValidate(filter, expectedRecords);
});
} }
export default function () { export default function () {

Loading…
Cancel
Save