test: Added test cases for edit Cells, #3423 (#3541)

This commit is contained in:
Florian Giroud 2021-02-01 14:43:27 +01:00 committed by GitHub
parent b8982d1d6e
commit 3ce9292b66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 233 additions and 2 deletions

View File

@ -0,0 +1,28 @@
describe(__filename, function () {
it('Ensure cells are blanked down', function () {
const fixture = [
['a', 'b', 'c'],
['0a', 'identical', '0c'],
['1a', 'identical', '1c'],
['2a', '2b', '2c'],
['3a', 'also identical', '3c'],
['4a', 'also identical', '4c'],
['5a', 'also identical', '5c'],
]
cy.loadAndVisitProject(fixture)
// click
cy.columnActionClick('b', ['Edit cells', 'Blank down'])
// ensure notification and cell content
cy.assertNotificationContainingText('Blank down 3 cells')
cy.assertCellEquals(0, 'b', 'identical') // untouched
cy.assertCellEquals(1, 'b', null) // blanked
cy.assertCellEquals(2, 'b', '2b') // untouched
cy.assertCellEquals(3, 'b', 'also identical') // untouched
cy.assertCellEquals(4, 'b', null) // blanked
cy.assertCellEquals(5, 'b', null) // blanked
})
})

View File

@ -0,0 +1,23 @@
describe(__filename, function () {
it('Ensure multiple whitespaces are collapsed', function () {
const fixture = [
['NDB_No', 'Shrt_Desc'],
['01001', 'THIS IS A TEST'],
['01002', 'THIS IS ANOTHER TEST'],
['01003', 'THIS IS a THIRD TEST'],
]
cy.loadAndVisitProject(fixture)
cy.columnActionClick('Shrt_Desc', [
'Edit cells',
'Common transforms',
'Collapse consecutive whitespace',
])
// Check notification and cell content
cy.assertNotificationContainingText('Text transform on 2 cells')
cy.assertCellEquals(0, 'Shrt_Desc', 'THIS IS A TEST')
cy.assertCellEquals(1, 'Shrt_Desc', 'THIS IS ANOTHER TEST')
cy.assertCellEquals(2, 'Shrt_Desc', 'THIS IS a THIRD TEST')
})
})

View File

@ -0,0 +1,28 @@
describe(__filename, function () {
it('Ensure only some cells are converted to dates', function () {
const fixture = [
['NDB_No', 'A Date'],
['01001', '2021-01-01'],
['01002', '2021-01-01 05:35:15'],
['01003', 'THIS SHOULD NOT BE TOUCHED'],
]
cy.loadAndVisitProject(fixture)
// Update grid
cy.columnActionClick('A Date', [
'Edit cells',
'Common transforms',
'To date',
])
// Check notification and cell content
cy.assertNotificationContainingText('Text transform on 2 cells')
cy.assertCellEquals(0, 'A Date', '2021-01-01T00:00:00Z')
cy.assertCellEquals(1, 'A Date', '2021-01-01T05:35:15Z')
cy.assertCellEquals(2, 'A Date', 'THIS SHOULD NOT BE TOUCHED')
// ensure cells are marked as non-string
cy.assertCellNotString(0, 'A Date')
cy.assertCellNotString(1, 'A Date')
})
})

View File

@ -0,0 +1,52 @@
describe(__filename, function () {
it('Ensure some cells are converted to numbers, and some remains untouched (int)', function () {
const fixture = [
['NDB_No', 'A Number'],
['01001', 'This is not a number'],
['01002', '42'],
['01003', '43'],
]
cy.loadAndVisitProject(fixture)
// click
cy.columnActionClick('A Number', [
'Edit cells',
'Common transforms',
'To number',
])
// Ensure notification and cell content
cy.assertNotificationContainingText('Text transform on 2 cells')
cy.assertCellEquals(0, 'A Number', 'This is not a number')
cy.assertCellEquals(1, 'A Number', '42')
cy.assertCellEquals(2, 'A Number', '43')
// Ensure a numeric type is applied to the cell
cy.assertCellNotString(1, 'A Number')
cy.assertCellNotString(2, 'A Number')
})
it('Ensure toNumber works with floats', function () {
const fixture = [
['NDB_No', 'A Number'],
['01001', '42.2'],
['01002', '43.5'],
['01002', '43.50000'],
['01002', '43.500001'],
]
cy.loadAndVisitProject(fixture)
// click
cy.columnActionClick('A Number', [
'Edit cells',
'Common transforms',
'To number',
])
// Ensure cell content
cy.assertCellEquals(0, 'A Number', '42.2')
cy.assertCellEquals(1, 'A Number', '43.5')
cy.assertCellEquals(2, 'A Number', '43.5')
cy.assertCellEquals(3, 'A Number', '43.500001')
})
})

