From c89cdcf11c66e80c33cd77edceaee7eb59a704b3 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 31 Mar 2021 09:08:16 +0000 Subject: [PATCH] [FIX] web: tests: patch form multiClickTime once for all A lot of tests in different QUnit modules need this delay to be patched to 0. Some of them (e.g. the 'ActionManager > Misc' module) didn't patch it correctly. It worked before because a patch was done in a previous test, and wasn't unpatch. The previous commit ensures the patch is removed, so now we have at least 2 tests of the above mentionned module that fail. This commit ensures that the delay is patched in every tests, and allows to specify a custom delay if necessary. --- .../web/static/tests/fields/basic_fields_tests.js | 7 ------- .../relational_fields/field_many2one_tests.js | 7 ------- .../relational_fields/field_one2many_tests.js | 7 ------- .../static/tests/fields/relational_fields_tests.js | 7 ------- addons/web/static/tests/helpers/test_utils_mock.js | 7 +++++++ addons/web/static/tests/views/form_tests.js | 13 +------------ addons/web_editor/static/tests/field_html_tests.js | 4 ---- 7 files changed, 8 insertions(+), 44 deletions(-) diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index b9789ba94c3..ba86b2896f4 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -151,13 +151,6 @@ QUnit.module('basic_fields', { }] }, }; - - testUtils.mock.patch(FormController, { - 'multiClickTime': 0, - }); - }, - afterEach() { - testUtils.mock.unpatch(FormController); }, }, function () { diff --git a/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js b/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js index 500b61eed1f..07cbcd1c224 100644 --- a/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js +++ b/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js @@ -152,13 +152,6 @@ QUnit.module('fields', {}, function () { }] }, }; - - testUtils.mock.patch(FormController, { - 'multiClickTime': 0, - }); - }, - afterEach: function () { - testUtils.mock.unpatch(FormController); }, }, function () { QUnit.module('FieldMany2One'); diff --git a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js index 2a09ebd1f98..e50c8dff3de 100644 --- a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js +++ b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js @@ -164,13 +164,6 @@ QUnit.module('fields', {}, function () { }] }, }; - - testUtils.mock.patch(FormController, { - 'multiClickTime': 0, - }); - }, - afterEach: function () { - testUtils.mock.unpatch(FormController); }, }, function () { QUnit.module('FieldOne2Many'); diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index cb9718169d4..8b70ca78d0a 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -170,13 +170,6 @@ QUnit.module('relational_fields', { onchanges: {}, }, }; - - testUtils.mock.patch(FormController, { - 'multiClickTime': 0, - }); - }, - afterEach: function () { - testUtils.mock.unpatch(FormController); }, }, function () { diff --git a/addons/web/static/tests/helpers/test_utils_mock.js b/addons/web/static/tests/helpers/test_utils_mock.js index 962b9610f4b..c7bc927fbe3 100644 --- a/addons/web/static/tests/helpers/test_utils_mock.js +++ b/addons/web/static/tests/helpers/test_utils_mock.js @@ -17,6 +17,7 @@ const Bus = require('web.Bus'); const config = require('web.config'); const core = require('web.core'); const dom = require('web.dom'); +const FormController = require('web.FormController'); const makeTestEnvironment = require('web.test_env'); const MockServer = require('web.MockServer'); const RamStorage = require('web.RamStorage'); @@ -366,6 +367,10 @@ async function addMockEnvironmentOwl(Component, params, mockServer) { }); } + // remove the multi-click delay for the quick edit in form view + const initialQuickEditDelay = FormController.prototype.multiClickTime; + FormController.prototype.multiClickTime = params.formMultiClickTime || 0; + // make sure the debounce value for input fields is set to 0 const initialDebounceValue = DebouncedField.prototype.DEBOUNCE; DebouncedField.prototype.DEBOUNCE = params.fieldDebounce || 0; @@ -425,6 +430,8 @@ async function addMockEnvironmentOwl(Component, params, mockServer) { } }); + FormController.prototype.multiClickTime = initialQuickEditDelay; + DebouncedField.prototype.DEBOUNCE = initialDebounceValue; dom.DEBOUNCE = initialDOMDebounceValue; _.debounce = initialDebounce; diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index f0ef47fb36b..383f036f5ba 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -152,13 +152,6 @@ QUnit.module('Views', { type: 'ir.actions.act_window', views: [[false, 'kanban'], [false, 'form']], }]; - - testUtils.mock.patch(FormController, { - 'multiClickTime': 0, - }); - }, - afterEach: function () { - testUtils.mock.unpatch(FormController); }, }, function () { @@ -11112,10 +11105,6 @@ QUnit.module('Views', { const MULTI_CLICK_TIME = 50; - testUtils.mock.patch(FormController, { - 'multiClickTime': MULTI_CLICK_TIME, - }); - const form = await createView({ View: FormView, model: 'partner', @@ -11126,6 +11115,7 @@ QUnit.module('Views', { `, + formMultiClickTime: MULTI_CLICK_TIME, res_id: 1, }); @@ -11157,7 +11147,6 @@ QUnit.module('Views', { await concurrency.delay(MULTI_CLICK_TIME); assert.containsOnce(form, '.o_form_view.o_form_editable'); - testUtils.mock.unpatch(FormController); form.destroy(); }); diff --git a/addons/web_editor/static/tests/field_html_tests.js b/addons/web_editor/static/tests/field_html_tests.js index bb8e509a054..62c754a07b4 100644 --- a/addons/web_editor/static/tests/field_html_tests.js +++ b/addons/web_editor/static/tests/field_html_tests.js @@ -121,13 +121,9 @@ QUnit.module('web_editor', {}, function () { throw 'Wrong template'; }, }); - testUtils.mock.patch(FormController, { - 'multiClickTime': 0, - }); }, afterEach: function () { testUtils.mock.unpatch(ajax); - testUtils.mock.unpatch(FormController); }, }, function () {