Since the QUnit config is more strict as to what is allowed to stay in the DOM after tests, a test has been updated to clean its elements before the test ends. closes odoo/odoo#53705 X-original-commit: 33b567a777a69a4da627ff1d62b46ad09127f86d Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Signed-off-by: Julien Mougenot (jum) <jum@odoo.com>
77 lines
3.2 KiB
JavaScript
77 lines
3.2 KiB
JavaScript
odoo.define('barcodes.barcode_mobile_tests', function () {
|
|
"use strict";
|
|
|
|
QUnit.module('Barcodes', {}, function () {
|
|
|
|
QUnit.module('Barcodes Mobile');
|
|
|
|
QUnit.test('barcode field automatically focus behavior', function (assert) {
|
|
assert.expect(10);
|
|
|
|
// Mock Chrome mobile environment
|
|
var barcodeEvents = odoo.__DEBUG__.services["barcodes.BarcodeEvents"].BarcodeEvents;
|
|
var __isChromeMobile = barcodeEvents.isChromeMobile;
|
|
barcodeEvents.isChromeMobile = true;
|
|
// Rebind keyboard events
|
|
barcodeEvents.stop();
|
|
barcodeEvents.start();
|
|
|
|
var $form = $(
|
|
'<form>' +
|
|
'<input name="email" type="email"/>' +
|
|
'<input name="number" type="number"/>' +
|
|
'<input name="password" type="password"/>' +
|
|
'<input name="tel" type="tel"/>' +
|
|
'<input name="text"/>' +
|
|
'<input name="explicit_text" type="text"/>' +
|
|
'<textarea></textarea>' +
|
|
'<div contenteditable="true"></div>' +
|
|
'<select name="select">' +
|
|
'<option value="option1">Option 1</option>' +
|
|
'<option value="option2">Option 2</option>' +
|
|
'</select>' +
|
|
'</form>');
|
|
$('#qunit-fixture').append($form);
|
|
|
|
// Some elements doesn't need to keep the focus
|
|
$('body').keydown();
|
|
assert.strictEqual(document.activeElement.name, 'barcode',
|
|
"hidden barcode input should have the focus");
|
|
|
|
var $element = $form.find('select');
|
|
$element.focus().keydown();
|
|
assert.strictEqual(document.activeElement.name, 'barcode',
|
|
"hidden barcode input should have the focus");
|
|
|
|
// Those elements absolutely need to keep the focus:
|
|
// inputs elements:
|
|
var keepFocusedElements = ['email', 'number', 'password', 'tel',
|
|
'text', 'explicit_text'];
|
|
for (var i = 0; i < keepFocusedElements.length; ++i) {
|
|
$element = $form.find('input[name=' + keepFocusedElements[i] + ']');
|
|
$element.focus().keydown();
|
|
assert.strictEqual(document.activeElement, $element[0],
|
|
"input " + keepFocusedElements[i] + " should keep focus");
|
|
}
|
|
// textarea element
|
|
$element = $form.find('textarea');
|
|
$element.focus().keydown();
|
|
assert.strictEqual(document.activeElement, $element[0],
|
|
"textarea should keep focus");
|
|
// contenteditable elements
|
|
$element = $form.find('[contenteditable=true]');
|
|
$element.focus().keydown();
|
|
assert.strictEqual(document.activeElement, $element[0],
|
|
"contenteditable should keep focus");
|
|
|
|
$('#qunit-fixture').empty();
|
|
barcodeEvents.isChromeMobile = __isChromeMobile;
|
|
// Rebind keyboard events
|
|
barcodeEvents.stop();
|
|
barcodeEvents.start();
|
|
|
|
document.querySelector('input[name=barcode]').remove();
|
|
});
|
|
});
|
|
});
|