feat: add tests for sorting column (#3519)

* feat: add tests for sorting column
This commit is contained in:
Kush Trivedi 2021-02-01 18:10:40 +05:30 committed by GitHub
parent f58054b337
commit 0b748bcc37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 230 additions and 40 deletions

View File

@ -1,9 +1,11 @@
const foodMini = require('./food.mini.js')
const foodSmall = require('./food.small.js')
const foodSort = require('./food.sort.js')
const fixtures = {
'food.mini': foodMini,
'food.small': foodSmall,
'food.sort': foodSort,
}
export default fixtures

View File

@ -0,0 +1,3 @@
NDB_No,Shrt_Desc,Water,Energ_Kcal,Date,Fat
01001,"BUTTER,WITH SALT",15.87,717,17/12/2020,false
01002,"BUTTER,WHIPPED,WITH SALT",15.87,717,17/08/2020,true
1 NDB_No Shrt_Desc Water Energ_Kcal Date Fat
2 01001 BUTTER,WITH SALT 15.87 717 17/12/2020 false
3 01002 BUTTER,WHIPPED,WITH SALT 15.87 717 17/08/2020 true

View File

@ -0,0 +1,7 @@
const fixture = [
['NDB_No', 'Shrt_Desc', 'Water', 'Energ_Kcal', 'Date', 'Fat'],
['01001', 'BUTTER,WITH SALT', '15.87', '717', '17/12/2020', 'false'],
['01002', 'BUTTER,WHIPPED,WITH SALT', '15.87', '717', '17/08/2020', 'true'],
]
export default fixture

View File

@ -1,6 +1,6 @@
describe(__filename, function () {
it('Perform a basic sort', function () {
cy.loadAndVisitProject('food.mini')
it('Perform a text sort + Reverse + Remove', function () {
cy.loadAndVisitProject('food.sort')
// sort and confirm
cy.columnActionClick('Shrt_Desc', ['Sort'])
@ -13,57 +13,103 @@ describe(__filename, function () {
'BUTTER,WHIPPED,WITH SALT'
)
cy.getCell(1, 'Shrt_Desc').should('to.contain', 'BUTTER,WITH SALT')
})
it('Perform a basic sort + Reverse', function () {
cy.loadAndVisitProject('food.mini')
// sort and confirm
cy.columnActionClick('Shrt_Desc', ['Sort'])
cy.waitForDialogPanel()
cy.confirmDialogPanel()
// check the sorting
cy.getCell(0, 'Shrt_Desc').should(
'to.contain',
'BUTTER,WHIPPED,WITH SALT'
)
cy.getCell(1, 'Shrt_Desc').should('to.contain', 'BUTTER,WITH SALT')
// do a reverse sort
cy.columnActionClick('Shrt_Desc', ['Sort', 'Reverse'])
// re-check the sorting
cy.getCell(0, 'Shrt_Desc').should('to.contain', 'BUTTER,WITH SALT')
cy.getCell(1, 'Shrt_Desc').should(
'to.contain',
'BUTTER,WHIPPED,WITH SALT'
)
})
it('Perform a basic sort + Remove Sort', function () {
cy.loadAndVisitProject('food.mini')
// sort and confirm
cy.columnActionClick('Shrt_Desc', ['Sort'])
cy.waitForDialogPanel()
cy.confirmDialogPanel()
// check the sorting
cy.getCell(0, 'Shrt_Desc').should(
'to.contain',
'BUTTER,WHIPPED,WITH SALT'
)
cy.getCell(1, 'Shrt_Desc').should('to.contain', 'BUTTER,WITH SALT')
// remove
cy.columnActionClick('Shrt_Desc', ['Sort', 'Remove sort'])
// re-check the sorting
cy.getCell(0, 'Shrt_Desc').should('to.contain', 'BUTTER,WITH SALT')
cy.getCell(1, 'Shrt_Desc').should(
'to.contain',
'BUTTER,WHIPPED,WITH SALT'
)
})
it('Perform a number sort + Reverse + Remove', function () {
cy.loadAndVisitProject('food.sort')
cy.castColumnTo('NDB_No','number')
cy.columnActionClick('NDB_No', ['Sort'])
cy.waitForDialogPanel()
cy.get('[type="radio"]').check('number')
cy.get('[type="radio"]').check('reverse')
cy.confirmDialogPanel()
// ensure sorting is active
cy.getCell(0, 'NDB_No').should('to.contain', 1002)
cy.getCell(1, 'NDB_No').should('to.contain', 1001)
cy.columnActionClick('NDB_No', ['Sort', 'Reverse'])
cy.getCell(0, 'NDB_No').should('to.contain', 1001)
cy.getCell(1, 'NDB_No').should('to.contain', 1002)
cy.columnActionClick('NDB_No', ['Sort', 'Remove sort'])
cy.getCell(0, 'NDB_No').should('to.contain', 1001)
cy.getCell(1, 'NDB_No').should('to.contain', 1002)
})
it('Perform a date sort + Reverse + Remove', function () {
cy.loadAndVisitProject('food.sort')
cy.castColumnTo('Date','date')
cy.columnActionClick('Date', ['Sort'])
cy.waitForDialogPanel()
cy.get('[type="radio"]').check('date')
cy.get('[type="radio"]').check('reverse')
cy.confirmDialogPanel()
// ensure sorting is active
cy.getCell(0, 'Date').should('to.contain', '2020-12-17T00:00:00Z')
cy.getCell(1, 'Date').should('to.contain', '2020-08-17T00:00:00Z')
cy.columnActionClick('Date', ['Sort', 'Reverse'])
cy.getCell(0, 'Date').should('to.contain', '2020-08-17T00:00:00Z')
cy.getCell(1, 'Date').should('to.contain', '2020-12-17T00:00:00Z')
cy.columnActionClick('Date', ['Sort', 'Remove sort'])
cy.getCell(0, 'Date').should('to.contain', '2020-12-17T00:00:00Z')
cy.getCell(1, 'Date').should('to.contain', '2020-08-17T00:00:00Z')
})
it('Perform a bool sort + Reverse + Remove', function () {
cy.loadAndVisitProject('food.sort')
cy.getCell(0, 'Fat')
.trigger('mouseover')
.within(() => {
cy.get('a.data-table-cell-edit').click()
})
cy.get('select').select('boolean')
cy.get('button').contains(new RegExp('Apply', 'g')).click()
cy.getCell(1, 'Fat')
.trigger('mouseover')
.within(() => {
cy.get('a.data-table-cell-edit').click()
})
cy.get('select').select('boolean')
cy.get('button').contains(new RegExp('Apply', 'g')).click()
cy.columnActionClick('Fat', ['Sort'])
cy.waitForDialogPanel()
cy.get('[type="radio"]').check('boolean')
cy.confirmDialogPanel()
cy.getCell(0, 'Fat').should('to.contain', 'false')
cy.getCell(1, 'Fat').should('to.contain', 'true')
cy.columnActionClick('Fat', ['Sort', 'Reverse'])
cy.getCell(0, 'Fat').should('to.contain', 'true')
cy.getCell(1, 'Fat').should('to.contain', 'false')
cy.columnActionClick('Fat', ['Sort', 'Remove sort'])
cy.getCell(0, 'Fat').should('to.contain', 'false')
cy.getCell(1, 'Fat').should('to.contain', 'true')
})
})

View File

@ -0,0 +1,120 @@
describe(__filename, function () {
it('Ensure it reverses and reorders text sort', function () {
cy.loadAndVisitProject('food.sort')
cy.columnActionClick('Shrt_Desc', ['Sort'])
cy.waitForDialogPanel()
cy.confirmDialogPanel()
cy.getCell(0, 'Shrt_Desc').should(
'to.contain',
'BUTTER,WHIPPED,WITH SALT'
)
cy.getCell(1, 'Shrt_Desc').should('to.contain', 'BUTTER,WITH SALT')
cy.get('.viewpanel-sorting a').contains('Sort').click()
cy.get('.menu-container').contains('By Shrt_Desc').trigger('mouseover')
cy.get('.menu-item').contains('Reverse').click()
cy.getCell(0, 'Shrt_Desc').should('to.contain', 'BUTTER,WITH SALT')
cy.getCell(1, 'Shrt_Desc').should(
'to.contain',
'BUTTER,WHIPPED,WITH SALT'
)
cy.get('.viewpanel-sorting a').contains('Sort').click()
cy.get('.menu-container').contains('Reorder rows permanently').click()
cy.reload()
cy.getCell(0, 'Shrt_Desc').should('to.contain', 'BUTTER,WITH SALT')
cy.getCell(1, 'Shrt_Desc').should(
'to.contain',
'BUTTER,WHIPPED,WITH SALT'
)
})
it('Ensure it reverses and reorders number sort', function () {
cy.loadAndVisitProject('food.sort')
cy.castColumnTo('NDB_No','number')
cy.columnActionClick('NDB_No', ['Sort'])
cy.waitForDialogPanel()
cy.get('[type="radio"]').check('number')
cy.get('[type="radio"]').check('reverse')
cy.confirmDialogPanel()
cy.getCell(0, 'NDB_No').should('to.contain', 1002)
cy.getCell(1, 'NDB_No').should('to.contain', 1001)
cy.get('.viewpanel-sorting a').contains('Sort').click()
cy.get('.menu-container').contains('By NDB_No').trigger('mouseover')
cy.get('.menu-item').contains('Reverse').click()
cy.getCell(0, 'NDB_No').should('to.contain', 1001)
cy.getCell(1, 'NDB_No').should('to.contain', 1002)
cy.get('.viewpanel-sorting a').contains('Sort').click()
cy.get('.menu-container').contains('Reorder rows permanently').click()
cy.reload()
cy.getCell(0, 'NDB_No').should('to.contain', 1001)
cy.getCell(1, 'NDB_No').should('to.contain', 1002)
})
it('Ensure it reverses and reorders date sort', function () {
cy.loadAndVisitProject('food.sort')
cy.castColumnTo('Date','date')
cy.columnActionClick('Date', ['Sort'])
cy.waitForDialogPanel()
cy.get('[type="radio"]').check('date')
cy.get('[type="radio"]').check('reverse')
cy.confirmDialogPanel()
cy.getCell(0, 'Date').should('to.contain', '2020-12-17T00:00:00Z')
cy.getCell(1, 'Date').should('to.contain', '2020-08-17T00:00:00Z')
cy.get('.viewpanel-sorting a').contains('Sort').click()
cy.get('.menu-container').contains('By Date').trigger('mouseover')
cy.get('.menu-item').contains('Reverse').click()
cy.getCell(0, 'Date').should('to.contain', '2020-08-17T00:00:00Z')
cy.getCell(1, 'Date').should('to.contain', '2020-12-17T00:00:00Z')
cy.get('.viewpanel-sorting a').contains('Sort').click()
cy.get('.menu-container').contains('Reorder rows permanently').click()
cy.reload()
cy.getCell(0, 'Date').should('to.contain', '2020-08-17T00:00:00Z')
cy.getCell(1, 'Date').should('to.contain', '2020-12-17T00:00:00Z')
})
it('Ensure it reverses and reorders bool sort', function () {
cy.loadAndVisitProject('food.sort')
cy.getCell(0, 'Fat')
.trigger('mouseover')
.within(() => {
cy.get('a.data-table-cell-edit').click()
})
cy.get('select').select('boolean')
cy.get('button').contains(new RegExp('Apply', 'g')).click()
cy.getCell(1, 'Fat')
.trigger('mouseover')
.within(() => {
cy.get('a.data-table-cell-edit').click()
})
cy.get('select').select('boolean')
cy.get('button').contains(new RegExp('Apply', 'g')).click()
cy.columnActionClick('Fat', ['Sort'])
cy.waitForDialogPanel()
cy.get('[type="radio"]').check('boolean')
cy.confirmDialogPanel()
cy.getCell(0, 'Fat').should('to.contain', 'false')
cy.getCell(1, 'Fat').should('to.contain', 'true')
cy.get('.viewpanel-sorting a').contains('Sort').click()
cy.get('.menu-container').contains('By Fat').trigger('mouseover')
cy.get('.menu-item').contains('Reverse').click()
cy.getCell(0, 'Fat').should('to.contain', 'true')
cy.getCell(1, 'Fat').should('to.contain', 'false')
cy.get('.viewpanel-sorting a').contains('Sort').click()
cy.get('.menu-container').contains('Reorder rows permanently').click()
cy.reload()
cy.getCell(0, 'Fat').should('to.contain', 'true')
cy.getCell(1, 'Fat').should('to.contain', 'false')
})
})

View File

@ -57,6 +57,18 @@ Cypress.Commands.add('doCreateProjectThroughUserInterface', () => {
})
})
Cypress.Commands.add('castColumnTo', (selector, target) => {
cy.get(
'.data-table th:contains("' + selector + '") .column-header-menu'
).click()
const targetAction = 'To ' + target
cy.get('body > .menu-container').eq(0).contains('Edit cells').click()
cy.get('body > .menu-container').eq(1).contains('Common transforms').click()
cy.get('body > .menu-container').eq(2).contains(targetAction).click()
})
Cypress.Commands.add('getCell', (rowIndex, columnName) => {
const cssRowIndex = rowIndex + 1
// first get the header, to know the cell index