Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it(" combines search and filter", done => {
const take = 10,
filteredCount = 1;
let request = new GridRequest(
[
{
name: 'first_name', label: 'First Name', sortable: true, searchable: true, filter: {
name: '',
text: 'Merrick',
argument: [],
operator: CompareOperators.Equals,
hasFilter: false
}
},
{
name: 'last_name', label: 'Last Name', sortable: true, searchable: true, filter: {
name: '',
text: 'Probart',
argument: [],
operator: CompareOperators.Equals,
it(" use free text search", done => {
const take = 10,
filteredCount = 2;
let request = new GridRequest(
[
{ name: 'first_name', label: 'First Name', sortable: true, searchable: true },
{ name: 'last_name', label: 'Last Name', sortable: true, searchable: true },
{ name: 'address_id', label: 'Address Id', sortable: true, searchable: false }
],
take,
0,
'And'
);
tubular.createGridResponse(request, data)
.then(response => {
expect(response.counter).toBeDefined();
expect(response.totalRecordCount).toBe(totalRecordCount);
expect(response.filteredRecordCount).toBe(filteredCount);
expect(response.totalPages).toBe(Math.ceil(filteredCount / take));
it("skipping first 10 and taking 20", done => {
const take = 20,
filteredCount = 49;
let request = new GridRequest([
{
name: 'first_name', label: 'First Name', sortable: true, searchable: true, filter: {
name: '',
text: 'Ignacius',
argument: [],
operator: CompareOperators.NotEquals,
hasFilter: false
}
},
{ name: 'last_name', label: 'Last Name', sortable: true, searchable: true },
{ name: 'address_id', label: 'Address Id', sortable: true, searchable: false }
],
take,
0);
tubular.createGridResponse(request, data)
it(" use free text search", done => {
const take = 10,
filteredCount = 31;
let queryBuilder = knex.select('first_name', 'last_name', 'address_id').from('customer');
let request = new GridRequest(
[
{ name: 'first_name', label: 'First Name', sortable: true, searchable: true },
{ name: 'last_name', label: 'Last Name', sortable: true, searchable: true },
{ name: 'address_id', label: 'Address Id', sortable: true, searchable: false }
],
take,
0,
'And',
);
tubular.createGridResponse(request, queryBuilder)
.then(response => {
expect(response.counter).toBeDefined();
expect(response.totalRecordCount).toBe(totalRecordCount);
expect(response.filteredRecordCount).toBe(filteredCount);
expect(response.totalPages).toBe(Math.ceil(filteredCount / take));
it(" filters by one column", done => {
const take = 10,
filteredCount = 1;
let queryBuilder = knex.select('first_name', 'last_name', 'address_id').from('customer');
let request = new GridRequest(
[
{
name: 'first_name', label: 'First Name', sortable: true, searchable: true, filter: {
name: '',
text: 'JOY',
argument: [],
operator: CompareOperators.Contains,
hasFilter: false
}
},
{ name: 'last_name', label: 'Last Name', sortable: true, searchable: true },
{ name: 'address_id', label: 'Address Id', sortable: true, searchable: false }
],
take,
0,
'GEO'
it("filters using Gt", done => {
const take = 10,
filteredCount = 1;
let request = new GridRequest(
[
{ name: 'first_name', label: 'First Name', sortable: true, searchable: true },
{ name: 'last_name', label: 'Last Name', sortable: true, searchable: true },
{
name: 'address_id', label: 'Address Id', sortable: true, searchable: false, filter: {
name: '',
text: 49,
argument: [],
operator: CompareOperators.Gt,
hasFilter: false
}
}
],
take,
0,
);
it("skipping first 10 and taking 20", done => {
const take = 20,
filteredCount = 598;
let queryBuilder = knex.select('first_name', 'last_name', 'address_id').from('customer');
let request = new GridRequest(
[
{
name: 'first_name', label: 'First Name', sortable: true, searchable: true, filter: {
name: '',
text: 'Patricia',
argument: [],
operator: CompareOperators.NotEquals,
hasFilter: false
}
},
{ name: 'last_name', label: 'Last Name', sortable: true, searchable: true },
{ name: 'address_id', label: 'Address Id', sortable: true, searchable: false }
],
take,
0,
);
it(" filters by one column", done => {
const take = 10,
filteredCount = 1;
let request = new GridRequest(
[
{
name: 'first_name', label: 'First Name', sortable: true, searchable: true, filter: {
name: '',
text: 'ucy',
argument: [],
operator: CompareOperators.Contains,
hasFilter: false
}
},
{ name: 'last_name', label: 'Last Name', sortable: true, searchable: true },
{ name: 'address_id', label: 'Address Id', sortable: true, searchable: false }
],
take,
0,
'GEO'
it(" combines search and filter", done => {
const take = 10,
filteredCount = 1;
let queryBuilder = knex.select('first_name', 'last_name', 'address_id').from('customer');
let request = new GridRequest(
[
{
name: 'first_name', label: 'First Name', sortable: true, searchable: true, filter: {
name: '',
text: 'ANDREW',
argument: [],
operator: CompareOperators.Equals,
hasFilter: false
}
},
{
name: 'last_name', label: 'Last Name', sortable: true, searchable: true, filter: {
name: '',
text: 'PURDY',
argument: [],
operator: CompareOperators.Equals,
exportTo: async (allRows: boolean, exportFunc: (payload: any[], columns: ColumnModel[]) => void) => {
if (getState.filteredRecordCount === 0) {
return;
}
let payload: any[] = getState.data;
if (allRows) {
const { Payload } =
await getAllRecords(new GridRequest(getColumns, -1, 0, getSearchText));
payload = Payload;
}
exportFunc(payload, getColumns);
},
goToPage: (page: number) => {