cypress_test/integration_tests/common/helper.js            |   10 ++---
 cypress_test/integration_tests/mobile/writer/focus_spec.js |   12 +++---
 loleaflet/src/map/Map.js                                   |   25 ++++++++++---
 3 files changed, 30 insertions(+), 17 deletions(-)

New commits:
commit 0b7f70786c1057b9cbe71a7167b82e2d35a447b3
Author:     Ashod Nakashian <ashod.nakash...@collabora.co.uk>
AuthorDate: Sat Mar 21 10:12:09 2020 -0400
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Wed Mar 25 12:28:09 2020 +0100

    leaflet: do not expose map to cypress tests
    
    We only need to expose a couple of helpers
    to test the keyboard and clipboard, which
    are not possible to test via the UI.
    
    This patch reduces the surface area of
    exposed code to testing, to avoid misuse.
    The only needed helpers should be made
    available, and they are read-only functions,
    so there is no risk of changing the internal
    state from test code.
    
    Change-Id: Id4a1800e3d3b9364754a18fb11f61df612e56490
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90991
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/cypress_test/integration_tests/common/helper.js 
b/cypress_test/integration_tests/common/helper.js
index 71ab8a92c..67b033ff8 100644
--- a/cypress_test/integration_tests/common/helper.js
+++ b/cypress_test/integration_tests/common/helper.js
@@ -63,7 +63,7 @@ function enableEditingMobile() {
 // Assert that NO keyboard input is accepted (i.e. keyboard should be HIDDEN).
 function assertNoKeyboardInput() {
        cy.window().then(win => {
-               var acceptInput = win.map._textInput.shouldAcceptInput();
+               var acceptInput = win.shouldAcceptInput();
                expect(acceptInput, 'Should accept input').to.equal(false);
        });
 }
@@ -71,7 +71,7 @@ function assertNoKeyboardInput() {
 // Assert that keyboard input is accepted (i.e. keyboard should be VISIBLE).
 function assertHaveKeyboardInput() {
        cy.window().then(win => {
-               var acceptInput = win.map._textInput.shouldAcceptInput();
+               var acceptInput = win.shouldAcceptInput();
                expect(acceptInput, 'Should accept input').to.equal(true);
        });
 }
@@ -127,16 +127,14 @@ function clearAllText() {
 // });
 function getTextForClipboard(f) {
        cy.window().then(win => {
-               var htmlText = win.map._clip._getHtmlForClipboard();
-               var plainText = win.map._clip.stripHTML(htmlText);
-               f(htmlText, plainText);
+               f(win.getTextForClipboard());
        });
 }
 
 // Expects getTextForClipboard return the given
 // plain-text, and asserts equality.
 function expectTextForClipboard(expectedPlainText) {
-       getTextForClipboard((htmlText, plainText) => {
+       getTextForClipboard((plainText) => {
                expect(plainText, 'Selection Text').to.equal(expectedPlainText);
        });
 }
diff --git a/cypress_test/integration_tests/mobile/writer/focus_spec.js 
b/cypress_test/integration_tests/mobile/writer/focus_spec.js
index 14c0e65db..8193b3bfe 100644
--- a/cypress_test/integration_tests/mobile/writer/focus_spec.js
+++ b/cypress_test/integration_tests/mobile/writer/focus_spec.js
@@ -287,7 +287,7 @@ describe('Focus tests', function() {
                        .should('not.have.class', 'checked');
 
                cy.window().then(win => {
-                       win.lastInputState = 
win.map._textInput.shouldAcceptInput();
+                       win.lastInputState = win.shouldAcceptInput();
                });
 
                cy.get('#tb_editbar_item_bold')
@@ -297,7 +297,7 @@ describe('Focus tests', function() {
                        .should('have.class', 'checked');
 
                cy.window().then(win => {
-                       var acceptInput = 
win.map._textInput.shouldAcceptInput();
+                       var acceptInput = win.shouldAcceptInput();
                        expect(acceptInput, 'Should accept 
input').to.equal(win.lastInputState);
                });
        });
@@ -316,7 +316,7 @@ describe('Focus tests', function() {
                        .should('not.have.class', 'checked');
 
                cy.window().then(win => {
-                       win.lastInputState = 
win.map._textInput.shouldAcceptInput();
+                       win.lastInputState = win.shouldAcceptInput();
                });
 
                cy.get('#tb_editbar_item_italic')
@@ -326,7 +326,7 @@ describe('Focus tests', function() {
                        .should('have.class', 'checked');
 
                cy.window().then(win => {
-                       var acceptInput = 
win.map._textInput.shouldAcceptInput();
+                       var acceptInput = win.shouldAcceptInput();
                        expect(acceptInput, 'Should accept 
input').to.equal(win.lastInputState);
                });
        });
@@ -345,7 +345,7 @@ describe('Focus tests', function() {
                        .should('not.have.class', 'checked');
 
                cy.window().then(win => {
-                       win.lastInputState = 
win.map._textInput.shouldAcceptInput();
+                       win.lastInputState = win.shouldAcceptInput();
                });
 
                cy.get('#tb_editbar_item_underline')
@@ -355,7 +355,7 @@ describe('Focus tests', function() {
                        .should('have.class', 'checked');
 
                cy.window().then(win => {
-                       var acceptInput = 
win.map._textInput.shouldAcceptInput();
+                       var acceptInput = win.shouldAcceptInput();
                        expect(acceptInput, 'Should accept 
input').to.equal(win.lastInputState);
                });
        });
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 4e8bd7b75..cc683de13 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -97,11 +97,6 @@ L.Map = L.Evented.extend({
                // lead to URL's of the form <webserver>//insertfile/...
                options.webserver = options.webserver.replace(/\/*$/, '');
 
-               if (L.Browser.cypressTest) {
-                       // Expose us in test mode.
-                       window.map = this;
-               }
-
                this._handlers = [];
                this._layers = {};
                this._zoomBoundLayers = {};
@@ -327,6 +322,26 @@ 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.shouldAcceptInput = function() { return 
map.shouldAcceptInput(); };
+
+                       // This is used to extract the text we *intended*
+                       // to put on the clipboard. There is currently
+                       // no way to actually put data on the clipboard
+                       // programmatically, so this is the way to test
+                       // what we "copied".
+                       window.getTextForClipboard = function() { return 
map._clip.stripHTML(map._clip._getHtmlForClipboard()); };
+               }
        },
 
        loadDocument: function(socket) {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to