From e22ead56a5a71d9fc17ab9057b964920e092a47f Mon Sep 17 00:00:00 2001 From: Ritesh Soni Date: Wed, 13 Oct 2021 13:31:27 +0530 Subject: [PATCH] added test for replace and transform (#4196) Added test for replace and transform --- .../grid/column/edit-cells/replace.spec.js | 146 ++++++++++++++++++ .../grid/column/edit-cells/transform.spec.js | 70 +++++++++ 2 files changed, 216 insertions(+) create mode 100644 main/tests/cypress/cypress/integration/project/grid/column/edit-cells/replace.spec.js create mode 100644 main/tests/cypress/cypress/integration/project/grid/column/edit-cells/transform.spec.js diff --git a/main/tests/cypress/cypress/integration/project/grid/column/edit-cells/replace.spec.js b/main/tests/cypress/cypress/integration/project/grid/column/edit-cells/replace.spec.js new file mode 100644 index 000000000..2b4527a53 --- /dev/null +++ b/main/tests/cypress/cypress/integration/project/grid/column/edit-cells/replace.spec.js @@ -0,0 +1,146 @@ +describe(__filename, function () { + it('Ensure cells are replaced', function () { + const fixture = [ + ['a', 'b', 'c'], + + ['0a', 'change', '0c'], + ['1a', 'Change', '1c'], + ['2a', 'Change', '2c'], + ]; + + cy.loadAndVisitProject(fixture); + + cy.columnActionClick('b', ['Edit cells', 'Replace']); + + cy.get('.dialog-container input[bind="text_to_findInput"]').type("change"); + cy.get('.dialog-container input[bind="replacement_textInput"]').type("a"); + cy.confirmDialogPanel(); + + cy.assertNotificationContainingText('Text transform on 1 cell'); + + cy.assertCellEquals(0, 'b', 'a'); + cy.assertCellEquals(1, 'b', 'Change'); + cy.assertCellEquals(2, 'b', 'Change'); + }); + it('Ensure cells are replaced case insensitively', function () { + const fixture = [ + ['a', 'b', 'c'], + + ['0a', 'change', '0c'], + ['1a', 'Change', '1c'], + ['2a', 'Change', '2c'], + ]; + + cy.loadAndVisitProject(fixture); + + cy.columnActionClick('b', ['Edit cells', 'Replace']); + + cy.get('.dialog-container input[bind="text_to_findInput"]').type("change"); + cy.get('.dialog-container input[bind="replacement_textInput"]').type("a"); + cy.get('label[bind="or_views_find_case_insensitive"]').click(); + cy.confirmDialogPanel(); + + cy.assertNotificationContainingText('Text transform on 3 cells'); + + cy.assertCellEquals(0, 'b', 'a'); + cy.assertCellEquals(1, 'b', 'a'); + cy.assertCellEquals(2, 'b', 'a'); + }); + it('Ensure cells are replaced with whole word', function () { + const fixture = [ + ['a', 'b', 'c'], + + ['0a', 'change', '0c'], + ['1a', 'change1', '1c'], + ['2a', 'change2', '2c'], + ]; + + cy.loadAndVisitProject(fixture); + + cy.columnActionClick('b', ['Edit cells', 'Replace']); + + cy.get('.dialog-container input[bind="text_to_findInput"]').type("change"); + cy.get('.dialog-container input[bind="replacement_textInput"]').type("a"); + cy.get('label[bind="or_views_find_whole_word"]').click(); + cy.confirmDialogPanel(); + + cy.assertNotificationContainingText('Text transform on 1 cells'); + + cy.assertCellEquals(0, 'b', 'a'); + cy.assertCellEquals(1, 'b', 'change1'); + cy.assertCellEquals(2, 'b', 'change2'); + }); + it('Ensure cells are replaced with regular expression', function () { + const fixture = [ + ['a', 'b', 'c'], + + ['0a', 'hat', '0c'], + ['1a', 'cat', '1c'], + ['2a', 'bat', '2c'], + ]; + + cy.loadAndVisitProject(fixture); + + cy.columnActionClick('b', ['Edit cells', 'Replace']); + + cy.get('.dialog-container input[bind="text_to_findInput"]').type("[hc]at"); + cy.get('.dialog-container input[bind="replacement_textInput"]').type("a"); + cy.get('label[bind="or_views_find_regExp"]').click(); + cy.confirmDialogPanel(); + + cy.assertNotificationContainingText('Text transform on 2 cells'); + + cy.assertCellEquals(0, 'b', 'a'); + cy.assertCellEquals(1, 'b', 'a'); + cy.assertCellEquals(2, 'b', 'bat'); + }); + it('Ensure cells are replaced with line ', function () { + const fixture = [ + ['a', 'b', 'c'], + + ['0a', 'first_name second_name', '0c'], + ['1a', 'first_name second_name', '1c'], + ['2a', 'first_name', '2c'], + ]; + + cy.loadAndVisitProject(fixture); + + cy.columnActionClick('b', ['Edit cells', 'Replace']); + + cy.get('.dialog-container input[bind="text_to_findInput"]').type(" "); + cy.get('.dialog-container input[bind="replacement_textInput"]').type("\\n"); + cy.get('label[bind="or_views_replace_dont_escape"]').click(); + cy.confirmDialogPanel(); + + cy.assertNotificationContainingText('Text transform on 2 cells'); + + cy.assertCellEquals(0, 'b', 'first_name\nsecond_name'); + cy.assertCellEquals(1, 'b', 'first_name\nsecond_name'); + cy.assertCellEquals(2, 'b', 'first_name'); + }); + it('Ensure cells are replaced with \\n', function () { + const fixture = [ + ['a', 'b', 'c'], + + ['0a', 'first_name second_name', '0c'], + ['1a', 'first_name second_name', '1c'], + ['2a', 'first_name', '2c'], + ]; + + cy.loadAndVisitProject(fixture); + + cy.columnActionClick('b', ['Edit cells', 'Replace']); + + cy.get('.dialog-container input[bind="text_to_findInput"]').type(" "); + cy.get('.dialog-container input[bind="replacement_textInput"]').type("\\\\n"); + cy.get('label[bind="or_views_replace_dont_escape"]').click(); + cy.confirmDialogPanel(); + + cy.assertNotificationContainingText('Text transform on 2 cells'); + + cy.assertCellEquals(0, 'b', 'first_name\\nsecond_name'); + cy.assertCellEquals(1, 'b', 'first_name\\nsecond_name'); + cy.assertCellEquals(2, 'b', 'first_name'); + + }); +}); \ No newline at end of file diff --git a/main/tests/cypress/cypress/integration/project/grid/column/edit-cells/transform.spec.js b/main/tests/cypress/cypress/integration/project/grid/column/edit-cells/transform.spec.js new file mode 100644 index 000000000..eb3871d5c --- /dev/null +++ b/main/tests/cypress/cypress/integration/project/grid/column/edit-cells/transform.spec.js @@ -0,0 +1,70 @@ +describe(__filename, function () { + it('Ensure cells are transformed', function () { + const fixture = [ + ['a', 'b', 'c'], + + ['0a', 'change', '0c'], + ['1a', 'change', '1c'], + ['2a', 'change', '2c'], + ]; + + cy.loadAndVisitProject(fixture); + + cy.columnActionClick('b', ['Edit cells', 'Transform']); + + cy.typeExpression('replace(value,"change","a")'); + cy.confirmDialogPanel(); + + cy.assertNotificationContainingText('Text transform on 3 cells'); + + cy.assertCellEquals(0, 'b', 'a'); + cy.assertCellEquals(1, 'b', 'a'); + cy.assertCellEquals(2, 'b', 'a'); + }); + it('Ensure cells are set to blank when error occurs', function () { + const fixture = [ + ['a', 'b', 'c'], + + ['0a', 'change', '0c'], + ['1a', 'change', '1c'], + ['2a', 'change', '2c'], + ]; + + cy.loadAndVisitProject(fixture); + + cy.columnActionClick('b', ['Edit cells', 'Transform']); + + cy.typeExpression('value.replace()');; + cy.get('label[bind="or_views_setBlank"]').click(); + cy.confirmDialogPanel(); + + cy.assertNotificationContainingText('Text transform on 3 cells'); + + cy.assertCellEquals(0, 'b', ''); + cy.assertCellEquals(1, 'b', ''); + cy.assertCellEquals(2, 'b', ''); + }); + it('Ensure cells cells contains error message when error occurs', function () { + const fixture = [ + ['a', 'b', 'c'], + + ['0a', 'change', '0c'], + ['1a', 'change', '1c'], + ['2a', 'change', '2c'], + ]; + + cy.loadAndVisitProject(fixture); + + cy.columnActionClick('b', ['Edit cells', 'Transform']); + + cy.typeExpression('value.replace()'); + cy.get('label[bind="or_views_storeErr"]').click(); + cy.confirmDialogPanel(); + + cy.assertNotificationContainingText('Text transform on 3 cells'); + + cy.assertCellEquals(0, 'b', 'replace expects 3 strings, or 1 string, 1 regex, and 1 string'); + cy.assertCellEquals(1, 'b', 'replace expects 3 strings, or 1 string, 1 regex, and 1 string'); + cy.assertCellEquals(2, 'b', 'replace expects 3 strings, or 1 string, 1 regex, and 1 string'); + }); +});