cypress_test/data/desktop/calc/focus.ods                  |binary
 cypress_test/integration_tests/common/calc.js             |   47 +++++++++
 cypress_test/integration_tests/common/helper.js           |   22 ++++
 cypress_test/integration_tests/desktop/calc/focus_spec.js |   71 ++++++++++++++
 cypress_test/integration_tests/mobile/calc/focus_spec.js  |   70 +++++++++++--
 5 files changed, 200 insertions(+), 10 deletions(-)

New commits:
commit b6c9b3e20db14e0cd23a333c23fe6c8adafadf9f
Author:     Ashod Nakashian <ashod.nakash...@collabora.co.uk>
AuthorDate: Sat Mar 28 14:28:05 2020 -0400
Commit:     Tamás Zolnai <tamas.zol...@collabora.com>
CommitDate: Mon Apr 27 10:53:44 2020 +0200

    cypress: Calc Formula-Bar tests
    
    New tests to exercise the Formula-Bar in
    both desktop and mobile modes.
    
    Change-Id: Ibc174232f7b614132913c1d66af0051b51151a29
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/91537
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com>

diff --git a/cypress_test/data/desktop/calc/focus.ods 
b/cypress_test/data/desktop/calc/focus.ods
new file mode 100644
index 000000000..ab2f20975
Binary files /dev/null and b/cypress_test/data/desktop/calc/focus.ods differ
diff --git a/cypress_test/integration_tests/common/calc.js 
b/cypress_test/integration_tests/common/calc.js
new file mode 100644
index 000000000..1ed2ef289
--- /dev/null
+++ b/cypress_test/integration_tests/common/calc.js
@@ -0,0 +1,47 @@
+/* global cy expect */
+
+// Click on the formula bar.
+// moveMouse is set to avoid leaving the mouse on the Formula-Bar,
+// which shows the tooltip and messes up tests.
+function clickFormulaBar(XPos = -1, moveMouse = true) {
+
+       // The inputbar_container is 100% width, which
+       // can extend behind the sidebar. So we can't
+       // rely on its width. Instead, we rely on the
+       // canvas, which is accurately sized.
+       // N.B. Setting the width of the inputbar_container
+       // is futile because it messes the size of the canvas.
+       cy.get('.inputbar_canvas')
+               .then(function(items) {
+                       expect(items).to.have.lengthOf(1);
+                       if (XPos < 0) // Click in the center if undefined.
+                               XPos = items[0].getBoundingClientRect().width / 
2;
+                       var YPos = items[0].getBoundingClientRect().height / 2;
+                       cy.get('.inputbar_container')
+                               .click(XPos, YPos);
+               });
+
+       if (moveMouse)
+               cy.get('body').trigger('mouseover');
+}
+
+// Click on the first cell.
+function clickOnFirstCell() {
+       cy.get('.leaflet-container')
+               .then(function(items) {
+                       expect(items).to.have.lengthOf(1);
+                       var XPos = items[0].getBoundingClientRect().left + 10;
+                       var YPos = items[0].getBoundingClientRect().top + 10;
+                       cy.get('body')
+                               .click(XPos, YPos);
+               });
+
+       cy.wait(500);
+
+       cy.get('.leaflet-marker-icon')
+               .should('be.visible');
+
+}
+
+module.exports.clickOnFirstCell = clickOnFirstCell;
+module.exports.clickFormulaBar = clickFormulaBar;
diff --git a/cypress_test/integration_tests/common/helper.js 
b/cypress_test/integration_tests/common/helper.js
index 6ebfcaccf..7a8c6d38c 100644
--- a/cypress_test/integration_tests/common/helper.js
+++ b/cypress_test/integration_tests/common/helper.js
@@ -43,6 +43,7 @@ function loadTestDoc(fileName, subFolder, mobile) {
                        Cypress.env('WORKDIR') + subFolder + '/' + fileName;
        }
 
