2020-12-28 06:28:59 -06:00
|
|
|
/* global cy Cypress expect */
|
2020-01-24 10:13:51 -06:00
|
|
|
|
2020-12-02 10:38:00 -06:00
|
|
|
var mobileWizardIdleTime = 1250;
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Loading the test document directly in Collabora Online.
|
|
|
|
// Parameters:
|
|
|
|
// fileName - test document file name (without path)
|
|
|
|
// subFolder - sub folder inside data folder (e.g. writer, calc, impress)
|
|
|
|
// noFileCopy - whether to create a copy of the test file before run the test.
|
|
|
|
// By default, we create a copy to have a clear test document
|
|
|
|
// but when we open the same document with another user (multi-user tests),
|
|
|
|
// then we intend to open the same document without modification.
|
|
|
|
function loadTestDocNoIntegration(fileName, subFolder, noFileCopy) {
|
2020-09-03 08:52:40 -05:00
|
|
|
cy.log('Loading test document with a local build - start.');
|
2020-04-07 09:13:23 -05:00
|
|
|
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
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Get a clean test document, by creating a copy of it in the workdir
|
|
|
|
// We overwrite this copy everytime we run a new test case.
|
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
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// We generate the URI of the document.
|
2020-09-14 08:53:51 -05:00
|
|
|
var URI = 'http://localhost';
|
|
|
|
if (Cypress.env('INTEGRATION') === 'php-proxy') {
|
|
|
|
URI += '/richproxy/proxy.php?req=';
|
|
|
|
} else {
|
|
|
|
URI += ':' + Cypress.env('SERVER_PORT');
|
|
|
|
}
|
|
|
|
|
2020-02-12 11:01:47 -06:00
|
|
|
if (subFolder === undefined) {
|
2020-09-14 08:53:51 -05:00
|
|
|
URI += '/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-09-14 08:53:51 -05:00
|
|
|
URI += '/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-09-03 08:52:40 -05:00
|
|
|
cy.log('Loading test document with a local build - end.');
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Loading the test document inside a Nextcloud integration.
|
|
|
|
// Parameters:
|
|
|
|
// fileName - test document file name (without path)
|
|
|
|
// subFolder - sub folder inside data folder (e.g. writer, calc, impress)
|
|
|
|
// subsequentLoad - whether we load a test document for the first time in the
|
|
|
|
// test case or not. It's important because we need to sign in
|
|
|
|
// with the username + password only for the first time.
|
2020-09-22 09:51:23 -05:00
|
|
|
function loadTestDocNextcloud(fileName, subFolder, subsequentLoad) {
|
|
|
|
cy.log('Loading test document with nextcloud - start.');
|
|
|
|
cy.log('Param - fileName: ' + fileName);
|
|
|
|
cy.log('Param - subFolder: ' + subFolder);
|
|
|
|
cy.log('Param - subsequentLoad: ' + subsequentLoad);
|
|
|
|
|
2020-10-28 08:39:45 -05:00
|
|
|
// Ignore exceptions comming from nextlcoud.
|
|
|
|
Cypress.on('uncaught:exception', function() {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
upLoadFileToNextCloud(fileName, subFolder, subsequentLoad);
|
2020-09-22 09:51:23 -05:00
|
|
|
|
|
|
|
// Open test document
|
|
|
|
cy.get('tr[data-file=\'' + fileName + '\']')
|
|
|
|
.click();
|
|
|
|
|
|
|
|
cy.get('iframe#richdocumentsframe')
|
|
|
|
.should('be.visible', {timeout : Cypress.config('defaultCommandTimeout') * 2.0});
|
|
|
|
|
2020-11-19 02:12:04 -06:00
|
|
|
cy.wait(10000);
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// We create global aliases for iframes, so it's faster to reach them.
|
2020-11-19 02:12:04 -06:00
|
|
|
cy.get('iframe#richdocumentsframe')
|
|
|
|
.its('0.contentDocument').should('exist')
|
|
|
|
.its('body').should('not.be.undefined')
|
|
|
|
.then(cy.wrap).as('richdocumentsIFrameGlobal');
|
|
|
|
|
|
|
|
cy.get('@richdocumentsIFrameGlobal')
|
2020-11-19 03:16:52 -06:00
|
|
|
.find('iframe#loleafletframe')
|
|
|
|
.its('0.contentDocument').should('exist')
|
|
|
|
.its('body').should('not.be.undefined')
|
|
|
|
.then(cy.wrap).as('loleafletIFrameGlobal');
|
2020-11-19 02:12:04 -06:00
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Let's overwrite get() and contains() methods, because they don't work
|
|
|
|
// inside iframes. We need to find the iframes first and find the related
|
|
|
|
// DOM elements under them.
|
|
|
|
// https://www.cypress.io/blog/2020/02/12/working-with-iframes-in-cypress/
|
2020-11-19 02:12:04 -06:00
|
|
|
var getIframeBody = function(level) {
|
2020-09-22 09:51:23 -05:00
|
|
|
if (level === 1) {
|
2020-11-19 02:12:04 -06:00
|
|
|
return cy.get('@richdocumentsIFrameGlobal');
|
2020-09-22 09:51:23 -05:00
|
|
|
} else if (level === 2) {
|
2020-11-19 02:12:04 -06:00
|
|
|
return cy.get('@loleafletIFrameGlobal');
|
2020-09-22 09:51:23 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Cypress.Commands.overwrite('get', function(originalFn, selector, options) {
|
|
|
|
var iFrameLevel = Cypress.env('IFRAME_LEVEL');
|
|
|
|
if ((iFrameLevel === '1' || iFrameLevel === '2') && !selector.startsWith('@'))
|
|
|
|
if (selector === 'body')
|
2020-11-19 02:12:04 -06:00
|
|
|
return getIframeBody(parseInt(iFrameLevel));
|
2020-09-22 09:51:23 -05:00
|
|
|
else
|
2020-11-19 02:12:04 -06:00
|
|
|
return getIframeBody(parseInt(iFrameLevel)).find(selector, options);
|
2020-09-22 09:51:23 -05:00
|
|
|
else
|
|
|
|
return originalFn(selector, options);
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.overwrite('contains', function(originalFn, selector, content, options) {
|
|
|
|
if (Cypress.env('IFRAME_LEVEL') === '2')
|
|
|
|
return cy.get('#document-container').parent().wrap(originalFn(selector, content, options));
|
|
|
|
else
|
|
|
|
return originalFn(selector, content, options);
|
|
|
|
});
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// The IFRAME_LEVEL environment variable will indicate
|
|
|
|
// in which iframe we have.
|
|
|
|
cy.get('iframe#richdocumentsframe')
|
|
|
|
.then(function() {
|
|
|
|
Cypress.env('IFRAME_LEVEL', '2');
|
|
|
|
});
|
2020-09-22 09:51:23 -05:00
|
|
|
|
|
|
|
cy.log('Loading test document with nextcloud - end.');
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Hide NC's first run wizard, which is opened by the first run of
|
|
|
|
// nextcloud. When we run cypress in headless mode, NC don't detect
|
|
|
|
// that we already used it and so it always opens this wizard.
|
2020-11-05 07:03:10 -06:00
|
|
|
function hideNCFirstRunWizard() {
|
|
|
|
// Hide first run wizard if it's there
|
|
|
|
cy.wait(2000); // Wait some time to the wizard become visible, if it's there.
|
|
|
|
cy.get('body')
|
|
|
|
.then(function(body) {
|
|
|
|
if (body.find('#firstrunwizard').length !== 0) {
|
|
|
|
cy.get('#firstrunwizard')
|
|
|
|
.then(function(wizard) {
|
|
|
|
wizard.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Upload a test document into Nexcloud and open it.
|
|
|
|
// Parameters:
|
|
|
|
// fileName - test document file name (without path)
|
|
|
|
// subFolder - sub folder inside data folder (e.g. writer, calc, impress)
|
|
|
|
// subsequentLoad - whether we load a test document for the first time in the
|
|
|
|
// test case or not. It's important because we need to sign in
|
|
|
|
// with the username + password only for the first time.
|
|
|
|
function upLoadFileToNextCloud(fileName, subFolder, subsequentLoad) {
|
|
|
|
cy.log('Uploading test document into nextcloud - start.');
|
2020-09-03 08:52:40 -05:00
|
|
|
cy.log('Param - fileName: ' + fileName);
|
|
|
|
cy.log('Param - subFolder: ' + subFolder);
|
2020-11-03 09:55:09 -06:00
|
|
|
cy.log('Param - subsequentLoad: ' + subsequentLoad);
|
2020-09-03 08:52:40 -05:00
|
|
|
|
|
|
|
// Open local nextcloud installation
|
2020-11-03 09:55:09 -06:00
|
|
|
cy.visit('http://localhost/nextcloud/index.php/apps/files');
|
2020-09-03 08:52:40 -05:00
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Log in with cypress test user / password (if this is the first time)
|
2020-11-03 09:55:09 -06:00
|
|
|
if (subsequentLoad !== true) {
|
|
|
|
cy.get('input#user')
|
|
|
|
.clear()
|
|
|
|
.type('cypress_test');
|
2020-09-03 08:52:40 -05:00
|
|
|
|
2020-11-03 09:55:09 -06:00
|
|
|
cy.get('input#password')
|
|
|
|
.clear()
|
|
|
|
.type('cypress_test');
|
2020-09-03 08:52:40 -05:00
|
|
|
|
2020-11-03 09:55:09 -06:00
|
|
|
cy.get('input#submit-form')
|
|
|
|
.click();
|
2020-09-03 08:52:40 -05:00
|
|
|
|
2020-11-03 09:55:09 -06:00
|
|
|
cy.get('.button.new')
|
|
|
|
.should('be.visible');
|
2020-09-03 08:52:40 -05:00
|
|
|
|
2020-11-03 09:55:09 -06:00
|
|
|
// Wait for free space calculation before uploading document
|
|
|
|
cy.get('#free_space')
|
|
|
|
.should('not.have.attr', 'value', '');
|
2020-09-03 08:52:40 -05:00
|
|
|
|
2020-11-05 07:03:10 -06:00
|
|
|
hideNCFirstRunWizard();
|
2020-09-10 08:56:09 -05:00
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Remove all existing file, so we make sure the test document is removed
|
|
|
|
// and then we can upload a new one.
|
2020-11-03 09:55:09 -06:00
|
|
|
cy.get('#fileList')
|
|
|
|
.then(function(filelist) {
|
|
|
|
if (filelist.find('tr').length !== 0) {
|
|
|
|
cy.waitUntil(function() {
|
|
|
|
cy.get('#fileList tr:nth-of-type(1) .action-menu.permanent')
|
|
|
|
.click();
|
2020-09-10 08:56:09 -05:00
|
|
|
|
2020-11-03 09:55:09 -06:00
|
|
|
cy.get('.menuitem.action.action-delete.permanent')
|
|
|
|
.click();
|
2020-09-10 08:56:09 -05:00
|
|
|
|
2020-11-03 09:55:09 -06:00
|
|
|
cy.get('#uploadprogressbar')
|
|
|
|
.should('not.be.visible');
|
|
|
|
|
|
|
|
return cy.get('#fileList')
|
|
|
|
.then(function(filelist) {
|
|
|
|
return filelist.find('tr').length === 0;
|
|
|
|
});
|
|
|
|
}, {timeout: 60000});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Wait for free space calculation before uploading document
|
|
|
|
cy.get('#free_space')
|
|
|
|
.should('not.have.attr', 'value', '');
|
2020-11-05 07:03:10 -06:00
|
|
|
|
|
|
|
hideNCFirstRunWizard();
|
2020-11-03 09:55:09 -06:00
|
|
|
}
|
2020-09-03 08:52:40 -05:00
|
|
|
|
|
|
|
cy.get('tr[data-file=\'' + fileName + '\']')
|
|
|
|
.should('not.exist');
|
|
|
|
|
|
|
|
// Upload test document
|
|
|
|
var fileURI = '';
|
|
|
|
if (subFolder === undefined) {
|
|
|
|
fileURI += fileName;
|
|
|
|
} else {
|
|
|
|
fileURI += subFolder + '/' + fileName;
|
|
|
|
}
|
|
|
|
doIfOnDesktop(function() {
|
|
|
|
cy.get('input#file_upload_start')
|
|
|
|
.attachFile({ filePath: 'desktop/' + fileURI, encoding: 'binary' });
|
|
|
|
});
|
|
|
|
doIfOnMobile(function() {
|
|
|
|
cy.get('input#file_upload_start')
|
|
|
|
.attachFile({ filePath: 'mobile/' + fileURI, encoding: 'binary' });
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.get('#uploadprogressbar')
|
|
|
|
.should('not.be.visible');
|
|
|
|
|
|
|
|
cy.get('tr[data-file=\'' + fileName + '\']')
|
2020-09-22 09:51:23 -05:00
|
|
|
.should('be.visible');
|
2021-02-05 08:08:28 -06:00
|
|
|
|
|
|
|
cy.log('Uploading test document into nextcloud - end.');
|
2020-09-03 08:52:40 -05:00
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Used for interference test. We wait until the interfering user loads
|
|
|
|
// its instance of the document and starts its interfering actions.
|
|
|
|
// So we can be sure the interference actions are made during the test
|
|
|
|
// user does the actual test steps.
|
2020-11-26 10:53:29 -06:00
|
|
|
function waitForInterferingUser() {
|
|
|
|
cy.get('#tb_actionbar_item_userlist', { timeout: Cypress.config('defaultCommandTimeout') * 2.0 })
|
|
|
|
.should('be.visible');
|
|
|
|
|
|
|
|
cy.wait(10000);
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Loading the test document inside Collabora Online (directly or via some integration).
|
|
|
|
// Parameters:
|
|
|
|
// fileName - test document file name (without path)
|
|
|
|
// subFolder - sub folder inside data folder (e.g. writer, calc, impress)
|
|
|
|
// noFileCopy - whether to create a copy of the test file before run the test.
|
|
|
|
// By default, we create a copy to have a clear test document
|
|
|
|
// but when we open the same document with another user (multi-user tests),
|
|
|
|
// then we intend to open the same document without modification.
|
|
|
|
// subsequentLoad - whether we load a test document for the first time in the
|
|
|
|
// test case or not. It's important for nextcloud because we need to sign in
|
|
|
|
// with the username + password only for the first time.
|
2020-09-22 09:51:23 -05:00
|
|
|
function loadTestDoc(fileName, subFolder, noFileCopy, subsequentLoad) {
|
2020-09-03 08:52:40 -05:00
|
|
|
cy.log('Loading test document - start.');
|
|
|
|
cy.log('Param - fileName: ' + fileName);
|
|
|
|
cy.log('Param - subFolder: ' + subFolder);
|
|
|
|
cy.log('Param - noFileCopy: ' + noFileCopy);
|
2021-02-05 08:08:28 -06:00
|
|
|
cy.log('Param - subsequentLoad: ' + noFileCopy);
|
2020-09-03 08:52:40 -05:00
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// We set the mobile screen size here. We could use any other phone type here.
|
2020-09-03 08:52:40 -05:00
|
|
|
doIfOnMobile(function() {
|
|
|
|
cy.viewport('iphone-6');
|
|
|
|
});
|
|
|
|
|
|
|
|
if (Cypress.env('INTEGRATION') === 'nextcloud') {
|
2020-09-22 09:51:23 -05:00
|
|
|
loadTestDocNextcloud(fileName, subFolder, subsequentLoad);
|
2020-09-03 08:52:40 -05:00
|
|
|
} else {
|
2021-02-05 08:08:28 -06:00
|
|
|
loadTestDocNoIntegration(fileName, subFolder, noFileCopy);
|
2020-09-03 08:52:40 -05:00
|
|
|
}
|
|
|
|
|
2020-01-24 10:13:51 -06:00
|
|
|
// Wait for the document to fully load
|
2020-09-30 07:50:37 -05:00
|
|
|
cy.get('.leaflet-canvas-container canvas', {timeout : Cypress.config('defaultCommandTimeout') * 2.0});
|
|
|
|
|
2020-10-03 11:38:25 -05:00
|
|
|
// Wait until anything is drawn on tile canvas.
|
2020-09-30 07:50:37 -05:00
|
|
|
canvasShouldBeFullWhiteOrNot('.leaflet-canvas-container canvas', false);
|
2020-04-07 09:13:23 -05:00
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// With php-proxy the client is irresponsive for some seconds after load, because of the incoming messages.
|
2020-09-14 08:53:51 -05:00
|
|
|
if (Cypress.env('INTEGRATION') === 'php-proxy') {
|
|
|
|
cy.wait(10000);
|
|
|
|
}
|
|
|
|
|
2020-08-10 09:25:56 -05:00
|
|
|
// Wait for the sidebar to open.
|
2020-11-03 06:11:35 -06:00
|
|
|
if (Cypress.env('INTEGRATION') !== 'nextcloud') {
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2021-02-01 09:21:02 -06:00
|
|
|
|
|
|
|
// Check also that the inputbar is drawn in Calc.
|
|
|
|
doIfInCalc(function() {
|
|
|
|
canvasShouldBeFullWhiteOrNot('#calc-inputbar .inputbar_canvas', false);
|
|
|
|
});
|
2020-11-03 06:11:35 -06:00
|
|
|
});
|
|
|
|
}
|
2020-08-10 09:25:56 -05:00
|
|
|
|
2020-11-26 10:53:29 -06:00
|
|
|
if (Cypress.env('INTERFERENCE_TEST') === true) {
|
|
|
|
waitForInterferingUser();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Assert that we have cursor and focus on the text area of the document.
|
2020-03-01 09:48:10 -06:00
|
|
|
function assertCursorAndFocus() {
|
2021-02-05 08:08:28 -06:00
|
|
|
cy.log('Verifying Cursor and Focus - start');
|
2020-09-11 06:54:55 -05:00
|
|
|
|
|
|
|
if (Cypress.env('INTEGRATION') !== 'nextcloud') {
|
|
|
|
// Active element must be the textarea named clipboard.
|
|
|
|
cy.document().its('activeElement.className')
|
|
|
|
.should('be.eq', 'clipboard');
|
|
|
|
}
|
2020-03-24 11:15:51 -05:00
|
|
|
|
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();
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
cy.log('Verifying Cursor and Focus - end');
|
2020-03-01 09:48:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Select all text via CTRL+A shortcut.
|
2021-02-05 08:12:51 -06:00
|
|
|
function selectAllText() {
|
2021-02-05 08:08:28 -06:00
|
|
|
cy.log('Select all text - start');
|
|
|
|
|
2020-08-11 22:23:25 -05:00
|
|
|
typeIntoDocument('{ctrl}a');
|
2020-03-16 15:27:00 -05:00
|
|
|
|
2020-12-07 08:59:52 -06:00
|
|
|
textSelectionShouldExist();
|
2021-02-05 08:08:28 -06:00
|
|
|
|
|
|
|
cy.log('Select all text - end');
|
2020-03-01 09:48:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear all text by selecting all and deleting.
|
|
|
|
function clearAllText() {
|
2021-02-05 08:08:28 -06:00
|
|
|
cy.log('Clear all text - start');
|
2020-03-01 09:48:10 -06:00
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
assertCursorAndFocus();
|
2020-03-01 09:48:10 -06:00
|
|
|
|
2020-04-22 10:43:03 -05:00
|
|
|
// Trigger select all
|
2021-02-05 08:14:25 -06:00
|
|
|
selectAllText();
|
2020-04-22 10:43:03 -05:00
|
|
|
|
|
|
|
// Then remove
|
2020-08-11 22:23:25 -05:00
|
|
|
typeIntoDocument('{del}');
|
2020-04-22 10:43:03 -05:00
|
|
|
|
2020-12-07 08:59:52 -06:00
|
|
|
textSelectionShouldNotExist();
|
2021-02-05 08:08:28 -06:00
|
|
|
|
|
|
|
cy.log('Clear all text - end');
|
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.
|
2021-02-05 08:08:28 -06:00
|
|
|
// Parameters:
|
|
|
|
// expectedPlainText - a string, the clipboard container should have.
|
2020-03-01 09:48:10 -06:00
|
|
|
function expectTextForClipboard(expectedPlainText) {
|
2020-06-22 05:34:06 -05:00
|
|
|
doIfInWriter(function() {
|
2020-10-07 08:22:26 -05:00
|
|
|
cy.get('#copy-paste-container p')
|
|
|
|
.then(function(pItem) {
|
|
|
|
if (pItem.children('font').length !== 0) {
|
|
|
|
cy.get('#copy-paste-container p font')
|
|
|
|
.should('have.text', expectedPlainText);
|
|
|
|
} else {
|
|
|
|
cy.get('#copy-paste-container p')
|
|
|
|
.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.
|
2021-02-05 08:08:28 -06:00
|
|
|
// Parameters:
|
|
|
|
// regexp - a regular expression to match the content with.
|
|
|
|
// https://docs.cypress.io/api/commands/contains.html#Regular-Expression
|
2020-06-01 05:04:15 -05:00
|
|
|
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-09-22 09:51:23 -05:00
|
|
|
function beforeAll(fileName, subFolder, noFileCopy, subsequentLoad) {
|
|
|
|
loadTestDoc(fileName, subFolder, noFileCopy, subsequentLoad);
|
2020-03-28 13:28:05 -05:00
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// This method is intended to call after each test case.
|
|
|
|
// We use this method to close the document, before step
|
|
|
|
// on to the next test case.
|
|
|
|
// Parameters:
|
|
|
|
// fileName - test document name (we can check it on the admin console).
|
|
|
|
// testState - whether the test passed or failed before this method was called.
|
2020-11-13 02:40:27 -06:00
|
|
|
function afterAll(fileName, testState) {
|
2020-04-07 09:13:23 -05:00
|
|
|
cy.log('Waiting for closing the document - start.');
|
|
|
|
|
2020-09-03 08:52:40 -05:00
|
|
|
if (Cypress.env('INTEGRATION') === 'nextcloud') {
|
2020-12-15 06:49:48 -06:00
|
|
|
if (testState === 'failed') {
|
|
|
|
Cypress.env('IFRAME_LEVEL', '');
|
2020-11-16 09:54:52 -06:00
|
|
|
return;
|
2020-12-15 06:49:48 -06:00
|
|
|
}
|
2020-11-16 09:54:52 -06:00
|
|
|
|
2020-09-22 09:51:23 -05:00
|
|
|
if (Cypress.env('IFRAME_LEVEL') === '2') {
|
2021-02-05 08:08:28 -06:00
|
|
|
// Close the document, with the close button.
|
2020-09-03 08:52:40 -05:00
|
|
|
doIfOnMobile(function() {
|
2020-09-18 06:00:31 -05:00
|
|
|
cy.get('#tb_actionbar_item_closemobile')
|
|
|
|
.click();
|
|
|
|
|
|
|
|
cy.get('#mobile-edit-button')
|
|
|
|
.should('be.visible');
|
|
|
|
|
2020-09-03 08:52:40 -05:00
|
|
|
cy.get('#tb_actionbar_item_closemobile')
|
|
|
|
.then(function(item) {
|
|
|
|
cy.wrap(item)
|
|
|
|
.click();
|
2020-09-22 09:51:23 -05:00
|
|
|
Cypress.env('IFRAME_LEVEL', '');
|
2020-09-03 08:52:40 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
doIfOnDesktop(function() {
|
|
|
|
cy.get('#closebutton')
|
|
|
|
.then(function(item) {
|
|
|
|
cy.wrap(item)
|
|
|
|
.click();
|
2020-09-22 09:51:23 -05:00
|
|
|
Cypress.env('IFRAME_LEVEL', '');
|
2020-09-03 08:52:40 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.get('#filestable')
|
|
|
|
.should('be.visible');
|
|
|
|
|
|
|
|
cy.get('#filestable')
|
|
|
|
.should('not.have.class', 'hidden');
|
|
|
|
|
|
|
|
cy.wait(3000);
|
|
|
|
|
|
|
|
// Remove the document
|
|
|
|
cy.get('tr[data-file=\'' + fileName + '\'] .action-menu.permanent')
|
|
|
|
.click();
|
|
|
|
|
|
|
|
cy.get('.menuitem.action.action-delete.permanent')
|
|
|
|
.click();
|
|
|
|
|
|
|
|
cy.get('tr[data-file=\'' + fileName + '\']')
|
|
|
|
.should('not.exist');
|
|
|
|
|
|
|
|
}
|
2021-02-05 08:08:28 -06:00
|
|
|
// For php-proxy admin console does not work, so we just open
|
|
|
|
// localhost and wait some time for the test document to be closed.
|
2020-11-12 09:13:09 -06:00
|
|
|
} else if (Cypress.env('INTEGRATION') === 'php-proxy') {
|
|
|
|
cy.visit('http://localhost/', {failOnStatusCode: false});
|
2020-03-13 09:27:33 -05:00
|
|
|
|
2020-09-01 07:57:36 -05:00
|
|
|
cy.wait(5000);
|
|
|
|
} else {
|
2020-09-03 08:52:40 -05:00
|
|
|
// Make sure that the document is closed
|
|
|
|
cy.visit('http://admin:admin@localhost:' +
|
|
|
|
Cypress.env('SERVER_PORT') +
|
|
|
|
'/loleaflet/dist/admin/admin.html');
|
|
|
|
|
2020-11-16 09:54:52 -06:00
|
|
|
// https://github.com/cypress-io/cypress/issues/9207
|
|
|
|
if (testState === 'failed') {
|
|
|
|
cy.wait(5000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-01 07:57:36 -05:00
|
|
|
cy.get('#uptime')
|
|
|
|
.should('not.have.text', '0');
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
cy.get('#docview', { timeout: Cypress.config('defaultCommandTimeout') * 2.0 })
|
|
|
|
.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
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Initialize an alias to a negative number value. It can be useful
|
|
|
|
// when we use an alias as a variable and later we intend to set it
|
|
|
|
// to a non-negative value.
|
|
|
|
// Parameters:
|
|
|
|
// aliasName - a string, expected to be used as alias.
|
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.');
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Initialize an alias to an empty string. It can be useful
|
|
|
|
// when we use an alias as a variable and later we intend to
|
|
|
|
// set it to a non-empty string.
|
|
|
|
// Parameters:
|
|
|
|
// aliasName - a string, expected to be used as alias.
|
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.');
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Run a code snippet if we are inside Calc.
|
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
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Run a code snippet if we are *NOT* inside Calc.
|
2020-08-13 08:13:49 -05:00
|
|
|
function doIfNotInCalc(callback) {
|
|
|
|
cy.get('#document-container')
|
|
|
|
.then(function(doc) {
|
|
|
|
if (!doc.hasClass('spreadsheet-doctype')) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Run a code snippet if we are inside Impress.
|
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
|
|
|
}
|
2021-02-05 08:08:28 -06:00
|
|
|
|
|
|
|
// Run a code snippet if we are *NOT* inside Impress.
|
2020-08-13 08:13:49 -05:00
|
|
|
function doIfNotInImpress(callback) {
|
|
|
|
cy.get('#document-container')
|
|
|
|
.then(function(doc) {
|
|
|
|
if (!doc.hasClass('presentation-doctype')) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-04-22 10:40:35 -05:00
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Run a code snippet if we are inside Writer.
|
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
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Run a code snippet if we are *NOT* inside Writer.
|
2020-08-13 08:13:49 -05:00
|
|
|
function doIfNotInWriter(callback) {
|
|
|
|
cy.get('#document-container')
|
|
|
|
.then(function(doc) {
|
|
|
|
if (!doc.hasClass('text-doctype')) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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.
|
2021-02-05 08:08:28 -06:00
|
|
|
// Parameters:
|
|
|
|
// selector - a CSS selector to query a DOM element to type in.
|
|
|
|
// text - a text, what we'll type char-by-char.
|
|
|
|
// delayMs - delay in ms between the characters.
|
2020-03-28 13:28:05 -05:00
|
|
|
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-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-09-30 07:50:37 -05:00
|
|
|
function canvasShouldBeFullWhiteOrNot(selector, fullWhite = true) {
|
|
|
|
cy.get(selector)
|
|
|
|
.should(function(canvas) {
|
|
|
|
var context = canvas[0].getContext('2d');
|
|
|
|
var pixelData = context.getImageData(0, 0, canvas[0].width, canvas[0].height).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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Waits until a DOM element becomes idle (does not change for a given time).
|
|
|
|
// It's useful to handle flickering on the UI, which might make cypress
|
|
|
|
// tests unstable. If the UI flickers, we can use this method to wait
|
|
|
|
// until it settles and the move on with the test.
|
|
|
|
// Parameters:
|
|
|
|
// selector - a CSS selector to query a DOM element to wait on to be idle.
|
|
|
|
// content - a string, a content selector used by cy.contains() to select the correct DOM element.
|
|
|
|
// waitingTime - how much time to wait before we say the item is idle.
|
2020-12-02 10:38:00 -06:00
|
|
|
function waitUntilIdle(selector, content, waitingTime = mobileWizardIdleTime) {
|
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;
|
2021-02-05 08:08:28 -06:00
|
|
|
// We check every 'waitOnce' time whether we are idle.
|
2020-07-14 08:25:19 -05:00
|
|
|
var waitOnce = 250;
|
2021-02-05 08:08:28 -06:00
|
|
|
// 'idleSince' variable counts the idle time so far.
|
2020-07-14 08:25:19 -05:00
|
|
|
var idleSince = 0;
|
2020-07-07 05:28:33 -05:00
|
|
|
if (content) {
|
2021-02-05 08:08:28 -06:00
|
|
|
// We get the initial DOM item first.
|
2020-07-07 05:28:33 -05:00
|
|
|
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])) {
|
2021-02-05 08:08:28 -06:00
|
|
|
cy.log('Item was 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 {
|
2021-02-05 08:08:28 -06:00
|
|
|
// We get the initial DOM item first.
|
2020-07-07 05:28:33 -05:00
|
|
|
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])) {
|
2021-02-05 08:08:28 -06:00
|
|
|
cy.log('Item was 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.');
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Waits the DOM element to be idle and clicks on it afterwards.
|
2020-07-07 05:28:33 -05:00
|
|
|
// 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
|
2021-02-05 08:08:28 -06:00
|
|
|
// IMPORTANT: don't use this if there is no flickering.
|
|
|
|
// Use simple click() instead. This method is much slower.
|
|
|
|
// Parameters:
|
|
|
|
// selector - a CSS selector to query a DOM element to wait on to be idle.
|
|
|
|
// content - a string, a content selector used by cy.contains() to select the correct DOM element.
|
|
|
|
// waitingTime - how much time to wait before we say the item is idle.
|
2020-12-02 10:38:00 -06:00
|
|
|
function clickOnIdle(selector, content, waitingTime = mobileWizardIdleTime) {
|
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);
|
2021-02-05 08:08:28 -06:00
|
|
|
|
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.');
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Waits the DOM element to be idle and typs into it afterwards.
|
|
|
|
// See also the comments at clickOnIdle() method.
|
|
|
|
// Parameters:
|
|
|
|
// selector - a CSS selector to query a DOM element to wait on to be idle.
|
|
|
|
// input - text to be typed into the selected DOM element.
|
|
|
|
// waitingTime - how much time to wait before we say the item is idle.
|
2020-12-02 10:38:00 -06:00
|
|
|
function inputOnIdle(selector, input, waitingTime = mobileWizardIdleTime) {
|
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.');
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Run a code snippet if we are in a mobile test.
|
2020-07-31 08:44:39 -05:00
|
|
|
function doIfOnMobile(callback) {
|
|
|
|
cy.window()
|
|
|
|
.then(function(win) {
|
|
|
|
if (win.navigator.userAgent === 'cypress-mobile') {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Run a code snippet if we are in a desktop test.
|
2020-07-31 08:44:39 -05:00
|
|
|
function doIfOnDesktop(callback) {
|
|
|
|
cy.window()
|
|
|
|
.then(function(win) {
|
|
|
|
if (win.navigator.userAgent === 'cypress') {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Move the cursor in the given direction and wait until it moves.
|
|
|
|
// Parameters:
|
|
|
|
// direction - the direction the cursor should be moved.
|
|
|
|
// possible valude: up, down, left, right, home, end
|
|
|
|
// modifier - a modifier to the cursor movement keys (e.g. 'shift' or 'ctrl').
|
|
|
|
// checkCursorVis - whether check the cursor visibility after movement.
|
|
|
|
// cursorSelector - selector for the cursor DOM element (document cursor is the default).
|
2021-01-29 06:23:51 -06:00
|
|
|
function moveCursor(direction, modifier,
|
|
|
|
checkCursorVis = true,
|
|
|
|
cursorSelector = '.leaflet-overlay-pane .blinking-cursor') {
|
2020-08-05 10:17:43 -05:00
|
|
|
cy.log('Moving text cursor - start.');
|
|
|
|
cy.log('Param - direction: ' + direction);
|
2020-12-14 09:27:13 -06:00
|
|
|
cy.log('Param - modifier: ' + modifier);
|
|
|
|
cy.log('Param - checkCursorVis: ' + checkCursorVis);
|
2021-01-29 06:23:51 -06:00
|
|
|
cy.log('Param - cursorSelector: ' + cursorSelector);
|
2020-08-05 10:17:43 -05:00
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Get the original cursor position.
|
2020-12-14 09:27:13 -06:00
|
|
|
if (direction === 'up' ||
|
|
|
|
direction === 'down' ||
|
|
|
|
(direction === 'home' && modifier === 'ctrl') ||
|
|
|
|
(direction === 'end' && modifier === 'ctrl')) {
|
2021-01-29 06:23:51 -06:00
|
|
|
getCursorPos('top', 'origCursorPos', cursorSelector);
|
2020-12-14 09:27:13 -06:00
|
|
|
} else if (direction === 'left' ||
|
|
|
|
direction === 'right' ||
|
|
|
|
direction === 'home' ||
|
|
|
|
direction === 'end') {
|
2021-01-29 06:23:51 -06:00
|
|
|
getCursorPos('left', 'origCursorPos', cursorSelector);
|
2020-08-05 10:17:43 -05:00
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Move the cursor using keyboard input.
|
2020-08-05 10:17:43 -05:00
|
|
|
var key = '';
|
2020-12-14 09:27:13 -06:00
|
|
|
if (modifier === 'ctrl') {
|
|
|
|
key = '{ctrl}';
|
2020-12-14 09:54:46 -06:00
|
|
|
} else if (modifier === 'shift') {
|
|
|
|
key = '{shift}';
|
2020-12-14 09:27:13 -06:00
|
|
|
}
|
|
|
|
|
2020-08-05 10:17:43 -05:00
|
|
|
if (direction === 'up') {
|
2020-12-14 09:27:13 -06:00
|
|
|
key += '{uparrow}';
|
2020-08-05 10:17:43 -05:00
|
|
|
} else if (direction === 'down') {
|
2020-12-14 09:27:13 -06:00
|
|
|
key += '{downarrow}';
|
2020-08-05 10:17:43 -05:00
|
|
|
} else if (direction === 'left') {
|
2020-12-14 09:27:13 -06:00
|
|
|
key += '{leftarrow}';
|
2020-08-05 10:17:43 -05:00
|
|
|
} else if (direction === 'right') {
|
2020-12-14 09:27:13 -06:00
|
|
|
key += '{rightarrow}';
|
2020-09-16 09:01:46 -05:00
|
|
|
} else if (direction === 'home') {
|
2020-12-14 09:27:13 -06:00
|
|
|
key += '{home}';
|
2020-09-16 09:01:46 -05:00
|
|
|
} else if (direction === 'end') {
|
2020-12-14 09:27:13 -06:00
|
|
|
key += '{end}';
|
2020-08-05 10:17:43 -05:00
|
|
|
}
|
2020-12-14 09:27:13 -06:00
|
|
|
|
2020-08-11 22:23:25 -05:00
|
|
|
typeIntoDocument(key);
|
2020-08-05 10:17:43 -05:00
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Make sure the cursor position was changed.
|
2020-08-05 10:17:43 -05:00
|
|
|
cy.get('@origCursorPos')
|
|
|
|
.then(function(origCursorPos) {
|
2021-01-29 06:23:51 -06:00
|
|
|
cy.get(cursorSelector)
|
2020-08-05 10:17:43 -05:00
|
|
|
.should(function(cursor) {
|
2020-12-14 09:27:13 -06:00
|
|
|
if (direction === 'up' ||
|
2020-12-31 09:33:53 -06:00
|
|
|
direction === 'down' ||
|
|
|
|
(direction === 'home' && modifier === 'ctrl') ||
|
2020-12-14 09:27:13 -06:00
|
|
|
(direction === 'end' && modifier === 'ctrl')) {
|
2020-12-31 09:33:53 -06:00
|
|
|
expect(cursor.offset().top).to.not.equal(origCursorPos);
|
|
|
|
} else if (direction === 'left' ||
|
|
|
|
direction === 'right' ||
|
|
|
|
direction === 'end' ||
|
|
|
|
direction === 'home') {
|
|
|
|
expect(cursor.offset().left).to.not.equal(origCursorPos);
|
2020-08-05 10:17:43 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Cursor should be visible after move, because the view always follows it.
|
2020-12-31 09:33:53 -06:00
|
|
|
if (checkCursorVis === true) {
|
2021-01-29 06:23:51 -06:00
|
|
|
cy.get(cursorSelector)
|
2020-12-31 09:33:53 -06:00
|
|
|
.should('be.visible');
|
|
|
|
}
|
|
|
|
|
2020-08-05 10:17:43 -05:00
|
|
|
cy.log('Moving text cursor - end.');
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Type something into the document. It can be some text or special characters too.
|
2020-08-11 22:23:25 -05:00
|
|
|
function typeIntoDocument(text) {
|
2020-08-14 07:45:52 -05:00
|
|
|
cy.log('Typing into document - start.');
|
2020-08-12 09:59:12 -05:00
|
|
|
|
2020-08-11 22:23:25 -05:00
|
|
|
cy.get('textarea.clipboard')
|
|
|
|
.type(text, {force: true});
|
2020-08-14 07:45:52 -05:00
|
|
|
|
|
|
|
cy.log('Typing into document - end.');
|
2020-08-11 22:23:25 -05:00
|
|
|
}
|
2020-07-31 08:44:39 -05:00
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// Get cursor's current position.
|
|
|
|
// Parameters:
|
|
|
|
// offsetProperty - which offset position we need (e.g. 'left' or 'top').
|
|
|
|
// aliasName - we create an alias with the queried position.
|
|
|
|
// cursorSelector - selector to find the correct cursor element in the DOM.
|
2021-01-29 06:23:51 -06:00
|
|
|
function getCursorPos(offsetProperty, aliasName, cursorSelector = '.leaflet-overlay-pane .blinking-cursor') {
|
2020-10-19 09:40:45 -05:00
|
|
|
initAliasToNegative(aliasName);
|
|
|
|
|
2021-01-29 06:23:51 -06:00
|
|
|
cy.get(cursorSelector)
|
|
|
|
.invoke('offset')
|
|
|
|
.its(offsetProperty)
|
|
|
|
.as(aliasName);
|
2020-10-19 09:40:45 -05:00
|
|
|
|
|
|
|
cy.get('@' + aliasName)
|
|
|
|
.should('be.greaterThan', 0);
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// We make sure we have a text selection..
|
2020-12-07 08:59:52 -06:00
|
|
|
function textSelectionShouldExist() {
|
|
|
|
cy.log('Make sure text selection exists - start.');
|
|
|
|
|
|
|
|
cy.get('.leaflet-selection-marker-start')
|
|
|
|
.should('exist');
|
|
|
|
|
|
|
|
cy.get('.leaflet-selection-marker-end')
|
|
|
|
.should('exist');
|
|
|
|
|
|
|
|
// One of the marker should be visible at least (if not both).
|
|
|
|
cy.get('.leaflet-selection-marker-start, .leaflet-selection-marker-end')
|
|
|
|
.should('be.visible');
|
|
|
|
|
|
|
|
cy.log('Make sure text selection exists - end.');
|
|
|
|
}
|
|
|
|
|
2021-02-05 08:08:28 -06:00
|
|
|
// We make sure we don't have a text selection..
|
2020-12-07 08:59:52 -06:00
|
|
|
function textSelectionShouldNotExist() {
|
|
|
|
cy.log('Make sure there is no text selection - start.');
|
|
|
|
|
|
|
|
cy.get('.leaflet-selection-marker-start')
|
|
|
|
.should('not.exist');
|
|
|
|
|
|
|
|
cy.get('.leaflet-selection-marker-end')
|
|
|
|
.should('not.exist');
|
|
|
|
|
|
|
|
cy.log('Make sure there is no text selection - end.');
|
|
|
|
}
|
|
|
|
|
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-08-13 08:13:49 -05:00
|
|
|
module.exports.doIfNotInCalc = doIfNotInCalc;
|
|
|
|
module.exports.doIfNotInImpress = doIfNotInImpress;
|
|
|
|
module.exports.doIfNotInWriter = doIfNotInWriter;
|
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-15 09:35:09 -05:00
|
|
|
module.exports.imageShouldBeFullWhiteOrNot = imageShouldBeFullWhiteOrNot;
|
2020-09-30 07:50:37 -05:00
|
|
|
module.exports.canvasShouldBeFullWhiteOrNot = canvasShouldBeFullWhiteOrNot;
|
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;
|
2021-02-05 08:08:28 -06:00
|
|
|
module.exports.upLoadFileToNextCloud = upLoadFileToNextCloud;
|
2020-10-19 09:40:45 -05:00
|
|
|
module.exports.getCursorPos = getCursorPos;
|
2020-12-07 08:59:52 -06:00
|
|
|
module.exports.textSelectionShouldExist = textSelectionShouldExist;
|
|
|
|
module.exports.textSelectionShouldNotExist = textSelectionShouldNotExist;
|