2020-07-07 05:28:33 -05:00
|
|
|
/* global cy Cypress expect require */
|
|
|
|
|
|
|
|
require('cypress-wait-until');
|
2020-01-24 10:13:51 -06:00
|
|
|
|
2020-08-04 10:40:28 -05:00
|
|
|
function loadTestDoc(fileName, subFolder, noFileCopy) {
|
2020-04-07 09:13:23 -05:00
|
|
|
cy.log('Loading test document - start.');
|
|
|
|
cy.log('Param - fileName: ' + fileName);
|
|
|
|
cy.log('Param - subFolder: ' + subFolder);
|
2020-08-04 10:40:28 -05:00
|
|
|
cy.log('Param - noFileCopy: ' + noFileCopy);
|
2020-04-07 09:13:23 -05:00
|
|
|
|
2020-01-24 10:13:51 -06:00
|
|
|
// Get a clean test document
|
2020-08-04 10:40:28 -05:00
|
|
|
if (noFileCopy !== true) {
|
|
|
|
if (subFolder === undefined) {
|
|
|
|
cy.task('copyFile', {
|
|
|
|
sourceDir: Cypress.env('DATA_FOLDER'),
|
|
|
|
destDir: Cypress.env('WORKDIR'),
|
|
|
|
fileName: fileName,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
cy.task('copyFile', {
|
|
|
|
sourceDir: Cypress.env('DATA_FOLDER') + subFolder + '/',
|
|
|
|
destDir: Cypress.env('WORKDIR') + subFolder + '/',
|
|
|
|
fileName: fileName,
|
|
|
|
});
|
|
|
|
}
|
2020-02-12 11:01:47 -06:00
|
|
|
}
|
2020-01-24 10:13:51 -06:00
|
|
|
|
2020-07-31 08:44:39 -05:00
|
|
|
doIfOnMobile(function() {
|
2020-02-02 23:23:55 -06:00
|
|
|
cy.viewport('iphone-6');
|
2020-07-31 08:44:39 -05:00
|
|
|
});
|
2020-01-24 10:13:51 -06:00
|
|
|
|
|
|
|
// Open test document
|
2020-02-12 11:01:47 -06:00
|
|
|
var URI;
|
|
|
|
if (subFolder === undefined) {
|
2020-02-19 19:25:01 -06:00
|
|
|
URI = 'http://localhost:'+
|
|
|
|
Cypress.env('SERVER_PORT') +
|
|
|
|
'/loleaflet/' +
|
2020-02-12 11:01:47 -06:00
|
|
|
Cypress.env('WSD_VERSION_HASH') +
|
2020-02-13 11:03:58 -06:00
|
|
|
'/loleaflet.html?lang=en-US&file_path=file://' +
|
2020-02-12 11:01:47 -06:00
|
|
|
Cypress.env('WORKDIR') + fileName;
|
|
|
|
} else {
|
2020-02-19 19:25:01 -06:00
|
|
|
URI = 'http://localhost:'+
|
|
|
|
Cypress.env('SERVER_PORT') +
|
|
|
|
'/loleaflet/' +
|
2020-02-12 11:01:47 -06:00
|
|
|
Cypress.env('WSD_VERSION_HASH') +
|
2020-02-13 11:03:58 -06:00
|
|
|
'/loleaflet.html?lang=en-US&file_path=file://' +
|
2020-02-12 11:01:47 -06:00
|
|
|
Cypress.env('WORKDIR') + subFolder + '/' + fileName;
|
|
|
|
}
|
|
|
|
|
2020-03-28 13:28:05 -05:00
|
|
|
cy.log('Loading: ' + URI);
|
2020-02-12 11:01:47 -06:00
|
|
|
cy.visit(URI, {
|
2020-01-27 10:05:48 -06:00
|
|
|
onLoad: function(win) {
|
|
|
|
win.onerror = cy.onUncaughtException;
|
2020-05-18 09:53:49 -05:00
|
|
|
}});
|
|
|
|
|
2020-01-24 10:13:51 -06:00
|
|
|
// Wait for the document to fully load
|
2020-08-04 10:42:32 -05:00
|
|
|
cy.get('.leaflet-tile-loaded', {timeout : Cypress.config('defaultCommandTimeout') * 2.0});
|
2020-04-07 09:13:23 -05:00
|
|
|
|
2020-08-10 09:25:56 -05:00
|
|
|
// Wait for the sidebar to open.
|
|
|
|
doIfOnDesktop(function() {
|
|
|
|
cy.get('#sidebar-panel')
|
|
|
|
.should('be.visible');
|
|
|
|
|
|
|
|
// Check that the document does not take the whole window width.
|
|
|
|
cy.window()
|
|
|
|
.then(function(win) {
|
|
|
|
cy.get('#document-container')
|
|
|
|
.should(function(doc) {
|
|
|
|
expect(doc).to.have.lengthOf(1);
|
|
|
|
expect(doc[0].getBoundingClientRect().right).to.be.lessThan(win.innerWidth * 0.95);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-07 09:13:23 -05:00
|
|
|
cy.log('Loading test document - end.');
|
2020-01-24 10:13:51 -06:00
|
|
|
}
|
2020-04-07 09:13:23 -05:00
|
|
|
|
leaflet: maintain the keyboard state after toolbar actions
Previously we supressed the keyboard after toolbar
actions, but that is problematic because then the
user is unable to delete/replace selected text,
because the keyboard is hidden and there is no way
of showing keyboard without changing the selection.
Now we maintain the keyboard state, which is likely
visible, since a selection shows the keyboard.
This might not be ideal, because the user might
hide the keyboard on the device and we will restore
it after invoking a toolbar action, but at least
it's more usable now. Unfortunately, there is no
API to track the keyboard visibility.
New Cypress tests added to validate the above.
The tests depend on checking the last keyboard
visibility state in Map, because there is no
reliable (or any?) way to know whether the keyboard
is visible or not. There are many cases where we
actually hide the keyboard, while having the input
focus on the textarea element, so that is no indication
that the keyboard is visible. We do this for usability
purposes. For example, during zooming, when selecting
cells and graphics/shapes, etc.
The purpose of the cell is to validate that we restored
the keyboard visibility or we changed it, depending
on which is expected after each operation.
Change-Id: If0f2e96909ff20753043734789397d190cedb502
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90663
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
2020-03-17 11:02:59 -05:00
|
|
|
// Assert that NO keyboard input is accepted (i.e. keyboard should be HIDDEN).
|
|
|
|
function assertNoKeyboardInput() {
|
2020-04-22 04:51:15 -05:00
|
|
|
cy.get('textarea.clipboard')
|
|
|
|
.should('have.attr', 'data-accept-input', 'false');
|
leaflet: maintain the keyboard state after toolbar actions
Previously we supressed the keyboard after toolbar
actions, but that is problematic because then the
user is unable to delete/replace selected text,
because the keyboard is hidden and there is no way
of showing keyboard without changing the selection.
Now we maintain the keyboard state, which is likely
visible, since a selection shows the keyboard.
This might not be ideal, because the user might
hide the keyboard on the device and we will restore
it after invoking a toolbar action, but at least
it's more usable now. Unfortunately, there is no
API to track the keyboard visibility.
New Cypress tests added to validate the above.
The tests depend on checking the last keyboard
visibility state in Map, because there is no
reliable (or any?) way to know whether the keyboard
is visible or not. There are many cases where we
actually hide the keyboard, while having the input
focus on the textarea element, so that is no indication
that the keyboard is visible. We do this for usability
purposes. For example, during zooming, when selecting
cells and graphics/shapes, etc.
The purpose of the cell is to validate that we restored
the keyboard visibility or we changed it, depending
on which is expected after each operation.
Change-Id: If0f2e96909ff20753043734789397d190cedb502
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90663
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
2020-03-17 11:02:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Assert that keyboard input is accepted (i.e. keyboard should be VISIBLE).
|
|
|
|
function assertHaveKeyboardInput() {
|
2020-04-22 04:51:15 -05:00
|
|
|
cy.get('textarea.clipboard')
|
|
|
|
.should('have.attr', 'data-accept-input', 'true');
|
leaflet: maintain the keyboard state after toolbar actions
Previously we supressed the keyboard after toolbar
actions, but that is problematic because then the
user is unable to delete/replace selected text,
because the keyboard is hidden and there is no way
of showing keyboard without changing the selection.
Now we maintain the keyboard state, which is likely
visible, since a selection shows the keyboard.
This might not be ideal, because the user might
hide the keyboard on the device and we will restore
it after invoking a toolbar action, but at least
it's more usable now. Unfortunately, there is no
API to track the keyboard visibility.
New Cypress tests added to validate the above.
The tests depend on checking the last keyboard
visibility state in Map, because there is no
reliable (or any?) way to know whether the keyboard
is visible or not. There are many cases where we
actually hide the keyboard, while having the input
focus on the textarea element, so that is no indication
that the keyboard is visible. We do this for usability
purposes. For example, during zooming, when selecting
cells and graphics/shapes, etc.
The purpose of the cell is to validate that we restored
the keyboard visibility or we changed it, depending
on which is expected after each operation.
Change-Id: If0f2e96909ff20753043734789397d190cedb502
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90663
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
2020-03-17 11:02:59 -05:00
|
|
|
}
|
|
|
|
|
2020-03-01 09:48:10 -06:00
|
|
|
// Assert that we have cursor and focus.
|
|
|
|
function assertCursorAndFocus() {
|
|
|
|
cy.log('Verifying Cursor and Focus.');
|
|
|
|
|
2020-03-24 11:15:51 -05:00
|
|
|
// Active element must be the textarea named clipboard.
|
|
|
|
cy.document().its('activeElement.className')
|
|
|
|
.should('be.eq', 'clipboard');
|
|
|
|
|
2020-03-01 09:48:10 -06:00
|
|
|
// In edit mode, we should have the blinking cursor.
|
|
|
|
cy.get('.leaflet-cursor.blinking-cursor')
|
|
|
|
.should('exist');
|
|
|
|
cy.get('.leaflet-cursor-container')
|
|
|
|
.should('exist');
|
|
|
|
|
leaflet: maintain the keyboard state after toolbar actions
Previously we supressed the keyboard after toolbar
actions, but that is problematic because then the
user is unable to delete/replace selected text,
because the keyboard is hidden and there is no way
of showing keyboard without changing the selection.
Now we maintain the keyboard state, which is likely
visible, since a selection shows the keyboard.
This might not be ideal, because the user might
hide the keyboard on the device and we will restore
it after invoking a toolbar action, but at least
it's more usable now. Unfortunately, there is no
API to track the keyboard visibility.
New Cypress tests added to validate the above.
The tests depend on checking the last keyboard
visibility state in Map, because there is no
reliable (or any?) way to know whether the keyboard
is visible or not. There are many cases where we
actually hide the keyboard, while having the input
focus on the textarea element, so that is no indication
that the keyboard is visible. We do this for usability
purposes. For example, during zooming, when selecting
cells and graphics/shapes, etc.
The purpose of the cell is to validate that we restored
the keyboard visibility or we changed it, depending
on which is expected after each operation.
Change-Id: If0f2e96909ff20753043734789397d190cedb502
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90663
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
2020-03-17 11:02:59 -05:00
|
|
|
assertHaveKeyboardInput();
|
|
|
|
|
2020-03-01 09:48:10 -06:00
|
|
|
cy.log('Cursor and Focus verified.');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select all text via CTRL+A shortcut.
|
2020-03-18 07:18:59 -05:00
|
|
|
function selectAllText(assertFocus = true) {
|
|
|
|
if (assertFocus)
|
|
|
|
assertCursorAndFocus();
|
2020-03-01 09:48:10 -06:00
|
|
|
|
|
|
|
cy.log('Select all text');
|
|
|
|
|
2020-03-16 15:27:00 -05:00
|
|
|
// Trigger select all
|
2020-08-11 22:23:25 -05:00
|
|
|
typeIntoDocument('{ctrl}a');
|
2020-03-16 15:27:00 -05:00
|
|
|
|
|
|
|
cy.get('.leaflet-marker-icon')
|
|
|
|
.should('exist');
|
2020-03-01 09:48:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear all text by selecting all and deleting.
|
|
|
|
function clearAllText() {
|
|
|
|
assertCursorAndFocus();
|
|
|
|
|
|
|
|
cy.log('Clear all text');
|
|
|
|
|
2020-04-22 10:43:03 -05:00
|
|
|
// Trigger select all
|
2020-08-11 22:23:25 -05:00
|
|
|
typeIntoDocument('{ctrl}a');
|
2020-04-22 10:43:03 -05:00
|
|
|
|
|
|
|
cy.get('.leaflet-marker-icon')
|
|
|
|
.should('exist');
|
|
|
|
|
|
|
|
// Then remove
|
2020-08-11 22:23:25 -05:00
|
|
|
typeIntoDocument('{del}');
|
2020-04-22 10:43:03 -05:00
|
|
|
|
|
|
|
cy.get('.leaflet-marker-icon')
|
|
|
|
.should('not.exist');
|
2020-03-01 09:48:10 -06:00
|
|
|
}
|
|
|
|
|
2020-06-01 05:04:15 -05:00
|
|
|
// Check that the clipboard text matches with the specified text.
|
2020-03-01 09:48:10 -06:00
|
|
|
function expectTextForClipboard(expectedPlainText) {
|
2020-06-22 05:34:06 -05:00
|
|
|
doIfInWriter(function() {
|
2020-04-22 10:40:35 -05:00
|
|
|
cy.get('#copy-paste-container p font')
|
|
|
|
.should('have.text', expectedPlainText);
|
2020-06-22 05:34:06 -05:00
|
|
|
});
|
|
|
|
doIfInCalc(function() {
|
2020-04-22 10:40:35 -05:00
|
|
|
cy.get('#copy-paste-container pre')
|
|
|
|
.should('have.text', expectedPlainText);
|
2020-06-22 05:34:06 -05:00
|
|
|
});
|
|
|
|
doIfInImpress(function() {
|
|
|
|
cy.get('#copy-paste-container pre')
|
|
|
|
.should('have.text', expectedPlainText);
|
|
|
|
});
|
2020-03-01 09:48:10 -06:00
|
|
|
}
|
|
|
|
|
2020-06-01 05:04:15 -05:00
|
|
|
// Check that the clipboard text matches with the
|
|
|
|
// passed regular expression.
|
|
|
|
function matchClipboardText(regexp) {
|
2020-06-22 05:34:06 -05:00
|
|
|
doIfInWriter(function() {
|
2020-06-01 05:04:15 -05:00
|
|
|
cy.contains('#copy-paste-container p font', regexp)
|
|
|
|
.should('exist');
|
2020-06-22 05:34:06 -05:00
|
|
|
});
|
|
|
|
doIfInCalc(function() {
|
2020-06-01 05:04:15 -05:00
|
|
|
cy.contains('#copy-paste-container pre', regexp)
|
|
|
|
.should('exist');
|
2020-06-22 05:34:06 -05:00
|
|
|
});
|
|
|
|
doIfInImpress(function() {
|
|
|
|
cy.contains('#copy-paste-container pre', regexp)
|
|
|
|
.should('exist');
|
|
|
|
});
|
2020-06-01 05:04:15 -05:00
|
|
|
}
|
|
|
|
|
2020-08-04 21:14:36 -05:00
|
|
|
function beforeAll(fileName, subFolder, noFileCopy) {
|
|
|
|
loadTestDoc(fileName, subFolder, noFileCopy);
|
2020-03-28 13:28:05 -05:00
|
|
|
}
|
|
|
|
|
2020-03-13 09:27:33 -05:00
|
|
|
function afterAll(fileName) {
|
2020-04-07 09:13:23 -05:00
|
|
|
cy.log('Waiting for closing the document - start.');
|
|
|
|
cy.log('Param - fileName: ' + fileName);
|
|
|
|
|
2020-02-02 22:34:25 -06:00
|
|
|
// Make sure that the document is closed
|
2020-02-19 19:25:01 -06:00
|
|
|
cy.visit('http://admin:admin@localhost:' +
|
|
|
|
Cypress.env('SERVER_PORT') +
|
|
|
|
'/loleaflet/dist/admin/admin.html');
|
2020-03-13 09:27:33 -05:00
|
|
|
|
|
|
|
cy.get('#uptime')
|
|
|
|
.should('not.have.text', '0');
|
|
|
|
|
2020-04-14 05:29:30 -05:00
|
|
|
// We have all lines of document infos as one long string.
|
|
|
|
// We have PID number before the file names, with matching
|
|
|
|
// also on the PID number we can make sure to match on the
|
|
|
|
// whole file name, not on a suffix of a file name.
|
|
|
|
var regex = new RegExp('[0-9]' + fileName);
|
2020-08-04 04:28:56 -05:00
|
|
|
cy.get('#docview', { timeout: Cypress.config('defaultCommandTimeout') * 2.0 })
|
2020-04-14 05:29:30 -05:00
|
|
|
.invoke('text')
|
|
|
|
.should('not.match', regex);
|
2020-04-07 09:13:23 -05:00
|
|
|
|
|
|
|
cy.log('Waiting for closing the document - end.');
|
2020-01-30 07:31:10 -06:00
|
|
|
}
|
|
|
|
|
2020-04-17 06:34:03 -05:00
|
|
|
|
|
|
|
function initAliasToNegative(aliasName) {
|
|
|
|
cy.log('Initializing alias to a negative value - start.');
|
|
|
|
cy.log('Param - aliasName: ' + aliasName);
|
|
|
|
|
|
|
|
cy.get('#copy-paste-container')
|
|
|
|
.invoke('offset')
|
|
|
|
.its('top')
|
|
|
|
.as(aliasName);
|
|
|
|
|
|
|
|
cy.get('@' + aliasName)
|
|
|
|
.should('be.lessThan', 0);
|
|
|
|
|
|
|
|
cy.log('Initializing alias to a negative value - end.');
|
|
|
|
}
|
|
|
|
|
2020-05-18 06:16:15 -05:00
|
|
|
function initAliasToEmptyString(aliasName) {
|
|
|
|
cy.log('Initializing alias to empty string - start.');
|
|
|
|
cy.log('Param - aliasName: ' + aliasName);
|
|
|
|
|
|
|
|
// Do an empty slice to generate empty string
|
|
|
|
cy.get('#copy-paste-container')
|
|
|
|
.invoke('css', 'display')
|
|
|
|
.invoke('slice', '0', '0')
|
|
|
|
.as(aliasName);
|
|
|
|
|
|
|
|
cy.get('@' + aliasName)
|
|
|
|
.should('be.equal', '');
|
|
|
|
|
|
|
|
cy.log('Initializing alias to empty string - end.');
|
|
|
|
}
|
|
|
|
|
2020-06-22 05:34:06 -05:00
|
|
|
function doIfInCalc(callback) {
|
|
|
|
cy.get('#document-container')
|
|
|
|
.then(function(doc) {
|
|
|
|
if (doc.hasClass('spreadsheet-doctype')) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
2020-04-22 10:40:35 -05:00
|
|
|
}
|
|
|
|
|
2020-06-22 05:34:06 -05:00
|
|
|
function doIfInImpress(callback) {
|
|
|
|
cy.get('#document-container')
|
|
|
|
.then(function(doc) {
|
|
|
|
if (doc.hasClass('presentation-doctype')) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
2020-04-22 10:40:35 -05:00
|
|
|
}
|
|
|
|
|
2020-06-22 05:34:06 -05:00
|
|
|
function doIfInWriter(callback) {
|
|
|
|
cy.get('#document-container')
|
|
|
|
.then(function(doc) {
|
|
|
|
if (doc.hasClass('text-doctype')) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
2020-04-22 10:40:35 -05:00
|
|
|
}
|
|
|
|
|
2020-03-28 13:28:05 -05:00
|
|
|
// 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) {
|
|
|
|
for (var i = 0; i < text.length; i++) {
|
2020-07-29 04:14:30 -05:00
|
|
|
cy.get(selector)
|
|
|
|
.type(text.charAt(i));
|
2020-03-28 13:28:05 -05:00
|
|
|
if (delayMs > 0)
|
|
|
|
cy.wait(delayMs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-04 22:09:21 -05:00
|
|
|
function getLOVersion() {
|
|
|
|
var versionString = Cypress.env('LO_CORE_VERSION');
|
|
|
|
if (versionString.includes('Collabora')) {
|
2020-07-24 07:56:55 -05:00
|
|
|
if (versionString.includes('_6.2.')) {
|
2020-06-04 22:09:21 -05:00
|
|
|
return 'cp-6-2';
|
2020-07-24 07:56:55 -05:00
|
|
|
} else if (versionString.includes('_6.4.')) {
|
2020-06-04 22:09:21 -05:00
|
|
|
return 'cp-6-4';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 'master';
|
|
|
|
}
|
|
|
|
|
2020-06-15 09:35:09 -05:00
|
|
|
function imageShouldBeFullWhiteOrNot(selector, fullWhite = true) {
|
|
|
|
cy.get(selector)
|
|
|
|
.should(function(images) {
|
|
|
|
var img = images[0];
|
|
|
|
|
|
|
|
// Create an offscreen canvas to check the image's pixels
|
|
|
|
var canvas = document.createElement('canvas');
|
|
|
|
canvas.width = img.width;
|
|
|
|
canvas.height = img.height;
|
|
|
|
canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height);
|
|
|
|
var context = canvas.getContext('2d');
|
|
|
|
|
|
|
|
// Ignore a small zone on the edges, to ignore border.
|
|
|
|
var ignoredPixels = 2;
|
|
|
|
var pixelData = context.getImageData(ignoredPixels, ignoredPixels,
|
|
|
|
img.width - 2 * ignoredPixels,
|
|
|
|
img.height - 2 * ignoredPixels).data;
|
|
|
|
|
|
|
|
var allIsWhite = true;
|
|
|
|
for (var i = 0; i < pixelData.length; ++i) {
|
|
|
|
allIsWhite = allIsWhite && pixelData[i] == 255;
|
|
|
|
}
|
|
|
|
if (fullWhite)
|
|
|
|
expect(allIsWhite).to.be.true;
|
|
|
|
else
|
|
|
|
expect(allIsWhite).to.be.false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-14 08:25:19 -05:00
|
|
|
function waitUntilIdle(selector, content, waitingTime = 1000) {
|
2020-07-07 05:28:33 -05:00
|
|
|
cy.log('Waiting item to be idle - start.');
|
2020-07-31 08:30:37 -05:00
|
|
|
cy.log('Param - selector: ' + selector);
|
|
|
|
cy.log('Param - content: ' + content);
|
|
|
|
cy.log('Param - waitingTime: ' + waitingTime);
|
2020-07-07 05:28:33 -05:00
|
|
|
|
|
|
|
var item;
|
2020-07-14 08:25:19 -05:00
|
|
|
var waitOnce = 250;
|
|
|
|
var idleSince = 0;
|
2020-07-07 05:28:33 -05:00
|
|
|
if (content) {
|
|
|
|
cy.contains(selector, content, { log: false })
|
|
|
|
.then(function(itemToIdle) {
|
|
|
|
item = itemToIdle;
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.waitUntil(function() {
|
2020-07-14 08:25:19 -05:00
|
|
|
cy.wait(waitOnce, { log: false });
|
2020-07-07 05:28:33 -05:00
|
|
|
|
|
|
|
return cy.contains(selector, content, { log: false })
|
|
|
|
.then(function(itemToIdle) {
|
|
|
|
if (Cypress.dom.isDetached(item[0])) {
|
2020-07-14 08:25:19 -05:00
|
|
|
cy.log('Item is detached after ' + (idleSince + waitOnce).toString() + ' ms.');
|
2020-07-07 05:28:33 -05:00
|
|
|
item = itemToIdle;
|
2020-07-14 08:25:19 -05:00
|
|
|
idleSince = 0;
|
2020-07-07 05:28:33 -05:00
|
|
|
} else {
|
2020-07-14 08:25:19 -05:00
|
|
|
idleSince += waitOnce;
|
2020-07-07 05:28:33 -05:00
|
|
|
}
|
2020-07-14 08:25:19 -05:00
|
|
|
return idleSince > waitingTime;
|
2020-07-07 05:28:33 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
cy.get(selector, { log: false })
|
|
|
|
.then(function(itemToIdle) {
|
|
|
|
item = itemToIdle;
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.waitUntil(function() {
|
2020-07-14 08:25:19 -05:00
|
|
|
cy.wait(waitOnce, { log: false });
|
2020-07-07 05:28:33 -05:00
|
|
|
|
|
|
|
return cy.get(selector, { log: false })
|
|
|
|
.then(function(itemToIdle) {
|
|
|
|
if (Cypress.dom.isDetached(item[0])) {
|
2020-07-14 08:25:19 -05:00
|
|
|
cy.log('Item is detached after ' + (idleSince + waitOnce).toString() + ' ms.');
|
2020-07-07 05:28:33 -05:00
|
|
|
item = itemToIdle;
|
2020-07-14 08:25:19 -05:00
|
|
|
idleSince = 0;
|
2020-07-07 05:28:33 -05:00
|
|
|
} else {
|
2020-07-14 08:25:19 -05:00
|
|
|
idleSince += waitOnce;
|
2020-07-07 05:28:33 -05:00
|
|
|
}
|
2020-07-14 08:25:19 -05:00
|
|
|
return idleSince > waitingTime;
|
2020-07-07 05:28:33 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
cy.log('Waiting item to be idle - end.');
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a workaround for avoid 'item detached from DOM'
|
|
|
|
// failures caused by GUI flickering.
|
|
|
|
// GUI flickering might mean bad design, but
|
|
|
|
// until it's fixed we can use this method.
|
|
|
|
// Known GUI flickering:
|
|
|
|
// * mobile wizard
|
|
|
|
// IMPORTANT: don't use this if there is no
|
|
|
|
// flickering. Use simple click() instead. This method
|
|
|
|
// is much slower.
|
2020-07-14 08:25:19 -05:00
|
|
|
function clickOnIdle(selector, content, waitingTime = 1000) {
|
2020-07-07 05:28:33 -05:00
|
|
|
cy.log('Clicking on item when idle - start.');
|
|
|
|
|
2020-07-14 08:25:19 -05:00
|
|
|
waitUntilIdle(selector, content, waitingTime);
|
2020-07-07 05:28:33 -05:00
|
|
|
if (content) {
|
|
|
|
cy.contains(selector, content)
|
|
|
|
.click();
|
|
|
|
} else {
|
|
|
|
cy.get(selector)
|
|
|
|
.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
cy.log('Clicking on item when idle - end.');
|
|
|
|
}
|
|
|
|
|
|
|
|
// See comments at clickOnIdle() method.
|
2020-07-14 08:25:19 -05:00
|
|
|
function inputOnIdle(selector, input, waitingTime = 1000) {
|
2020-07-07 05:28:33 -05:00
|
|
|
cy.log('Type into an input item when idle - start.');
|
|
|
|
|
2020-07-14 08:25:19 -05:00
|
|
|
waitUntilIdle(selector, undefined, waitingTime);
|
2020-07-07 05:28:33 -05:00
|
|
|
|
|
|
|
cy.get(selector)
|
|
|
|
.clear()
|
|
|
|
.type(input)
|
|
|
|
.type('{enter}');
|
|
|
|
|
|
|
|
cy.log('Type into an input item when idle - end.');
|
|
|
|
}
|
|
|
|
|
2020-07-31 08:44:39 -05:00
|
|
|
function doIfOnMobile(callback) {
|
|
|
|
cy.window()
|
|
|
|
.then(function(win) {
|
|
|
|
if (win.navigator.userAgent === 'cypress-mobile') {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function doIfOnDesktop(callback) {
|
|
|
|
cy.window()
|
|
|
|
.then(function(win) {
|
|
|
|
if (win.navigator.userAgent === 'cypress') {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:23:25 -05:00
|
|
|
function moveCursor(direction) {
|
2020-08-05 10:17:43 -05:00
|
|
|
cy.log('Moving text cursor - start.');
|
|
|
|
cy.log('Param - direction: ' + direction);
|
|
|
|
|
|
|
|
initAliasToNegative('origCursorPos');
|
|
|
|
|
|
|
|
cy.get('.blinking-cursor')
|
2020-08-06 01:02:53 -05:00
|
|
|
.should('exist');
|
2020-08-05 10:17:43 -05:00
|
|
|
|
|
|
|
if (direction === 'up' || direction === 'down') {
|
|
|
|
cy.get('.blinking-cursor')
|
|
|
|
.invoke('offset')
|
|
|
|
.its('top')
|
|
|
|
.as('origCursorPos');
|
|
|
|
} else if (direction === 'left' || direction === 'right') {
|
|
|
|
cy.get('.blinking-cursor')
|
|
|
|
.invoke('offset')
|
|
|
|
.its('left')
|
|
|
|
.as('origCursorPos');
|
|
|
|
}
|
|
|
|
|
|
|
|
cy.get('@origCursorPos')
|
2020-08-11 08:18:11 -05:00
|
|
|
.should('be.at.least', 0);
|
2020-08-05 10:17:43 -05:00
|
|
|
|
|
|
|
var key = '';
|
|
|
|
if (direction === 'up') {
|
|
|
|
key = '{uparrow}';
|
|
|
|
} else if (direction === 'down') {
|
|
|
|
key = '{downarrow}';
|
|
|
|
} else if (direction === 'left') {
|
|
|
|
key = '{leftarrow}';
|
|
|
|
} else if (direction === 'right') {
|
|
|
|
key = '{rightarrow}';
|
|
|
|
}
|
2020-08-11 22:23:25 -05:00
|
|
|
typeIntoDocument(key);
|
2020-08-05 10:17:43 -05:00
|
|
|
|
|
|
|
cy.get('@origCursorPos')
|
|
|
|
.then(function(origCursorPos) {
|
|
|
|
cy.get('.blinking-cursor')
|
|
|
|
.should(function(cursor) {
|
|
|
|
if (direction === 'up') {
|
|
|
|
expect(cursor.offset().top).to.be.lessThan(origCursorPos);
|
|
|
|
} else if (direction === 'down') {
|
|
|
|
expect(cursor.offset().top).to.be.greaterThan(origCursorPos);
|
|
|
|
} else if (direction === 'left') {
|
|
|
|
expect(cursor.offset().left).to.be.lessThan(origCursorPos);
|
|
|
|
} else if (direction === 'right') {
|
|
|
|
expect(cursor.offset().left).to.be.greaterThan(origCursorPos);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.log('Moving text cursor - end.');
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:23:25 -05:00
|
|
|
function typeIntoDocument(text) {
|
2020-08-12 09:59:12 -05:00
|
|
|
cy.get('textarea.clipboard')
|
|
|
|
.focus();
|
|
|
|
|
|
|
|
cy.document().its('activeElement.tagName')
|
|
|
|
.should('be.eq', 'TEXTAREA');
|
|
|
|
|
|
|
|
cy.document().its('activeElement.className')
|
|
|
|
.should('be.eq', 'clipboard');
|
|
|
|
|
2020-08-11 22:23:25 -05:00
|
|
|
cy.get('textarea.clipboard')
|
|
|
|
.type(text, {force: true});
|
|
|
|
}
|
2020-07-31 08:44:39 -05:00
|
|
|
|
2020-01-24 10:13:51 -06:00
|
|
|
module.exports.loadTestDoc = loadTestDoc;
|
2020-03-01 09:48:10 -06:00
|
|
|
module.exports.assertCursorAndFocus = assertCursorAndFocus;
|
leaflet: maintain the keyboard state after toolbar actions
Previously we supressed the keyboard after toolbar
actions, but that is problematic because then the
user is unable to delete/replace selected text,
because the keyboard is hidden and there is no way
of showing keyboard without changing the selection.
Now we maintain the keyboard state, which is likely
visible, since a selection shows the keyboard.
This might not be ideal, because the user might
hide the keyboard on the device and we will restore
it after invoking a toolbar action, but at least
it's more usable now. Unfortunately, there is no
API to track the keyboard visibility.
New Cypress tests added to validate the above.
The tests depend on checking the last keyboard
visibility state in Map, because there is no
reliable (or any?) way to know whether the keyboard
is visible or not. There are many cases where we
actually hide the keyboard, while having the input
focus on the textarea element, so that is no indication
that the keyboard is visible. We do this for usability
purposes. For example, during zooming, when selecting
cells and graphics/shapes, etc.
The purpose of the cell is to validate that we restored
the keyboard visibility or we changed it, depending
on which is expected after each operation.
Change-Id: If0f2e96909ff20753043734789397d190cedb502
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90663
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
2020-03-17 11:02:59 -05:00
|
|
|
module.exports.assertNoKeyboardInput = assertNoKeyboardInput;
|
|
|
|
module.exports.assertHaveKeyboardInput = assertHaveKeyboardInput;
|
2020-03-01 09:48:10 -06:00
|
|
|
module.exports.selectAllText = selectAllText;
|
|
|
|
module.exports.clearAllText = clearAllText;
|
|
|
|
module.exports.expectTextForClipboard = expectTextForClipboard;
|
2020-06-01 05:04:15 -05:00
|
|
|
module.exports.matchClipboardText = matchClipboardText;
|
2020-02-02 22:34:25 -06:00
|
|
|
module.exports.afterAll = afterAll;
|
2020-04-17 06:34:03 -05:00
|
|
|
module.exports.initAliasToNegative = initAliasToNegative;
|
2020-05-18 06:16:15 -05:00
|
|
|
module.exports.initAliasToEmptyString = initAliasToEmptyString;
|
2020-06-22 05:34:06 -05:00
|
|
|
module.exports.doIfInCalc = doIfInCalc;
|
|
|
|
module.exports.doIfInImpress = doIfInImpress;
|
|
|
|
module.exports.doIfInWriter = doIfInWriter;
|
2020-07-31 08:44:39 -05:00
|
|
|
module.exports.beforeAll = beforeAll;
|
2020-03-28 13:28:05 -05:00
|
|
|
module.exports.typeText = typeText;
|
2020-06-04 22:09:21 -05:00
|
|
|
module.exports.getLOVersion = getLOVersion;
|
2020-06-15 09:35:09 -05:00
|
|
|
module.exports.imageShouldBeFullWhiteOrNot = imageShouldBeFullWhiteOrNot;
|
2020-07-07 05:28:33 -05:00
|
|
|
module.exports.clickOnIdle = clickOnIdle;
|
|
|
|
module.exports.inputOnIdle = inputOnIdle;
|
2020-07-17 07:03:33 -05:00
|
|
|
module.exports.waitUntilIdle = waitUntilIdle;
|
2020-07-31 08:44:39 -05:00
|
|
|
module.exports.doIfOnMobile = doIfOnMobile;
|
|
|
|
module.exports.doIfOnDesktop = doIfOnDesktop;
|
2020-08-05 10:17:43 -05:00
|
|
|
module.exports.moveCursor = moveCursor;
|
2020-08-11 22:23:25 -05:00
|
|
|
module.exports.typeIntoDocument = typeIntoDocument;
|