From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- .../barcodes/static/tests/barcode_mobile_tests.js | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 addons/barcodes/static/tests/barcode_mobile_tests.js (limited to 'addons/barcodes/static/tests/barcode_mobile_tests.js') diff --git a/addons/barcodes/static/tests/barcode_mobile_tests.js b/addons/barcodes/static/tests/barcode_mobile_tests.js new file mode 100644 index 00000000..c030af9c --- /dev/null +++ b/addons/barcodes/static/tests/barcode_mobile_tests.js @@ -0,0 +1,76 @@ +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 = $( + '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
' + + '' + + '
'); + $('#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(); + }); + }); + }); -- cgit v1.2.3