+       cy.log('Loading: ' + URI);
        cy.visit(URI, {
                onLoad: function(win) {
                        win.onerror = cy.onUncaughtException;
@@ -132,6 +133,13 @@ function expectTextForClipboard(expectedPlainText) {
        }
 }
 
+function beforeAllDesktop(fileName, subFolder) {
+       var mobile = false;
+       loadTestDoc(fileName, subFolder, mobile);
+
+       // detectLOCoreVersion(); //TODO: implement Core version check.
+}
+
 function afterAll(fileName) {
        cy.log('Waiting for closing the document - start.');
        cy.log('Param - fileName: ' + fileName);
@@ -184,6 +192,18 @@ function isWriter() {
        return !isCalc() && !isImpress();
 }
 
+// Types text into elem with a delay in between characters.
+// Sometimes cy.type results in random character insertion,
+// this avoids that, which is not clear why it happens.
+function typeText(selector, text, delayMs=0) {
+       var elem= cy.get(selector);
+       for (var i = 0; i < text.length; i++) {
+               elem.type(text.charAt(i));
+               if (delayMs > 0)
+                       cy.wait(delayMs);
+       }
+}
+
 module.exports.loadTestDoc = loadTestDoc;
 module.exports.assertCursorAndFocus = assertCursorAndFocus;
 module.exports.assertNoKeyboardInput = assertNoKeyboardInput;
@@ -196,3 +216,5 @@ module.exports.initAliasToNegative = initAliasToNegative;
 module.exports.isCalc = isCalc;
 module.exports.isImpress = isImpress;
 module.exports.isWriter = isWriter;
+module.exports.beforeAllDesktop = beforeAllDesktop;
+module.exports.typeText = typeText;
diff --git a/cypress_test/integration_tests/desktop/calc/focus_spec.js 
b/cypress_test/integration_tests/desktop/calc/focus_spec.js
new file mode 100644
index 000000000..aebef57f8
--- /dev/null
+++ b/cypress_test/integration_tests/desktop/calc/focus_spec.js
@@ -0,0 +1,71 @@
+/* global describe it cy beforeEach require afterEach */
+
+var helper = require('../../common/helper');
+var calc = require('../../common/calc');
+
+var delayForEventsMs = 300; // The maximum roundrip time for an event to fire 
based on some action.
+
+describe('Calc focus tests', function() {
+       beforeEach(function() {
+               helper.beforeAllDesktop('focus.ods', 'calc');
+
+               // Wait until the Formula-Bar is loaded.
+               cy.get('.inputbar_container', {timeout : 10000});
+       });
+
+       afterEach(function() {
+               helper.afterAll('focus.ods');
+       });
+
+       it('Formula-bar focus', function() {
+
+               // Select the first cell to edit the same one.
+               // Use the tile's edge to find the first cell's position
+               calc.clickOnFirstCell();
+
+               // Click in the formula-bar.
+               calc.clickFormulaBar();
+               helper.assertCursorAndFocus();
+
+               // Type some text.
+               var text1 = 'Hello from Calc';
+               helper.typeText('textarea.clipboard', text1);
+               
cy.get('textarea.clipboard').type('{enter}').wait(delayForEventsMs);
+
+               // Select the first cell to edit the same one.
+               calc.clickOnFirstCell();
+               calc.clickFormulaBar();
+               helper.assertCursorAndFocus();
+               // Validate.
+               cy.get('textarea.clipboard').type('{ctrl}a');
+               helper.expectTextForClipboard(text1);
+               // End editing.
+               
cy.get('textarea.clipboard').type('{enter}').wait(delayForEventsMs);
+
+               // Type some more text, at the end.
+               cy.log('Appending text at the end.');
+               calc.clickOnFirstCell();
+               calc.clickFormulaBar();
+               helper.assertCursorAndFocus();
+               var text2 = ', this is a test.';
+               helper.typeText('textarea.clipboard', text2);
+               // Validate.
+               
cy.get('textarea.clipboard').type('{ctrl}a').wait(delayForEventsMs);
+               helper.expectTextForClipboard(text1 + text2);
+               // End editing.
+               
cy.get('textarea.clipboard').type('{enter}').wait(delayForEventsMs);
+
+               // Type some more text, in the middle.
+               cy.log('Inserting text in the middle.');
+               calc.clickOnFirstCell();
+               calc.clickFormulaBar();
+               helper.assertCursorAndFocus();
+               var text3 = ' BAZINGA';
+               helper.typeText('textarea.clipboard', text3);
+               // Validate.
+               
cy.get('textarea.clipboard').type('{ctrl}a').wait(delayForEventsMs);
+               //NOTE: If this fails, it's probably because we clicked
+               // at a different point in the text.
+               helper.expectTextForClipboard(text1 + ', this is a' + text3 + ' 
test.');
+       });
+});
diff --git a/cypress_test/integration_tests/mobile/calc/focus_spec.js 
b/cypress_test/integration_tests/mobile/calc/focus_spec.js
index 04c53d868..1836fb1b2 100644
--- a/cypress_test/integration_tests/mobile/calc/focus_spec.js
+++ b/cypress_test/integration_tests/mobile/calc/focus_spec.js
@@ -2,11 +2,17 @@
 
 var helper = require('../../common/helper');
 var mobileHelper = require('../../common/mobile_helper');
+var calc = require('../../common/calc');
 var calcHelper = require('./calc_helper');
 
+var delayForEventsMs = 300; // The maximum roundrip time for an event to fire 
based on some action.
+
 describe('Calc focus tests', function() {
        beforeEach(function() {
                mobileHelper.beforeAllMobile('focus.ods', 'calc');
+
+               // Wait until the Formula-Bar is loaded.
+               cy.get('.inputbar_container', {timeout : 10000});
        });
 
        afterEach(function() {
@@ -82,24 +88,68 @@ describe('Calc focus tests', function() {
 
                helper.assertNoKeyboardInput();
 
-               // One tap on a cell -> no document focus
-               calcHelper.clickOnFirstCell();
-
-               cy.get('.leaflet-marker-icon')
-                       .should('be.visible');
+               // Select the first cell to edit the same one.
+               calc.clickOnFirstCell();
 
                // No focus
                cy.document().its('activeElement.tagName')
                        .should('be.eq', 'BODY');
 
                // Click in the formula-bar.
-               cy.get('.inputbar_container')
-                       .click();
-
+               calc.clickFormulaBar();
+               cy.get('body').trigger('mouseover');
                helper.assertCursorAndFocus();
 
                // Type some text.
-               cy.get('textarea.clipboard')
-                       .type('blah');
+               var text1 = 'Hello from Calc';
+               cy.get('textarea.clipboard').type(text1);
+               
cy.get('textarea.clipboard').type('{enter}').wait(delayForEventsMs);
+
+               helper.assertNoKeyboardInput();
+
+               // Select the first cell to edit the same one.
+               calc.clickOnFirstCell();
+
+               // Check the text we typed.
+               calc.clickFormulaBar();
+               cy.get('body').trigger('mouseover');
+               helper.assertCursorAndFocus();
+               cy.get('textarea.clipboard').type('{ctrl}a');
+               helper.expectTextForClipboard(text1);
+
+               // Accept changes.
+               
cy.get('textarea.clipboard').type('{enter}').wait(delayForEventsMs);
+
+               // Type some more text, at the end.
+               cy.log('Appending text at the end.');
+               calc.clickOnFirstCell();
+               calc.clickFormulaBar();
+               cy.get('body').trigger('mouseover');
+               helper.assertCursorAndFocus();
+               var text2 = ', this is a test.';
+               cy.get('textarea.clipboard').type(text2);
+               // Validate.
+               
cy.get('textarea.clipboard').type('{ctrl}a').wait(delayForEventsMs);
+               helper.expectTextForClipboard(text1 + text2);
+               // End editing.
+               
cy.get('textarea.clipboard').type('{enter}').wait(delayForEventsMs);
+               helper.assertNoKeyboardInput();
+
+               // Type some more text, in the middle.
+               cy.log('Inserting text in the middle.');
+               calc.clickOnFirstCell();
+               calc.clickFormulaBar();
+               cy.get('body').trigger('mouseover');
+               helper.assertCursorAndFocus();
+               var text3 = ', BAZINGA';
+               helper.typeText('textarea.clipboard', text3);
+               // Validate.
+               
cy.get('textarea.clipboard').type('{ctrl}a').wait(delayForEventsMs);
+               //NOTE: If this fails, it's probably because we clicked
+               // at a different point in the text.
+               helper.expectTextForClipboard(text1 + text3 + text2);
+               // End editing.
+               
cy.get('textarea.clipboard').type('{enter}').wait(delayForEventsMs);
+               helper.assertNoKeyboardInput();
        });
 });
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to