Cypress: Retry selectTextOfShape

Most users of selectTextOfShape also need to select all text.
Sometimes the cursor appears but does not allow CTRL+a to select
all text. Work around this by including the selection in the retry
using waitUntil.

Fixes mobile/impress/apply_paragraph_props_text_spec.js, which started
failing sporadically after commit e0a0646ce1.

I also adjusted the dblclick selector because it was finding multiple
elements but I think that is unrelated

I also created a separate function editTextInShape, for tests
that do not need to select all text

Signed-off-by: Neil Guertin <neil.guertin@collabora.com>
Change-Id: Icdfa731ba9a5f8d08a858192a4f1f5bc79b09b76
pull/8882/head
Neil Guertin 2024-04-26 14:56:09 -04:00 committed by Neil Guertin
parent d1a58af640
commit ed731b7091
3 changed files with 35 additions and 20 deletions

View File

@ -161,12 +161,31 @@ function triggerNewSVGForShapeInTheCenter() {
// Select the text inside a preselected shape. So we assume // Select the text inside a preselected shape. So we assume
// we have already a shape selected. We try to select the // we have already a shape selected. We try to select the
// text of this shape by double clicking into it, until the // text of this shape by double clicking into it, until the
// cursor becomes visible. // cursor becomes visible and the text is selected
function selectTextOfShape(selectAllText = true) { function selectTextOfShape() {
cy.log('>> selectTextOfShape - start'); cy.log('>> selectTextOfShape - start');
// Double click onto the selected shape // Double click onto the selected shape
// Retry until the cursor appears // Retry until the cursor appears and the text is selected
cy.waitUntil(function() {
cy.cGet('svg g svg').dblclick({force: true});
helper.typeIntoDocument('{ctrl}a');
return cy.cGet('.leaflet-marker-pane')
.then(function(markerPane) {
return markerPane.children().length !== 0;
});
});
helper.textSelectionShouldExist();
cy.log('<< selectTextOfShape - end');
}
// Double click on the shape to edit the text
// and wait for the cursor to appear
function editTextInShape() {
cy.log('>> editTextInShape - start');
cy.waitUntil(function() { cy.waitUntil(function() {
cy.cGet('svg g .leaflet-interactive').dblclick({force: true}); cy.cGet('svg g .leaflet-interactive').dblclick({force: true});
return cy.cGet('.cursor-overlay') return cy.cGet('.cursor-overlay')
@ -174,13 +193,9 @@ function selectTextOfShape(selectAllText = true) {
return overlay.children('.leaflet-cursor-container').length !== 0; return overlay.children('.leaflet-cursor-container').length !== 0;
}); });
}); });
cy.cGet('.leaflet-cursor.blinking-cursor').should('exist'); cy.cGet('.leaflet-cursor.blinking-cursor').should('exist');
if (selectAllText) cy.log('<< editTextInShape - end');
helper.selectAllText();
cy.log('<< selectTextOfShape - end');
} }
// Step into text editing of the preselected shape. So we assume // Step into text editing of the preselected shape. So we assume
@ -249,6 +264,7 @@ module.exports.selectTextShapeInTheCenter = selectTextShapeInTheCenter;
module.exports.triggerNewSVGForShapeInTheCenter = triggerNewSVGForShapeInTheCenter; module.exports.triggerNewSVGForShapeInTheCenter = triggerNewSVGForShapeInTheCenter;
module.exports.removeShapeSelection = removeShapeSelection; module.exports.removeShapeSelection = removeShapeSelection;
module.exports.selectTextOfShape = selectTextOfShape; module.exports.selectTextOfShape = selectTextOfShape;
module.exports.editTextInShape =editTextInShape;
module.exports.dblclickOnSelectedShape = dblclickOnSelectedShape; module.exports.dblclickOnSelectedShape = dblclickOnSelectedShape;
module.exports.addSlide = addSlide; module.exports.addSlide = addSlide;
module.exports.changeSlide = changeSlide; module.exports.changeSlide = changeSlide;

View File

