From 87c6c7d81d3729f21bb87b48326828c6f02b1a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Zolnai?= Date: Tue, 2 Mar 2021 13:08:08 +0100 Subject: [PATCH] cypress: extract typeIntoInputField() method. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tamás Zolnai Change-Id: I8dc89dc6abad9106ffae42fc52723e503ddc0cca --- .../integration_tests/common/helper.js | 32 +++++++++++++++++++ .../desktop/calc/statusbar_spec.js | 16 +++------- .../mobile/calc/formulabar_spec.js | 32 +++---------------- .../mobile/calc/number_format_spec.js | 14 ++------ .../mobile/calc/overlays_spec.js | 28 +++------------- .../apply_paragraph_props_shape_spec.js | 14 ++------ .../apply_paragraph_props_text_spec.js | 14 ++------ .../mobile/writer/shape_properties_spec.js | 18 ++--------- .../mobile/writer/table_properties_spec.js | 16 ++-------- 9 files changed, 56 insertions(+), 128 deletions(-) diff --git a/cypress_test/integration_tests/common/helper.js b/cypress_test/integration_tests/common/helper.js index 682a4b2dd..fe92c12c2 100644 --- a/cypress_test/integration_tests/common/helper.js +++ b/cypress_test/integration_tests/common/helper.js @@ -1088,6 +1088,37 @@ function overlayItemHasDifferentBoundsThan(itemDivId, bounds) { }); } +// Type some text into an input DOM item. +// Parameters: +// selector - selector to find the correct input item in the DOM. +// text - string to type in (can contain cypress command strings). +// clearBefore - whether clear the existing content or not. +// prop - whether the value is set as property or attribute (depends on implementation). +function typeIntoInputField(selector, text, clearBefore = true, prop = true) +{ + cy.log('Typing into input field - start.'); + + if (clearBefore) { + cy.get(selector) + .focus() + .clear() + .type(text + '{enter}'); + } else { + cy.get(selector) + .type(text + '{enter}'); + } + + if (prop) { + cy.get(selector) + .should('have.prop', 'value', text); + } else { + cy.get(selector) + .should('have.attr', 'value', text); + } + + cy.log('Typing into input field - end.'); +} + module.exports.loadTestDoc = loadTestDoc; module.exports.assertCursorAndFocus = assertCursorAndFocus; module.exports.assertNoKeyboardInput = assertNoKeyboardInput; @@ -1125,3 +1156,4 @@ module.exports.Bounds = Bounds; module.exports.getOverlayItemBounds = getOverlayItemBounds; module.exports.overlayItemHasBounds = overlayItemHasBounds; module.exports.overlayItemHasDifferentBoundsThan = overlayItemHasDifferentBoundsThan; +module.exports.typeIntoInputField = typeIntoInputField; diff --git a/cypress_test/integration_tests/desktop/calc/statusbar_spec.js b/cypress_test/integration_tests/desktop/calc/statusbar_spec.js index 9f98cc2db..1fe71136d 100644 --- a/cypress_test/integration_tests/desktop/calc/statusbar_spec.js +++ b/cypress_test/integration_tests/desktop/calc/statusbar_spec.js @@ -40,16 +40,12 @@ describe('Statubar tests.', function() { cy.get('#RowColSelCount') .should('have.text', '\u00a0Select multiple cells\u00a0'); - cy.get('input#addressInput') - .clear() - .type('A1:A2{enter}'); + helper.typeIntoInputField('input#addressInput', 'A1:A2'); cy.get('#RowColSelCount') .should('have.text', 'Selected: 2 rows, 1 column'); - cy.get('input#addressInput') - .clear() - .type('A1{enter}'); + helper.typeIntoInputField('input#addressInput', 'A1'); cy.get('#RowColSelCount') .should('have.text', '\u00a0Select multiple cells\u00a0'); @@ -74,16 +70,12 @@ describe('Statubar tests.', function() { cy.get('#StateTableCell') .should('have.text', 'Average: ; Sum: 0'); - cy.get('input#addressInput') - .clear() - .type('A1:A2{enter}'); + helper.typeIntoInputField('input#addressInput', 'A1:A2'); cy.get('#StateTableCell') .should('have.text', 'Average: 15.5; Sum: 31'); - cy.get('input#addressInput') - .clear() - .type('A1{enter}'); + helper.typeIntoInputField('input#addressInput', 'A1'); cy.get('#StateTableCell') .should('have.text', 'Average: 10; Sum: 10'); diff --git a/cypress_test/integration_tests/mobile/calc/formulabar_spec.js b/cypress_test/integration_tests/mobile/calc/formulabar_spec.js index ae10aa29f..d7b1d3675 100644 --- a/cypress_test/integration_tests/mobile/calc/formulabar_spec.js +++ b/cypress_test/integration_tests/mobile/calc/formulabar_spec.js @@ -22,22 +22,12 @@ describe('Formula bar tests.', function() { calcHelper.clickOnFirstCell(); // Select a different cell using address input. - cy.get('input#addressInput') - .clear() - .type('B2{enter}'); - - cy.get('input#addressInput') - .should('have.prop', 'value', 'B2'); + helper.typeIntoInputField('input#addressInput', 'B2'); cy.get('.spreadsheet-cell-resize-marker[style=\'visibility: visible; transform: translate3d(-8px, -8px, 0px); z-index: -8;\']') .should('not.exist'); - cy.get('input#addressInput') - .clear() - .type('A1{enter}'); - - cy.get('input#addressInput') - .should('have.prop', 'value', 'A1'); + helper.typeIntoInputField('input#addressInput', 'A1'); cy.get('.spreadsheet-cell-resize-marker[style=\'visibility: visible; transform: translate3d(-8px, -8px, 0px); z-index: -8;\']') .should('exist'); @@ -48,12 +38,7 @@ describe('Formula bar tests.', function() { calcHelper.clickOnFirstCell(); // Select a cell range using address input. - cy.get('input#addressInput') - .clear() - .type('B2:B3{enter}'); - - cy.get('input#addressInput') - .should('have.prop', 'value', 'B2:B3'); + helper.typeIntoInputField('input#addressInput', 'B2:B3'); cy.get('.spreadsheet-cell-resize-marker[style=\'visibility: visible; transform: translate3d(-8px, -8px, 0px); z-index: -8;\']') .should('not.exist'); @@ -65,12 +50,7 @@ describe('Formula bar tests.', function() { .should('exist'); // Select a cell range again using address input. - cy.get('input#addressInput') - .clear() - .type('B2:B3{enter}'); - - cy.get('input#addressInput') - .should('have.prop', 'value', 'B2:B3'); + helper.typeIntoInputField('input#addressInput', 'B2:B3'); cy.get('.spreadsheet-cell-resize-marker[style=\'visibility: visible; transform: translate3d(-8px, -8px, 0px); z-index: -8;\']') .should('not.exist'); @@ -84,9 +64,7 @@ describe('Formula bar tests.', function() { helper.expectTextForClipboard('long line long line long line'); // A2 cell is empty - cy.get('input#addressInput') - .clear() - .type('A2{enter}'); + helper.typeIntoInputField('input#addressInput', 'A2'); cy.get('.spreadsheet-cell-autofill-marker') .should('be.visible'); diff --git a/cypress_test/integration_tests/mobile/calc/number_format_spec.js b/cypress_test/integration_tests/mobile/calc/number_format_spec.js index 58088242e..a3b53d878 100644 --- a/cypress_test/integration_tests/mobile/calc/number_format_spec.js +++ b/cypress_test/integration_tests/mobile/calc/number_format_spec.js @@ -326,12 +326,7 @@ describe('Apply number formatting.', function() { .should('have.attr', 'value', '0'); // Type in a new value - cy.get('#decimalplaces input') - .clear() - .type('2{enter}'); - - cy.get('#decimalplaces input') - .should('have.attr', 'value', '2'); + helper.typeIntoInputField('#decimalplaces input', '2', true, false); calcHelper.selectEntireSheet(); @@ -350,12 +345,7 @@ describe('Apply number formatting.', function() { .should('have.attr', 'value', '1'); // Type in a new value - cy.get('#leadingzeroes input') - .clear() - .type('6{enter}'); - - cy.get('#leadingzeroes input') - .should('have.attr', 'value', '6'); + helper.typeIntoInputField('#leadingzeroes input', '6', true, false); calcHelper.selectEntireSheet(); diff --git a/cypress_test/integration_tests/mobile/calc/overlays_spec.js b/cypress_test/integration_tests/mobile/calc/overlays_spec.js index 90fbdbe51..ed342a590 100644 --- a/cypress_test/integration_tests/mobile/calc/overlays_spec.js +++ b/cypress_test/integration_tests/mobile/calc/overlays_spec.js @@ -25,23 +25,13 @@ describe('Overlay bounds.', function () { var cellA1Bounds = new helper.Bounds(); helper.getOverlayItemBounds('#test-div-overlay-cell-cursor', cellA1Bounds); - cy.get('input#addressInput') - .clear() - .type('C3{enter}'); - - cy.get('input#addressInput') - .should('have.prop', 'value', 'C3'); + helper.typeIntoInputField('input#addressInput', 'C3'); var cellC3Bounds = new helper.Bounds(); helper.overlayItemHasDifferentBoundsThan('#test-div-overlay-cell-cursor', cellA1Bounds); helper.getOverlayItemBounds('#test-div-overlay-cell-cursor', cellC3Bounds); - cy.get('input#addressInput') - .clear() - .type('B2{enter}'); - - cy.get('input#addressInput') - .should('have.prop', 'value', 'B2'); + helper.typeIntoInputField('input#addressInput', 'B2'); cy.wrap(null).should(function () { cy.log('cellA1Bounds = ' + cellA1Bounds + ', cellC3Bounds = ' + cellC3Bounds); @@ -65,23 +55,13 @@ describe('Overlay bounds.', function () { var cellA1Bounds = new helper.Bounds(); helper.getOverlayItemBounds('#test-div-overlay-cell-cursor', cellA1Bounds); - cy.get('input#addressInput') - .clear() - .type('D4{enter}'); - - cy.get('input#addressInput') - .should('have.prop', 'value', 'D4'); + helper.typeIntoInputField('input#addressInput', 'D4'); var cellD4Bounds = new helper.Bounds(); helper.overlayItemHasDifferentBoundsThan('#test-div-overlay-cell-cursor', cellA1Bounds); helper.getOverlayItemBounds('#test-div-overlay-cell-cursor', cellD4Bounds); - cy.get('input#addressInput') - .clear() - .type('A1:D4{enter}'); - - cy.get('input#addressInput') - .should('have.prop', 'value', 'A1:D4'); + helper.typeIntoInputField('input#addressInput', 'A1:D4'); cy.wrap(null).should(function () { cy.log('cellA1Bounds = ' + cellA1Bounds + ', cellD4Bounds = ' + cellD4Bounds); diff --git a/cypress_test/integration_tests/mobile/impress/apply_paragraph_props_shape_spec.js b/cypress_test/integration_tests/mobile/impress/apply_paragraph_props_shape_spec.js index d5abf6f56..91f5fb45f 100644 --- a/cypress_test/integration_tests/mobile/impress/apply_paragraph_props_shape_spec.js +++ b/cypress_test/integration_tests/mobile/impress/apply_paragraph_props_shape_spec.js @@ -181,12 +181,7 @@ describe('Apply paragraph properties on selected shape.', function() { openParagraphPropertiesPanel(); - cy.get('#aboveparaspacing input') - .clear() - .type('2{enter}'); - - cy.get('#aboveparaspacing input') - .should('have.attr', 'value', '2'); + helper.typeIntoInputField('#aboveparaspacing input', '2', true, false); triggerNewSVG(); @@ -200,12 +195,7 @@ describe('Apply paragraph properties on selected shape.', function() { openParagraphPropertiesPanel(); - cy.get('#belowparaspacing input') - .clear() - .type('2{enter}'); - - cy.get('#belowparaspacing input') - .should('have.attr', 'value', '2'); + helper.typeIntoInputField('#belowparaspacing input', '2', true, false); triggerNewSVG(); diff --git a/cypress_test/integration_tests/mobile/impress/apply_paragraph_props_text_spec.js b/cypress_test/integration_tests/mobile/impress/apply_paragraph_props_text_spec.js index 4b7bdd6b4..63f9c0ead 100644 --- a/cypress_test/integration_tests/mobile/impress/apply_paragraph_props_text_spec.js +++ b/cypress_test/integration_tests/mobile/impress/apply_paragraph_props_text_spec.js @@ -203,12 +203,7 @@ describe('Apply paragraph properties on selected text.', function() { openParagraphPropertiesPanel(); - cy.get('#aboveparaspacing input') - .clear() - .type('2{enter}'); - - cy.get('#aboveparaspacing input') - .should('have.attr', 'value', '2'); + helper.typeIntoInputField('#aboveparaspacing input', '2', true, false); triggerNewSVG(); @@ -224,12 +219,7 @@ describe('Apply paragraph properties on selected text.', function() { openParagraphPropertiesPanel(); - cy.get('#belowparaspacing input') - .clear() - .type('2{enter}'); - - cy.get('#belowparaspacing input') - .should('have.attr', 'value', '2'); + helper.typeIntoInputField('#belowparaspacing input', '2', true, false); triggerNewSVG(); diff --git a/cypress_test/integration_tests/mobile/writer/shape_properties_spec.js b/cypress_test/integration_tests/mobile/writer/shape_properties_spec.js index 16897b209..f847607f7 100644 --- a/cypress_test/integration_tests/mobile/writer/shape_properties_spec.js +++ b/cypress_test/integration_tests/mobile/writer/shape_properties_spec.js @@ -88,10 +88,7 @@ describe('Change shape properties via mobile wizard.', function() { openPosSizePanel(); - cy.get('#selectwidth .spinfield') - .clear() - .type('4.2') - .type('{enter}'); + helper.typeIntoInputField('#selectwidth .spinfield', '4.2', true, false); cy.get('.leaflet-pane.leaflet-overlay-pane svg g svg g g g path') .should('not.have.attr', 'd', defaultGeometry); @@ -104,10 +101,7 @@ describe('Change shape properties via mobile wizard.', function() { openPosSizePanel(); - cy.get('#selectheight .spinfield') - .clear() - .type('5.2') - .type('{enter}'); + helper.typeIntoInputField('#selectheight .spinfield', '5.2', true, false); cy.get('.leaflet-pane.leaflet-overlay-pane svg g svg g g g path') .should('not.have.attr', 'd', defaultGeometry); @@ -229,13 +223,7 @@ describe('Change shape properties via mobile wizard.', function() { it('Change line transparency', function() { openLinePropertyPanel(); - cy.get('#linetransparency .spinfield') - .clear() - .type('20') - .type('{enter}'); - - cy.get('#linetransparency .spinfield') - .should('have.attr', 'value', '20'); + helper.typeIntoInputField('#linetransparency .spinfield', '20', true, false); triggerNewSVG(); diff --git a/cypress_test/integration_tests/mobile/writer/table_properties_spec.js b/cypress_test/integration_tests/mobile/writer/table_properties_spec.js index 9dbeb8542..6cf425d53 100644 --- a/cypress_test/integration_tests/mobile/writer/table_properties_spec.js +++ b/cypress_test/integration_tests/mobile/writer/table_properties_spec.js @@ -234,13 +234,7 @@ describe('Change table properties / layout via mobile wizard.', function() { cy.get('#rowheight .spinfield') .should('have.attr', 'value', '0'); - cy.get('#rowheight .spinfield') - .clear() - .type('1.4') - .type('{enter}'); - - cy.get('#rowheight .spinfield') - .should('have.attr', 'value', '1.4'); + helper.typeIntoInputField('#rowheight .spinfield', '1.4', true, false); selectFullTable(); @@ -254,13 +248,7 @@ describe('Change table properties / layout via mobile wizard.', function() { openTablePanel(); - cy.get('#columnwidth .spinfield') - .clear() - .type('1.6') - .type('{enter}'); - - cy.get('#columnwidth .spinfield') - .should('have.attr', 'value', '1.6'); + helper.typeIntoInputField('#columnwidth .spinfield', '1.6', true, false); selectFullTable();