From 064d7f462122bd5193e094d8b03c132cb43d14a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Fri, 24 Feb 2017 11:53:28 +0100 Subject: [FIX] web: make focus tests works if window has not the focus Until now, those tests failed if the window did not have the focus. We solve the issue with 2 different fixes: * instead of checking that the focus property is set, we can check the activeElement instead, it seems to work. * instead of calling the focus method, in some tests, we can trigger a * 'focusin' event. I don't know why this works, but it does. Note that this might make the tests work in phantomjs --- addons/web/static/test/fields/basic_fields_tests.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'addons/web/static/test/fields/basic_fields_tests.js') diff --git a/addons/web/static/test/fields/basic_fields_tests.js b/addons/web/static/test/fields/basic_fields_tests.js index 0d03b98e467..cdba48ceff3 100644 --- a/addons/web/static/test/fields/basic_fields_tests.js +++ b/addons/web/static/test/fields/basic_fields_tests.js @@ -333,8 +333,8 @@ QUnit.module('basic_fields', { list.$buttons.find('.o_list_button_add').click(); - assert.ok(list.$('textarea').first().is(':focus'), - "text area should have the focus (make sure the test window had the focus)"); + assert.strictEqual(list.$('textarea').first().get(0), document.activeElement, + "text area should have the focus"); }); @@ -538,8 +538,8 @@ QUnit.module('basic_fields', { assert.strictEqual(list.$('input.o_datepicker_input').length, 1, "the view should have a date input for editable mode"); - assert.ok(list.$('input.o_datepicker_input').is(':focus'), - "date input should have the focus (make sure the test window had the focus)"); + assert.strictEqual(list.$('input.o_datepicker_input').get(0), document.activeElement, + "date input should have the focus"); }); QUnit.module('FieldDomain'); @@ -581,7 +581,7 @@ QUnit.module('basic_fields', { // Focusing the field selector input should open the field selector // popover - $fieldSelector.find("> input").focus(); + $fieldSelector.find("> input").trigger('focusin'); var $fieldSelectorPopover = $fieldSelector.find(".o_field_selector_popover"); assert.ok($fieldSelectorPopover.is(":visible"), "field selector popover should be visible"); @@ -646,7 +646,7 @@ QUnit.module('basic_fields', { "there should be a field selector"); // Focusing its input should open the field selector popover - $fieldSelector.find("> input").focus(); + $fieldSelector.find("> input").trigger('focusin'); var $fieldSelectorPopover = $fieldSelector.find(".o_field_selector_popover"); assert.ok($fieldSelectorPopover.is(":visible"), "field selector popover should be visible"); @@ -671,7 +671,7 @@ QUnit.module('basic_fields', { // Refocusing the field selector input should open the popover again $fieldSelector = form.$(".o_field_selector"); - $fieldSelector.find("> input").focus(); + $fieldSelector.find("> input").trigger('focusin'); $fieldSelectorPopover = $fieldSelector.find(".o_field_selector_popover"); assert.ok($fieldSelectorPopover.is(":visible"), "field selector popover should be visible"); -- cgit v1.2.3