test: Refactored the facet test, added more cases (#3534)

* test: Refactored the facet test, added more cases, added utility methods, #3419

* Update main/tests/cypress/cypress/integration/project/grid/column/facet/facets.spec.js

Co-authored-by: Thad Guidry <thadguidry@gmail.com>

* Update main/tests/cypress/cypress/integration/project/grid/column/facet/facets.spec.js

Co-authored-by: Thad Guidry <thadguidry@gmail.com>

* Update main/tests/cypress/cypress/integration/project/grid/column/facet/facets.spec.js

Co-authored-by: Thad Guidry <thadguidry@gmail.com>

* Removed assertion from utility method editCell

Co-authored-by: Thad Guidry <thadguidry@gmail.com>
This commit is contained in:
Florian Giroud 2021-02-02 09:07:40 +01:00 committed by GitHub
parent 3ce9292b66
commit 23be710f2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 410 additions and 168 deletions

View File

@ -1,184 +1,417 @@
/**
* Those tests are generic test to ensure the general behavior of the various facets components
* It's using "text facet" as it is the most simple facet
*/
describe(__filename, function () { describe(__filename, function () {
it('Test the facets text (no facets yet)', function () { it('Verify facets panel (left-panel) appears with no facets yet', function () {
cy.loadAndVisitProject('food.small') cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Text facet']) cy.columnActionClick('Water', ['Facet', 'Text facet'])
cy.get('#refine-tabs-facets') cy.get('#refine-tabs-facets')
.should('exist') .should('exist')
.contains('Using facets and filters') .contains('Using facets and filters')
}) })
it('Create a simple text facet', function () { it('Test the display of multiple facets', function () {
cy.loadAndVisitProject('food.small') cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Text facet']) cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
cy.get('#refine-tabs-facets').should('exist') cy.columnActionClick('Shrt_Desc', ['Facet', 'Text facet'])
cy.columnActionClick('Water', ['Facet', 'Text facet'])
// check the layout cy.getFacetContainer('NDB_No').should('exist')
cy.get( cy.getFacetContainer('Shrt_Desc').should('exist')
'#refine-tabs-facets .facets-container li:first-child span[bind="titleSpan"]' cy.getFacetContainer('Water').should('exist')
).contains('Water') })
cy.get(
'#refine-tabs-facets .facets-container li:first-child '
).contains('182 choices')
cy.get(
'#refine-tabs-facets .facets-container li:first-child '
).contains('Sort by')
cy.get(
'#refine-tabs-facets .facets-container li:first-child '
).contains('Cluster')
})
it('Create a facet, Sort by count', function () { it('Test the Remove All button', function () {
cy.loadAndVisitProject('food.small') cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Text facet']) cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
cy.get('#refine-tabs-facets').should('exist') cy.columnActionClick('Shrt_Desc', ['Facet', 'Text facet'])
cy.get('#refine-tabs-facets .facets-container .facet-container').should(
'have.length',
2
)
// Ensure sort should be by name by default cy.get('#refine-tabs-facets a').contains('Remove All').click()
cy.get( cy.get('#refine-tabs-facets .facets-container .facet-container').should(
'.facet-container .facet-body .facet-choice:first-child' 'have.length',
).contains('0.24') 0
cy.get( )
'#refine-tabs-facets .facets-container li:first-child a[bind="sortByCountLink"]' cy.get('#refine-tabs-facets')
).click() .should('exist')
// Sort should now be by count .contains('Using facets and filters')
cy.get( })
'.facet-container .facet-body .facet-choice:first-child'
).contains('15.87')
})
it('Create a facet, Sort by count, then by name', function () { it('Test the Reset All button', function () {
cy.loadAndVisitProject('food.small') cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Text facet']) cy.columnActionClick('Water', ['Facet', 'Text facet'])
cy.get('#refine-tabs-facets').should('exist') cy.columnActionClick('Energ_Kcal', ['Facet', 'Text facet'])
cy.get('#refine-tabs-facets .facets-container .facet-container').should(
'have.length',
2
)
// Sort should be by name by default // Click to facet 1, select first value
cy.get( cy.getFacetContainer('Water')
'.facet-container .facet-body .facet-choice:first-child' .find('.facet-choice:first-child .facet-choice-label')
).contains('0.24') .click()
cy.get( cy.getFacetContainer('Water')
'#refine-tabs-facets .facets-container li:first-child a[bind="sortByCountLink"]' .find('.facet-choice:first-child')
).click() .should('have.class', 'facet-choice-selected')
// Sort should now be by count
cy.get(
'.facet-container .facet-body .facet-choice:first-child'
).contains('15.87')
cy.get(
'#refine-tabs-facets .facets-container li:first-child a[bind="sortByNameLink"]'
).click()
cy.get(
'.facet-container .facet-body .facet-choice:first-child'
).contains('0.24')
})
it('Test the display of multiple facets', function () { // Click to facet 2, select first value
cy.loadAndVisitProject('food.small') cy.getFacetContainer('Energ_Kcal')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet']) .find('.facet-choice:first-child .facet-choice-label')
cy.columnActionClick('Shrt_Desc', ['Facet', 'Text facet']) .click()
cy.columnActionClick('Water', ['Facet', 'Text facet']) cy.getFacetContainer('Energ_Kcal')
.find('.facet-choice:first-child')
.should('have.class', 'facet-choice-selected')
cy.get( cy.get('#refine-tabs-facets a').contains('Reset All').click()
'#refine-tabs-facets .facets-container li:nth-child(1) span[bind="titleSpan"]'
).contains('NDB_No')
cy.get(
'#refine-tabs-facets .facets-container li:nth-child(2) span[bind="titleSpan"]'
).contains('Shrt_Desc')
cy.get(
'#refine-tabs-facets .facets-container li:nth-child(3) span[bind="titleSpan"]'
).contains('Water')
})
// it('Test collapsing facet panels', function () { // all facets selections should be gone
// The following test does not work cy.getFacetContainer('Water')
// Because the facet panels uses soem weird CSS with overflow:hidden, Cypress can not detect it .find('.facet-choice:first-child')
// //// # cy.loadAndVisitProject('food.small'); .should('not.have.class', 'facet-choice-selected')
// //// # cy.columnActionClick('NDB_No', ['Facet', 'Text facet']); cy.getFacetContainer('Energ_Kcal')
// //// # ensure facet inner panel is visible .find('.facet-choice:first-child')
// //// # cy.get('#refine-tabs-facets .facets-container li:nth-child(1) .facet-body-inner').should('be.visible'); .should('not.have.class', 'facet-choice-selected')
// //// #collapse the panel })
// //// # cy.get('#refine-tabs-facets .facets-container li:nth-child(1) a[bind="minimizeButton"]').click();
// //// # cy.get('#refine-tabs-facets .facets-container li:nth-child(1) .facet-body-inner').should('not.be.visible');
// });
it('Test editing a facet', function () { it('Create a simple text facet, check various elements in a Facet', function () {
cy.loadAndVisitProject('food.small') cy.loadAndVisitProject('food.small')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet']) cy.columnActionClick('Water', ['Facet', 'Text facet'])
cy.get( cy.get('#refine-tabs-facets').should('exist')
'#refine-tabs-facets .facets-container li:nth-child(1) a[bind="changeButton"]'
).contains('change')
cy.get(
'#refine-tabs-facets .facets-container li:nth-child(1) a[bind="changeButton"]'
).click()
cy.get('.dialog-container .dialog-header').contains(
`Edit Facet's Expression`
)
})
it('Test editing a facet / Preview', function () { cy.getFacetContainer('Water').should('exist')
cy.loadAndVisitProject('food.small') cy.getFacetContainer('Water').contains('182 choices')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet']) cy.getFacetContainer('Water').contains('Sort by')
cy.get( cy.getFacetContainer('Water').contains('Cluster')
'#refine-tabs-facets .facets-container li:nth-child(1) a[bind="changeButton"]' })
).click()
// test the tab
cy.get('.dialog-container #expression-preview-tabs-preview').should(
'be.visible'
)
// test the content
cy.get('.dialog-container #expression-preview-tabs-preview').contains(
'row'
)
})
it('Test editing a facet / History', function () { it('Delete a facet', function () {
cy.loadAndVisitProject('food.small') cy.loadAndVisitProject('food.small')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet']) cy.columnActionClick('Water', ['Facet', 'Text facet'])
cy.get(
'#refine-tabs-facets .facets-container li:nth-child(1) a[bind="changeButton"]'
).click()
cy.get('.dialog-container a[bind="or_dialog_history"]').click() cy.getFacetContainer('Water').find('a.facet-title-remove').click()
// test the tab cy.getFacetContainer('Water').should('not.exist')
cy.get('.dialog-container #expression-preview-tabs-history').should( })
'be.visible'
)
// test the content
cy.get('.dialog-container #expression-preview-tabs-history').contains(
'Reuse'
)
})
it('Test editing a facet / Starred', function () { it('Test editing a facet ("change")', function () {
cy.loadAndVisitProject('food.small') cy.loadAndVisitProject('food.small')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet']) cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
cy.get( cy.getFacetContainer('NDB_No')
'#refine-tabs-facets .facets-container li:nth-child(1) a[bind="changeButton"]' .find('a[bind="changeButton"]')
).click() .contains('change')
cy.getFacetContainer('NDB_No').find('a[bind="changeButton"]').click()
cy.get('.dialog-container .dialog-header').contains(
`Edit Facet's Expression`
)
})
cy.get('.dialog-container a[bind="or_dialog_starred"]').click() it('Test editing a facet / Preview', function () {
// test the tab cy.loadAndVisitProject('food.small')
cy.get('.dialog-container #expression-preview-tabs-starred').should( cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
'be.visible'
)
// test the content
cy.get('.dialog-container #expression-preview-tabs-starred').contains(
'Expression'
)
})
it('Test editing a facet / Help', function () { // test the tab
cy.loadAndVisitProject('food.small') cy.getFacetContainer('NDB_No').find('a[bind="changeButton"]').click()
cy.columnActionClick('NDB_No', ['Facet', 'Text facet']) cy.get('.dialog-container #expression-preview-tabs-preview').should(
cy.get( 'be.visible'
'#refine-tabs-facets .facets-container li:nth-child(1) a[bind="changeButton"]' )
).click() // test the content
cy.get('.dialog-container #expression-preview-tabs-preview').contains(
'row'
)
})
cy.get('.dialog-container a[bind="or_dialog_help"]').click() it('Test editing a facet / History', function () {
// test the tab cy.loadAndVisitProject('food.small')
cy.get('.dialog-container #expression-preview-tabs-help').should( cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
'be.visible' cy.getFacetContainer('NDB_No').find('a[bind="changeButton"]').click()
)
// test the content // test the tab
cy.get('.dialog-container #expression-preview-tabs-help').contains( cy.get('.dialog-container a[bind="or_dialog_history"]').click()
'Variables' cy.get('.dialog-container #expression-preview-tabs-history').should(
) 'be.visible'
}) )
// test the content
cy.get('.dialog-container #expression-preview-tabs-history').contains(
'Expression'
)
})
it('Test editing a facet / Starred', function () {
cy.loadAndVisitProject('food.small')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
cy.getFacetContainer('NDB_No').find('a[bind="changeButton"]').click()
// test the tab
cy.get('.dialog-container a[bind="or_dialog_starred"]').click()
cy.get('.dialog-container #expression-preview-tabs-starred').should(
'be.visible'
)
// test the content
cy.get('.dialog-container #expression-preview-tabs-starred').contains(
'Expression'
)
})
it('Test editing a facet / Help', function () {
cy.loadAndVisitProject('food.small')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
cy.getFacetContainer('NDB_No').find('a[bind="changeButton"]').click()
// test the tab
cy.get('.dialog-container a[bind="or_dialog_help"]').click()
cy.get('.dialog-container #expression-preview-tabs-help').should(
'be.visible'
)
// test the content
cy.get('.dialog-container #expression-preview-tabs-help').contains(
'Variables'
)
})
it('Create a facet, Sorts, by count', function () {
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Text facet'])
cy.get('#refine-tabs-facets').should('exist')
// Ensure sort should be by name by default
cy.getFacetContainer('Water').contains('0.24')
cy.getFacetContainer('Water').find('a[bind="sortByCountLink"]').click()
// Sort should now be by count
cy.getFacetContainer('Water').contains('15.87')
})
it('Create a facet, Sorts multiple', function () {
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Text facet'])
cy.get('#refine-tabs-facets').should('exist')
// Sort should be by name by default
cy.getFacetContainer('Water').contains('0.24')
cy.getFacetContainer('Water').find('a[bind="sortByCountLink"]').click()
// Sort should now be by count
cy.getFacetContainer('Water').contains('15.87')
cy.getFacetContainer('Water').find('a[bind="sortByNameLink"]').click()
cy.getFacetContainer('Water').contains('0.24')
})
it('Test include/exlude filters', function () {
// Because the toggle of include/exclude buttons is unstable
// we force include/exclude to be visible
// This test focus solely on ensuring that filters are effectively applied to the grid
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Shrt_Desc', ['Facet', 'Text facet'])
// force visibility
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice-toggle')
.invoke('attr', 'style', 'visibility:visible')
// include ALLSPICE,GROUND, and check rows
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice')
.contains('ALLSPICE,GROUND')
.parent()
.find('.facet-choice-toggle')
.click()
cy.getCell(0, 'Shrt_Desc').should('to.contain', 'ALLSPICE,GROUND')
cy.get('#tool-panel').contains('1 matching rows')
// OR is refreshing facets, need to show the toggle again
cy.waitForOrOperation()
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice-toggle')
.invoke('attr', 'style', 'visibility:visible')
// include CELERY SEED, and check rows
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice')
.contains('ANISE SEED')
.parent()
.find('.facet-choice-toggle')
.click()
cy.getCell(1, 'Shrt_Desc').should('to.contain', 'ANISE SEED')
cy.get('#tool-panel').contains('2 matching rows')
// OR ir refreshing facets, need to show the toggle again
cy.waitForOrOperation()
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice-toggle')
.invoke('attr', 'style', 'visibility:visible')
// include a third one, CELERY SEED, and check rows
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice')
.contains('BUTTER OIL,ANHYDROUS')
.parent()
.find('.facet-choice-toggle')
.click()
cy.getCell(0, 'Shrt_Desc').should('to.contain', 'BUTTER OIL,ANHYDROUS') // this row is added first
cy.get('#tool-panel').contains('3 matching rows')
// OR ir refreshing facets, need to show the toggle again
cy.waitForOrOperation()
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice-toggle')
.invoke('attr', 'style', 'visibility:visible')
// EXCLUDE ALLSPICE,GROUND
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice')
.contains('ALLSPICE,GROUND')
.parent()
.find('.facet-choice-toggle')
.click()
cy.get('#tool-panel').contains('2 matching rows')
})
it('Test include/exclude, invert', function () {
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Shrt_Desc', ['Facet', 'Text facet'])
// do a basic facetting, expect 1 row
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice-toggle')
.invoke('attr', 'style', 'visibility:visible')
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice')
.contains('ALLSPICE,GROUND')
.parent()
.find('.facet-choice-toggle')
.click()
cy.getCell(0, 'Shrt_Desc').should('to.contain', 'ALLSPICE,GROUND')
cy.get('#tool-panel').contains('1 matching rows')
// now invert, expect 198 rows
cy.getFacetContainer('Shrt_Desc').find('a[bind="invertButton"]').click()
cy.waitForOrOperation()
cy.get('#tool-panel').contains('198 matching rows')
cy.getFacetContainer('Shrt_Desc')
.find('a[bind="invertButton"]')
.should('have.class', 'facet-mode-inverted')
// remove invert
cy.getFacetContainer('Shrt_Desc').find('a[bind="invertButton"]').click()
cy.waitForOrOperation()
cy.get('#tool-panel').contains('1 matching rows')
})
it('Test facet reset', function () {
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Shrt_Desc', ['Facet', 'Text facet'])
// do a basic facetting, expect 1 row
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice-toggle')
.invoke('attr', 'style', 'visibility:visible')
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice')
.contains('ALLSPICE,GROUND')
.parent()
.find('.facet-choice-toggle')
.click()
cy.get('#tool-panel').contains('1 matching rows')
// now reset, expect 199
cy.getFacetContainer('Shrt_Desc')
.find('a[bind="resetButton"]')
.contains('reset')
.click()
cy.get('#tool-panel').contains('199 rows')
cy.getFacetContainer('Shrt_Desc')
.find('a[bind="resetButton"]')
.should('not.be.visible')
})
/**
* This test ensure the refresh button behavior when editing a facet
* The grid is updated with a duplicate on "BUTTER,WITH SALT"
* Then we ensure the number of occurences is respected
*/
it('Test refresh reset', function () {
cy.loadAndVisitProject('food.mini')
cy.columnActionClick('Shrt_Desc', ['Facet', 'Text facet'])
cy.get('.facet-choice').should('have.length', 2)
cy.get('.facet-choice:nth-child(1)').contains(
'BUTTER,WHIPPED,WITH SALT'
)
cy.get('.facet-choice:nth-child(2)').contains('BUTTER,WITH SALT')
cy.editCell(1, 'Shrt_Desc', 'BUTTER,WITH SALT')
cy.get('#refine-tabs-facets .browsing-panel-controls-refresh')
.contains('Refresh')
.click()
cy.get('.facet-choice').should('have.length', 1)
cy.get('.facet-choice:first-child').contains('BUTTER,WITH SALT')
cy.getFacetContainer('Shrt_Desc')
.find('.facet-choice-count')
.contains(2)
})
it('Test facet by choice count', function () {
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Shrt_Desc', ['Facet', 'Text facet'])
cy.getFacetContainer('Shrt_Desc')
.find('.facet-body-controls')
.contains('Facet by choice counts')
.click()
cy.get(`#refine-tabs-facets .facets-container .facet-container#facet-1`)
.should('exist')
.contains('Shrt_Desc')
})
it('Test the mass edit from a Facet', function () {
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Text facet'])
cy.getFacetContainer('Water').within(() => {
cy.get('.facet-choice')
.contains('15.87')
.parent()
.trigger('mouseover')
.find('a.facet-choice-edit')
.contains('edit')
.should('be.visible')
.click()
})
// mass edit all cells that have Water = 15.87
cy.get('.data-table-cell-editor textarea').type(50)
cy.get('.data-table-cell-editor button').contains('Apply').click()
// ensure rows has been modified
cy.getCell(0, 'Water').should('to.contain', 50)
cy.getCell(1, 'Water').should('to.contain', 50)
// ensure modification is made only to the rows that had 15.87, not the others
cy.getCell(2, 'Water').should('to.contain', 0.24)
})
// // This test is unstable, mouseover behavior is unpredictable
// // This might be because the element is detached from the DOM in the middle
// // it('Test include/exlude toggle', function () {
// // cy.loadAndVisitProject('food.small');
// // cy.columnActionClick('NDB_No', ['Facet', 'Text facet']);
// // cy.getFacetContainer('NDB_No').find('.facet-choice[choiceindex="0"]').trigger('mouseover');
// // cy.getFacetContainer('NDB_No').find('.facet-choice[choiceindex="0"] a.facet-choice-toggle').contains('include').should('be.visible');
// // cy.getFacetContainer('NDB_No').find('.facet-choice[choiceindex="0"] a.facet-choice-toggle').click();
// // cy.getFacetContainer('NDB_No').find('.facet-choice[choiceindex="0"] a.facet-choice-toggle').contains('exclude');
// // cy.getFacetContainer('NDB_No').find('.facet-choice[choiceindex="0"] a.facet-choice-toggle').click();
// // cy.getFacetContainer('NDB_No').find('.facet-choice[choiceindex="0"] a.facet-choice-toggle').contains('include');
// // });
// it('Test collapsing facet panels', function () {
// The following test does not work
// Because the facet panels uses soem weird CSS with overflow:hidden, Cypress can not detect it
// //// # cy.loadAndVisitProject('food.small');
// //// # cy.columnActionClick('NDB_No', ['Facet', 'Text facet']);
// //// # ensure facet inner panel is visible
// //// # cy.get('#refine-tabs-facets .facets-container li:nth-child(1) .facet-body-inner').should('be.visible');
// //// #collapse the panel
// //// # cy.get('#refine-tabs-facets .facets-container li:nth-child(1) a[bind="minimizeButton"]').click();
// ////
}) })

View File

@ -10,9 +10,18 @@
import 'cypress-file-upload' import 'cypress-file-upload'
import 'cypress-wait-until' import 'cypress-wait-until'
// const fs = require('fs-extra');
// var uniqid = require('uniqid'); /**
// * Return the .facets-container for a given facet name
*/
Cypress.Commands.add('getFacetContainer', (facetName) => {
return cy
.get(
`#refine-tabs-facets .facets-container .facet-container span[bind="titleSpan"]:contains("${facetName}")`,
{ log: false }
)
.parentsUntil('.facets-container', { log: false })
})
/** /**
* Edit a cell, for a given row index, a column name and a value * Edit a cell, for a given row index, a column name and a value