cypress_test/integration_tests/common/helper.js            |   14 ++---
 cypress_test/integration_tests/mobile/writer/focus_spec.js |   31 ++-----------
 loleaflet/src/layer/marker/TextInput.js                    |   22 +++++++--
 loleaflet/src/map/Map.js                                   |   13 -----
 4 files changed, 29 insertions(+), 51 deletions(-)

New commits:
commit ba86534c432fc8f0c48feb44b065f41f9124e398
Author:     Tamás Zolnai <tamas.zol...@collabora.com>
AuthorDate: Wed Apr 22 11:51:15 2020 +0200
Commit:     Tamás Zolnai <tamas.zol...@collabora.com>
CommitDate: Wed Apr 22 13:35:35 2020 +0200

    cypress: introduce a data attribute for acceptInput
    
    So we can use cypress calls to wait on the tested state
    using cypress' retry functionality. It's also useful to
    have the acceptInput state in the DOM, so we can check
    it in the interactive test runner.
    
    Change-Id: I17cd8f88b270f7a329d35e77dec4eedd7aa1c2a3
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92682
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com>

diff --git a/cypress_test/integration_tests/common/helper.js 
b/cypress_test/integration_tests/common/helper.js
index 4c24ea327..b31c2badd 100644
--- a/cypress_test/integration_tests/common/helper.js
+++ b/cypress_test/integration_tests/common/helper.js
@@ -1,4 +1,4 @@
-/* global cy Cypress expect*/
+/* global cy Cypress*/
 
 function loadTestDoc(fileName, subFolder, mobile) {
        cy.log('Loading test document - start.');
@@ -55,18 +55,14 @@ function loadTestDoc(fileName, subFolder, mobile) {
 
 // Assert that NO keyboard input is accepted (i.e. keyboard should be HIDDEN).
 function assertNoKeyboardInput() {
-       cy.window().then(win => {
-               var acceptInput = win.canAcceptKeyboardInput();
-               expect(acceptInput, 'Should accept input').to.equal(false);
-       });
+       cy.get('textarea.clipboard')
+               .should('have.attr', 'data-accept-input', 'false');
 }
 
 // Assert that keyboard input is accepted (i.e. keyboard should be VISIBLE).
 function assertHaveKeyboardInput() {
-       cy.window().then(win => {
-               var acceptInput = win.canAcceptKeyboardInput();
-               expect(acceptInput, 'Should accept input').to.equal(true);
-       });
+       cy.get('textarea.clipboard')
+               .should('have.attr', 'data-accept-input', 'true');
 }
 
 // Assert that we have cursor and focus.
diff --git a/cypress_test/integration_tests/mobile/writer/focus_spec.js 
b/cypress_test/integration_tests/mobile/writer/focus_spec.js
index b32262f80..602723e0b 100644
--- a/cypress_test/integration_tests/mobile/writer/focus_spec.js
+++ b/cypress_test/integration_tests/mobile/writer/focus_spec.js
@@ -175,9 +175,7 @@ describe('Focus tests', function() {
                //      .should('be.eq', 'clipboard');
 
                // This is unstable too
-               //cy.window().then(win => {
-               //      expect(win.canAcceptKeyboardInput(), 'Should accept 
input').to.equal(true);
-               //});
+               // helper.assertHaveKeyboardInput()
        });
 
        it('Focus with hamburger menu.', function() {
@@ -256,9 +254,7 @@ describe('Focus tests', function() {
                cy.get('#tb_editbar_item_bold div table')
                        .should('not.have.class', 'checked');
 
-               cy.window().then(win => {
-                       win.lastInputState = win.canAcceptKeyboardInput();
-               });
+               helper.assertHaveKeyboardInput();
 
                cy.get('#tb_editbar_item_bold')
                        .click();
@@ -266,10 +262,7 @@ describe('Focus tests', function() {
                cy.get('#tb_editbar_item_bold div table')
                        .should('have.class', 'checked');
 
-               cy.window().then(win => {
-                       var acceptInput = win.canAcceptKeyboardInput();
-                       expect(acceptInput, 'Should accept 
input').to.equal(win.lastInputState);
-               });
+               helper.assertHaveKeyboardInput();
        });
 
        it('Apply italic, check keyboard.', function() {
@@ -285,9 +278,7 @@ describe('Focus tests', function() {
                cy.get('#tb_editbar_item_italic div table')
                        .should('not.have.class', 'checked');
 
-               cy.window().then(win => {
-                       win.lastInputState = win.canAcceptKeyboardInput();
-               });
+               helper.assertHaveKeyboardInput();
 
                cy.get('#tb_editbar_item_italic')
                        .click();
@@ -295,10 +286,7 @@ describe('Focus tests', function() {
                cy.get('#tb_editbar_item_italic div table')
                        .should('have.class', 'checked');
 
-               cy.window().then(win => {
-                       var acceptInput = win.canAcceptKeyboardInput();
-                       expect(acceptInput, 'Should accept 
input').to.equal(win.lastInputState);
-               });
+               helper.assertHaveKeyboardInput();
        });
 
        it('Apply underline, check keyboard.', function() {
@@ -314,9 +302,7 @@ describe('Focus tests', function() {
                cy.get('#tb_editbar_item_underline div table')
                        .should('not.have.class', 'checked');
 
-               cy.window().then(win => {
-                       win.lastInputState = win.canAcceptKeyboardInput();
-               });
+               helper.assertHaveKeyboardInput();
 
                cy.get('#tb_editbar_item_underline')
                        .click();
@@ -324,9 +310,6 @@ describe('Focus tests', function() {
                cy.get('#tb_editbar_item_underline div table')
                        .should('have.class', 'checked');
 
-               cy.window().then(win => {
-                       var acceptInput = win.canAcceptKeyboardInput();
-                       expect(acceptInput, 'Should accept 
input').to.equal(win.lastInputState);
-               });
+               helper.assertHaveKeyboardInput();
        });
 });
diff --git a/loleaflet/src/layer/marker/TextInput.js 
b/loleaflet/src/layer/marker/TextInput.js
index 046a5d808..10c665d12 100644
--- a/loleaflet/src/layer/marker/TextInput.js
+++ b/loleaflet/src/layer/marker/TextInput.js
@@ -29,7 +29,7 @@ L.TextInput = L.Layer.extend({
 
                // If the last focus intended to accept user input.
                // Signifies whether the keyboard is meant to be visible.
-               this._acceptInput = false;
+               this._setAcceptInput(false);
 
                // Content
                this._lastContent = []; // unicode characters
@@ -162,7 +162,7 @@ L.TextInput = L.Layer.extend({
                // container in order for the user to input text (and on-screen 
keyboards
                // to pop-up), unless the document is read only.
                if (this._map._permission !== 'edit') {
-                       this._acceptInput = false;
+                       this._setAcceptInput(false);
                        return;
                }
 
@@ -174,16 +174,16 @@ L.TextInput = L.Layer.extend({
                this._textArea.focus();
 
                if ((window.ThisIsAMobileApp || window.mode.isMobile()) && 
acceptInput !== true) {
-                       this._acceptInput = false;
+                       this._setAcceptInput(false);
                        this._textArea.blur();
                        this._textArea.removeAttribute('readonly');
                } else {
-                       this._acceptInput = true;
+                       this._setAcceptInput(true);
                }
        },
 
        blur: function() {
-               this._acceptInput = false;
+               this._setAcceptInput(false);
                this._textArea.blur();
        },
 
@@ -741,6 +741,18 @@ L.TextInput = L.Layer.extend({
                var cursorPos = 
this._map._docLayer._latLngToTwips(ev.target.getLatLng());
                this._map._docLayer._postMouseEvent('buttondown', cursorPos.x, 
cursorPos.y, 1, 1, 0);
                this._map._docLayer._postMouseEvent('buttonup', cursorPos.x, 
cursorPos.y, 1, 1, 0);
+       },
+
+       _setAcceptInput: function(accept) {
+               if (L.Browser.cypressTest && this._textArea) {
+                       // This is used to track whether we *intended*
+                       // the keyboard to be visible or hidden.
+                       // There is no way track the keyboard state
+                       // programmatically, so the next best thing
+                       // is to track what we intended to do.
+                       this._textArea.setAttribute('data-accept-input', 
accept);
+               }
+               this._acceptInput = accept;
        }
 });
 
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index fafe54a87..fd6ae2397 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -310,19 +310,6 @@ L.Map = L.Evented.extend({
                                this._docLoadedOnce = this._docLoaded;
                        }
                }, this);
-
-               if (L.Browser.cypressTest) {
-                       // Expose some helpers in test mode, as
-                       // Cypress doesn't suppor them.
-                       var map = this;
-
-                       // This is used to track whether we *intended*
-                       // the keyboard to be visible or hidden.
-                       // There is no way track the keyboard state
-                       // programmatically, so the next best thing
-                       // is to track what we intended to do.
-                       window.canAcceptKeyboardInput = function() { return 
map.canAcceptKeyboardInput(); };
-               }
        },
 
        loadDocument: function(socket) {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to