cypress_test/integration_tests/common/helper.js |   10 +++------
 loleaflet/src/map/Map.js                        |   25 +++++++++++++++++++-----
 2 files changed, 24 insertions(+), 11 deletions(-)

New commits:
commit 12e69c2e70bf5ada37e46b58fa902ae98a69d37f
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: Thu Mar 26 17:56:25 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>
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/91126

diff --git a/cypress_test/integration_tests/common/helper.js 
b/cypress_test/integration_tests/common/helper.js
index 505315594..402432bc8 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);
        });
 }
@@ -126,16 +126,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/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