From 84ef209535adaed68904e1ef989162d74444ee83 Mon Sep 17 00:00:00 2001 From: Arnaud Buchholz Date: Fri, 29 Nov 2024 16:42:46 -0500 Subject: [PATCH] test: check UI5 focus use case --- .../{ui5-focus.js => ui5-focus}/index.html | 21 ++++++++++++------- .../{ui5-focus.js => ui5-focus}/index.js | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) rename src/capabilities/tests/{ui5-focus.js => ui5-focus}/index.html (77%) rename src/capabilities/tests/{ui5-focus.js => ui5-focus}/index.js (57%) diff --git a/src/capabilities/tests/ui5-focus.js/index.html b/src/capabilities/tests/ui5-focus/index.html similarity index 77% rename from src/capabilities/tests/ui5-focus.js/index.html rename to src/capabilities/tests/ui5-focus/index.html index 069db72..f25e990 100644 --- a/src/capabilities/tests/ui5-focus.js/index.html +++ b/src/capabilities/tests/ui5-focus/index.html @@ -63,20 +63,27 @@ this.getView().setModel(model); // Set focus on the second row this.getView().byId("myTable").attachEventOnce("updateFinished", function() { - this.getItems()[1].focus(); - // Notify the test framework - const xhr = new XMLHttpRequest(); - xhr.open('POST', '/_/log'); - xhr.send('{}'); // TODO how do we assess focus is correctly set ? + // Need to do it asynchronously or the first item is selected instead + setTimeout(() => { + const listItem = this.getItems()[1]; + listItem.focus(); + + // Notify the test framework + const xhr = new XMLHttpRequest(); + xhr.open('POST', '/_/log'); + xhr.send(JSON.stringify({ + 'is-focus-set': document.activeElement.id === listItem.getFocusDomRef()?.id, + })); + }, 0); }); } }); XMLView.create({definition: jQuery('#myXml').html()}).then(function (oView) { - oView.placeAt("content"); + oView.placeAt(document.querySelector('body')); }); }); - + diff --git a/src/capabilities/tests/ui5-focus.js/index.js b/src/capabilities/tests/ui5-focus/index.js similarity index 57% rename from src/capabilities/tests/ui5-focus.js/index.js rename to src/capabilities/tests/ui5-focus/index.js index 489bf2c..de332b4 100644 --- a/src/capabilities/tests/ui5-focus.js/index.js +++ b/src/capabilities/tests/ui5-focus/index.js @@ -3,9 +3,9 @@ const assert = require('assert') module.exports = [{ - label: 'Loads a page which requires the focus', + label: 'UI5 focus handling', url: 'ui5-focus/index.html', endpoint: ({ body }) => { - assert.strictEqual(body['sap.m.Button'], true) + assert.strictEqual(body['is-focus-set'], true) } }]