Skip to content

Commit 638954a

Browse files
committed
Add test for pressing enter in a treeview in a dialog
I don't care if the dialog closes or stays open, but if it stays open then the focus should stay in the dialog. Pressing enter poses a problem with chrome during cypress tests with CDP where the form submission default isn't blocked as it is normally. So added a bodge around for that so the issue can be property tested. Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com> Change-Id: I5e241ea91f7467643b4a9c63eb1ea045df8527fa
1 parent eba80da commit 638954a

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

cypress_test/integration_tests/common/helper.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,36 @@ function waitForMapState(command, expectedValue) {
13381338
cy.log('<< waitForMapState - end');
13391339
}
13401340

1341+
// cy.realPress('Enter') via CDP bypasses preventDefault on keydown,
1342+
// which causes implicit form submission and spurious button clicks
1343+
// that don't happen with real keyboard input. This helper blocks
1344+
// those side effects for a single keypress.
1345+
function realPressInDialog(key) {
1346+
cy.cGet('.jsdialog-window form').then($form => {
1347+
// Block implicit form submission for this keypress
1348+
function blockSubmit(e) {
1349+
e.preventDefault();
1350+
e.stopImmediatePropagation();
1351+
}
1352+
$form[0].addEventListener('submit', blockSubmit, true);
1353+
1354+
// Block the close button from being clicked
1355+
var closeBtn = $form[0].querySelector('.ui-dialog-titlebar-close');
1356+
var origOnclick = closeBtn ? closeBtn.onclick : null;
1357+
if (closeBtn) {
1358+
closeBtn.onclick = function(e) {
1359+
e.preventDefault();
1360+
e.stopImmediatePropagation();
1361+
};
1362+
}
1363+
1364+
cy.realPress(key).then(() => {
1365+
$form[0].removeEventListener('submit', blockSubmit, true);
1366+
if (closeBtn) closeBtn.onclick = origOnclick;
1367+
});
1368+
});
1369+
}
1370+
13411371
module.exports.setupDocument = setupDocument;
13421372
module.exports.loadDocument = loadDocument;
13431373
module.exports.setupAndLoadDocument = setupAndLoadDocument;
@@ -1395,6 +1425,7 @@ module.exports.waitForTimers = waitForTimers;
13951425
module.exports.waitForMapState = waitForMapState;
13961426
module.exports.maxScreenshotableViewportHeight = maxScreenshotableViewportHeight;
13971427
module.exports.getMatchedCSSRules = getMatchedCSSRules;
1428+
module.exports.realPressInDialog = realPressInDialog;
13981429

13991430
// Find all author CSS rules that match an element, with the source
14001431
// stylesheet filename and the full selector for each matching rule.

cypress_test/integration_tests/desktop/writer/a11y_dialog_spec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,54 @@ describe(['tagdesktop'], 'Accessibility Writer Dialog Tests', { testIsolation: f
187187
});
188188
});
189189

190+
it('Treeview Enter key keeps focus in dialog', function () {
191+
cy.then(function () {
192+
win.app.map.sendUnoCommand('.uno:ChapterNumberingDialog');
193+
});
194+
195+
a11yHelper.getActiveDialog(1)
196+
.then(() => helper.processToIdle(win))
197+
.then(() => {
198+
cy.cGet('#level .ui-treeview-entry:nth-child(1)').click();
199+
return helper.processToIdle(win);
200+
})
201+
.then(() => {
202+
cy.cGet('#level .ui-treeview-entry:nth-child(1)').should('have.class', 'selected');
203+
cy.cGet('#level .ui-treeview-entry:nth-child(1)').focus();
204+
205+
// Move to second entry
206+
cy.realPress('ArrowDown');
207+
return helper.processToIdle(win);
208+
})
209+
.then(() => {
210+
cy.cGet('#level .ui-treeview-entry:nth-child(2)').should('have.class', 'selected');
211+
cy.cGet('#level .ui-treeview-entry:nth-child(2)').should('have.focus');
212+
213+
// Press Enter on the focused entry
214+
helper.realPressInDialog('Enter');
215+
return helper.processToIdle(win);
216+
})
217+
.then(() => {
218+
// Either dialog should still exist with focus inside it,
219+
// or dialog should have closed (OK activated)
220+
cy.cGet('body').then($body => {
221+
const dialogExists = $body.find('.ui-dialog[role="dialog"]').length > 0;
222+
if (dialogExists) {
223+
// Dialog still open - focus must be inside it
224+
cy.cGet('.ui-dialog[role="dialog"]').then($dlg => {
225+
const activeEl = win.document.activeElement;
226+
const focusInDialog = $dlg[0].contains(activeEl);
227+
const focusDesc = activeEl.tagName + '#' + activeEl.id + '.' + activeEl.className;
228+
expect(focusInDialog, 'focus should stay in dialog, but is on: ' + focusDesc).to.be.true;
229+
});
230+
cy.cGet('#cancel-button').click();
231+
} else {
232+
cy.log('Dialog closed after Enter');
233+
}
234+
});
235+
});
236+
});
237+
190238
it('Treeview arrow key moves focus and selection together', function () {
191239
cy.then(function () {
192240
win.app.map.sendUnoCommand('.uno:ChapterNumberingDialog');

0 commit comments

Comments
 (0)