@ -5,7 +5,6 @@ var desktopHelper = require('../../common/desktop_helper');
var impressHelper = require('../../common/impress_helper'); var impressHelper = require('../../common/impress_helper');
var ceHelper = require('../../common/contenteditable_helper'); var ceHelper = require('../../common/contenteditable_helper');
function selectTextShape(i) { function selectTextShape(i) {
cy.log('Selecting text shape - start.'); cy.log('Selecting text shape - start.');
if (typeof i !== 'number' || i <= 0 || i > 2) if (typeof i !== 'number' || i <= 0 || i > 2)
@ -41,7 +40,7 @@ describe(['taga11yenabled'], 'Editable area - Basic typing and caret moving', fu
it.skip('Editing top text shape', function () { it.skip('Editing top text shape', function () {
// select shape and activate editing // select shape and activate editing
selectTextShape(1); selectTextShape(1);
impressHelper.selectTextOfShape(false); impressHelper.editTextInShape();
// initial position // initial position
ceHelper.checkHTMLContent(''); ceHelper.checkHTMLContent('');
ceHelper.checkCaretPosition(0); ceHelper.checkCaretPosition(0);
@ -54,7 +53,7 @@ describe(['taga11yenabled'], 'Editable area - Basic typing and caret moving', fu
ceHelper.checkHTMLContent(''); ceHelper.checkHTMLContent('');
// activate editing again // activate editing again
selectTextShape(1); selectTextShape(1);
impressHelper.selectTextOfShape(false); impressHelper.editTextInShape();
ceHelper.checkPlainContent('Hello World'); ceHelper.checkPlainContent('Hello World');
ceHelper.moveCaret('end'); ceHelper.moveCaret('end');
ceHelper.checkCaretPosition(11); ceHelper.checkCaretPosition(11);
@ -64,7 +63,7 @@ describe(['taga11yenabled'], 'Editable area - Basic typing and caret moving', fu
it('Deleting text', function () { it('Deleting text', function () {
// select shape and activate editing // select shape and activate editing
selectTextShape(1); selectTextShape(1);
impressHelper.selectTextOfShape(false); impressHelper.editTextInShape();
// initial position // initial position
ceHelper.checkHTMLContent(''); ceHelper.checkHTMLContent('');
ceHelper.checkCaretPosition(0); ceHelper.checkCaretPosition(0);
@ -88,7 +87,7 @@ describe(['taga11yenabled'], 'Editable area - Basic typing and caret moving', fu
it.skip('Editing bottom text shape', function () { it.skip('Editing bottom text shape', function () {
// select shape and activate editing // select shape and activate editing
selectTextShape(2); selectTextShape(2);
impressHelper.selectTextOfShape(false); impressHelper.editTextInShape();
// initial position // initial position
ceHelper.checkHTMLContent(''); ceHelper.checkHTMLContent('');
ceHelper.checkCaretPosition(0); ceHelper.checkCaretPosition(0);
@ -99,7 +98,7 @@ describe(['taga11yenabled'], 'Editable area - Basic typing and caret moving', fu
impressHelper.removeShapeSelection(); impressHelper.removeShapeSelection();
// activate editing again // activate editing again
selectTextShape(2); selectTextShape(2);
impressHelper.selectTextOfShape(false); impressHelper.editTextInShape();
ceHelper.checkPlainContent('Hello World'); ceHelper.checkPlainContent('Hello World');
ceHelper.moveCaret('end'); ceHelper.moveCaret('end');
ceHelper.checkCaretPosition(11); ceHelper.checkCaretPosition(11);
@ -110,7 +109,7 @@ describe(['taga11yenabled'], 'Editable area - Basic typing and caret moving', fu
impressHelper.removeShapeSelection(); impressHelper.removeShapeSelection();
// activate editing again // activate editing again
selectTextShape(2); selectTextShape(2);
impressHelper.selectTextOfShape(false); impressHelper.editTextInShape();
// navigating between paragraphs // navigating between paragraphs
ceHelper.checkPlainContent('Green red'); ceHelper.checkPlainContent('Green red');
ceHelper.moveCaret('up'); ceHelper.moveCaret('up');
@ -121,7 +120,7 @@ describe(['taga11yenabled'], 'Editable area - Basic typing and caret moving', fu
it.skip('Editing both text shapes', function () { it.skip('Editing both text shapes', function () {
// select top shape and activate editing // select top shape and activate editing
selectTextShape(1); selectTextShape(1);
impressHelper.selectTextOfShape(false); impressHelper.editTextInShape();
// initial position // initial position
ceHelper.checkHTMLContent(''); ceHelper.checkHTMLContent('');
ceHelper.checkCaretPosition(0); ceHelper.checkCaretPosition(0);
@ -132,7 +131,7 @@ describe(['taga11yenabled'], 'Editable area - Basic typing and caret moving', fu
// select bottom shape and activate editing // select bottom shape and activate editing
selectTextShape(2); selectTextShape(2);
ceHelper.checkHTMLContent(''); ceHelper.checkHTMLContent('');
impressHelper.selectTextOfShape(false); impressHelper.editTextInShape();
// typing // typing
ceHelper.checkHTMLContent(''); ceHelper.checkHTMLContent('');
ceHelper.checkCaretPosition(0); ceHelper.checkCaretPosition(0);
@ -142,7 +141,7 @@ describe(['taga11yenabled'], 'Editable area - Basic typing and caret moving', fu
// select top shape and activate editing // select top shape and activate editing
selectTextShape(1); selectTextShape(1);
ceHelper.checkHTMLContent(''); ceHelper.checkHTMLContent('');
impressHelper.selectTextOfShape(false); impressHelper.editTextInShape();
ceHelper.checkPlainContent('Hello World'); ceHelper.checkPlainContent('Hello World');
ceHelper.moveCaret('end'); ceHelper.moveCaret('end');
ceHelper.type(' Yellow'); ceHelper.type(' Yellow');
@ -150,7 +149,7 @@ describe(['taga11yenabled'], 'Editable area - Basic typing and caret moving', fu
// select bottom shape and activate editing // select bottom shape and activate editing
selectTextShape(2); selectTextShape(2);
ceHelper.checkHTMLContent(''); ceHelper.checkHTMLContent('');
impressHelper.selectTextOfShape(false); impressHelper.editTextInShape();
ceHelper.checkPlainContent('Green red'); ceHelper.checkPlainContent('Green red');
// remove shape selection // remove shape selection
impressHelper.removeShapeSelection(); impressHelper.removeShapeSelection();

View File

@ -12,7 +12,7 @@ describe(['tagdesktop'], 'Editing Operations', function() {
desktopHelper.switchUIToCompact(); desktopHelper.switchUIToCompact();
desktopHelper.selectZoomLevel('30'); desktopHelper.selectZoomLevel('30');
impressHelper.selectTextShapeInTheCenter(); impressHelper.selectTextShapeInTheCenter();
impressHelper.selectTextOfShape(false); impressHelper.editTextInShape();
}); });
function undo() { function undo() {