From 307de6ed55b038b8e5071844d1355a6cd9dbf878 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Thu, 9 Aug 2018 14:20:55 +0530 Subject: [PATCH] test(filter): Add test for the new filter feature --- cypress/integration/datatable_spec.js | 49 ++++++++++++++++++++++++++- cypress/support/commands.js | 9 +++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/cypress/integration/datatable_spec.js b/cypress/integration/datatable_spec.js index 39bda5f..c89a8d9 100644 --- a/cypress/integration/datatable_spec.js +++ b/cypress/integration/datatable_spec.js @@ -95,7 +95,7 @@ describe('DataTable', function () { }); it('mouse selection', function () { - // TODO + // TODO: // cy.getCell(2, 1) // .trigger('mousedown', { which: 1, pageX: 331, pageY: 207, force: true }) // .trigger('mousemove', { which: 1, pageX: 489, pageY: 312 }) @@ -162,4 +162,51 @@ describe('DataTable', function () { cy.get('.dt-toast').contains('1 row selected'); }); }); + + describe('Inline Filters', function () { + before(function () { + cy.visit('/'); + }); + + beforeEach(function () { + cy.get('.dt-filter[data-col-index=5]').as('filterInput5'); + }); + + afterEach(function () { + cy.get('@filterInput5').clear(); + cy.get('.dt-row[data-row-index=0]').should('be.visible'); + }); + + it('simple text filter', function () { + cy.getCell(4, 0).click().type('{ctrl}f'); + + cy.get('.dt-filter[data-col-index=4]').as('filterInput4').type('edin'); + cy.get('.dt-row[data-row-index=0]').should('be.visible'); + cy.get('.dt-row[data-row-index=1]').should('not.be.visible'); + cy.get('@filterInput4').clear(); + + cy.get('@filterInput5').type('15'); + cy.get('.dt-row[data-row-index=2]').should('be.visible'); + cy.get('.dt-row[data-row-index=15]').should('be.visible'); + cy.get('.dt-row[data-row-index=22]').should('not.be.visible'); + }); + + it('greater than', function () { + cy.get('@filterInput5').type('> 6000'); + cy.get('.dt-row[data-row-index=0]').should('not.be.visible'); + cy.get('.dt-row[data-row-index=3]').should('be.visible'); + }); + + it('less than', function () { + cy.get('@filterInput5').type('< 2000'); + cy.get('.dt-row[data-row-index=0]').should('not.be.visible'); + cy.get('.dt-row[data-row-index=51]').should('be.visible'); + }); + + it('range', function () { + cy.get('@filterInput5').type(' 2000: 5000'); + cy.get('.dt-row[data-row-index=4]').should('not.be.visible'); + cy.get('.dt-row[data-row-index=5]').should('be.visible'); + }); + }); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 0e9e15d..c6d382c 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -47,3 +47,12 @@ Cypress.Commands.add('clickDropdownItem', (col, item) => { .find(`.dt-dropdown__list-item:contains("${item}")`) .click({ force: true }); }); + +Cypress.Commands.add('typeTab', (shiftKey, ctrlKey) => { + cy.focused().trigger('keydown', { + keyCode: 9, + which: 9, + shiftKey: shiftKey, + ctrlKey: ctrlKey + }); +});