summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/chrome/keyboard_navigation_mixin_tests.js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/web/static/tests/chrome/keyboard_navigation_mixin_tests.js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/web/static/tests/chrome/keyboard_navigation_mixin_tests.js')
-rw-r--r--addons/web/static/tests/chrome/keyboard_navigation_mixin_tests.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/addons/web/static/tests/chrome/keyboard_navigation_mixin_tests.js b/addons/web/static/tests/chrome/keyboard_navigation_mixin_tests.js
new file mode 100644
index 00000000..b0c638dd
--- /dev/null
+++ b/addons/web/static/tests/chrome/keyboard_navigation_mixin_tests.js
@@ -0,0 +1,88 @@
+odoo.define('web.keyboard_navigation_mixin_tests', function (require) {
+"use strict";
+
+var KeyboardNavigationMixin = require('web.KeyboardNavigationMixin');
+var testUtils = require('web.test_utils');
+var Widget = require('web.Widget');
+
+QUnit.module('KeyboardNavigationMixin', function () {
+ QUnit.test('aria-keyshortcuts is added on elements with accesskey', async function (assert) {
+ assert.expect(1);
+ var $target = $('#qunit-fixture');
+ var KeyboardWidget = Widget.extend(KeyboardNavigationMixin, {
+ init: function () {
+ this._super.apply(this, arguments);
+ KeyboardNavigationMixin.init.call(this);
+ },
+ start: function () {
+ KeyboardNavigationMixin.start.call(this);
+ var $button = $('<button>').text('Click Me!').attr('accesskey', 'o');
+ // we need to define the accesskey because it will not be assigned on invisible buttons
+ this.$el.append($button);
+ return this._super.apply(this, arguments);
+ },
+ destroy: function () {
+ KeyboardNavigationMixin.destroy.call(this);
+ return this._super(...arguments);
+ },
+ });
+ var parent = await testUtils.createParent({});
+ var w = new KeyboardWidget(parent);
+ await w.appendTo($target);
+
+ // minimum set of attribute to generate a native event that works with the mixin
+ var e = new Event("keydown");
+ e.key = '';
+ e.altKey = true;
+ w.$el[0].dispatchEvent(e);
+
+ assert.ok(w.$el.find('button[aria-keyshortcuts]')[0], 'the aria-keyshortcuts is set on the button');
+
+ parent.destroy();
+ });
+
+ QUnit.test('keep CSS position absolute for parent of overlay', async function (assert) {
+ // If we change the CSS position of an 'absolute' element to 'relative',
+ // we may likely change its position on the document. Since the overlay
+ // CSS position is 'absolute', it will match the size and cover the
+ // parent with 'absolute' > 'absolute', without altering the position
+ // of the parent on the document.
+ assert.expect(1);
+ var $target = $('#qunit-fixture');
+ var $button;
+ var KeyboardWidget = Widget.extend(KeyboardNavigationMixin, {
+ init: function () {
+ this._super.apply(this, arguments);
+ KeyboardNavigationMixin.init.call(this);
+ },
+ start: function () {
+ KeyboardNavigationMixin.start.call(this);
+ $button = $('<button>').text('Click Me!').attr('accesskey', 'o');
+ // we need to define the accesskey because it will not be assigned on invisible buttons
+ this.$el.append($button);
+ return this._super.apply(this, arguments);
+ },
+ destroy: function () {
+ KeyboardNavigationMixin.destroy.call(this);
+ return this._super(...arguments);
+ },
+ });
+ var parent = await testUtils.createParent({});
+ var w = new KeyboardWidget(parent);
+ await w.appendTo($target);
+
+ $button.css('position', 'absolute');
+
+ // minimum set of attribute to generate a native event that works with the mixin
+ var e = new Event("keydown");
+ e.key = '';
+ e.altKey = true;
+ w.$el[0].dispatchEvent(e);
+
+ assert.strictEqual($button.css('position'), 'absolute',
+ "should not have kept the CSS position of the button");
+
+ parent.destroy();
+ });
+});
+});