View File

@ -0,0 +1,21 @@
describe(__filename, function () {
it('Ensure multiple leading/tailing whitespaces are trimmed', function () {
const fixture = [
['NDB_No', 'A column'],
['01001', 'TEST'],
]
cy.loadAndVisitProject(fixture)
cy.editCell(0, 'A column', ' TEST ')
cy.columnActionClick('A column', [
'Edit cells',
'Common transforms',
'Trim leading and trailing whitespace',
])
// ensure notification and cell content
cy.assertNotificationContainingText('Text transform on 1 cells')
cy.assertCellEquals(0, 'A column', 'TEST')
})
})

View File

@ -0,0 +1,22 @@
describe(__filename, function () {
it('Ensure escaped html entities are unescaped', function () {
const fixture = [
['NDB_No', 'A column'],
['01001', '<img src="test" />'],
['01001', '&lt;img src=&quot;test&quot; /&gt;'],
]
cy.loadAndVisitProject(fixture, 'ok')
cy.columnActionClick('A column', [
'Edit cells',
'Common transforms',
'Unescape HTML entities',
])
// ensure notification and cell content
cy.assertNotificationContainingText('Text transform on 1 cells')
cy.assertCellEquals(0, 'A column', '<img src="test" />')
cy.assertCellEquals(1, 'A column', '<img src="test" />')
})
})

View File

@ -0,0 +1,27 @@
describe(__filename, function () {
it('Ensure cells are filled down', function () {
const fixture = [
['a', 'b', 'c'],
['0a', '0b', '0c'],
['1a', null, '1c'],
['2a', '2b', '2c'],
['3a', null, '3c'],
['4a', null, '4c'],
['5a', '5b', '5c'],
]
cy.loadAndVisitProject(fixture)
// click
cy.columnActionClick('b', ['Edit cells', 'Fill down'])
// ensure notification and cell content
cy.assertNotificationContainingText('Fill down 3 cells in column b')
cy.assertCellEquals(0, 'b', '0b') // untouched
cy.assertCellEquals(1, 'b', '0b') // filled
cy.assertCellEquals(2, 'b', '2b') // untouched
cy.assertCellEquals(3, 'b', '2b') // filled
cy.assertCellEquals(4, 'b', '2b') // filled
cy.assertCellEquals(5, 'b', '5b') // untouched
})
})

View File

@ -13,7 +13,19 @@ import 'cypress-wait-until'
// const fs = require('fs-extra');
// var uniqid = require('uniqid');
//
//
/**
* Edit a cell, for a given row index, a column name and a value
*/
Cypress.Commands.add('editCell', (rowIndex, columnName, value) => {
cy.getCell(rowIndex, columnName)
.trigger('mouseover')
.find('a.data-table-cell-edit')
.click()
cy.get('.menu-container.data-table-cell-editor textarea').type(value)
cy.get('.menu-container button[bind="okButton"]').click()
})
Cypress.Commands.add('assertTextareaHaveJsonValue', (selector, json) => {
cy.get(selector).then((el) => {
// expected json needs to be parsed / restringified, to avoid inconsitencies about spaces and tabs
@ -90,7 +102,12 @@ Cypress.Commands.add('assertCellEquals', (rowIndex, columnName, value) => {
cy.get(
`table.data-table tbody tr:nth-child(${cssRowIndex}) td:nth-child(${columnIndex}) div.data-table-cell-content > span`
).should(($cellSpan) => {
expect($cellSpan.text()).equals(value)
if (value == null) {
// weird, "null" is returned as a string in this case, bug in Chai ?
expect($cellSpan.text()).equals('null')
} else {
expect($cellSpan.text()).equals(value)
}
})
})
})
@ -147,3 +164,16 @@ Cypress.Commands.add(
})
}
)
Cypress.Commands.add('assertNotificationContainingText', (text) => {
cy.get('#notification').should('to.contain', text)
})
Cypress.Commands.add(
'assertCellNotString',
(rowIndex, columnName, expectedType) => {
cy.getCell(rowIndex, columnName)
.find('.data-table-value-nonstring')
.should('to.exist')
}
)