From 497dfb691774bd7b893e836584482980b0d1be79 Mon Sep 17 00:00:00 2001 From: Adrien Dieudonne Date: Fri, 26 Oct 2018 12:02:59 +0000 Subject: [PATCH] [MOV] web, base_import: mobile tests should be in mobile suite This fix some inconsistent error on runbot. In mobile, some views* depend on 'jquery.touchSwipe' library which is lazy loaded. As a result, the views become asynchronous... It's why this library is already loaded before running tests in the mobile test suite. So we can continue to use synchronous views whether in mobile tests or not. But some mobile tests weren't in mobile suite... In desktop, 'jquery.touchSwipe' is lazy loaded and the first test will load it for others. It's why the first one has to be asynchronous: https://github.com/odoo/odoo/commit/da7b59045d246c159f93bc75e3f19c6b1221d31c The inconsistency comes from the fact that all tests are sequential but we can't garantee the execution order. So, if the test mentionned is not the first executed one, an error will occur because the view is not asynchronous. Now, all mobile tests are moved in mobile suite to be sure that 'jquery.touchSwipe' is loaded. We also set the default value for size_class because we want a coherent environment. It is very rare to find mobile devices with more than 474px wide. *: form_view, kanban_view, res_config_settings closes odoo/odoo#28195 --- .../tests/import_buttons_mobile_tests.js | 56 +++++++++++++++++++ .../static/tests/import_buttons_tests.js | 47 ---------------- .../views/base_import_templates.xml | 7 ++- addons/web/static/tests/helpers/test_utils.js | 1 - addons/web/views/webclient_templates.xml | 1 + 5 files changed, 63 insertions(+), 49 deletions(-) create mode 100644 addons/base_import/static/tests/import_buttons_mobile_tests.js diff --git a/addons/base_import/static/tests/import_buttons_mobile_tests.js b/addons/base_import/static/tests/import_buttons_mobile_tests.js new file mode 100644 index 00000000000..ac3410b9369 --- /dev/null +++ b/addons/base_import/static/tests/import_buttons_mobile_tests.js @@ -0,0 +1,56 @@ +odoo.define('web.base_import_mobile_tests', function (require) { +"use strict"; + +var KanbanView = require('web.KanbanView'); +var ListView = require('web.ListView'); +var testUtils = require('web.test_utils'); + +var createView = testUtils.createView; + +QUnit.module('Base Import Mobile Tests', { + beforeEach: function () { + this.data = { + foo: { + fields: { + foo: {string: "Foo", type: "char"}, + }, + }, + }; + } +}); + +QUnit.test('import button should be hidden in list on mobile screens', function (assert) { + assert.expect(1); + + var list = createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: '', + }); + + assert.notOk(list.$buttons.find('.o_button_import').is(':visible'), + "import button should be hidden"); + list.destroy(); +}); + +QUnit.test('import button should be hidden in kanban on mobile screens', function (assert) { + assert.expect(1); + + var kanban = createView({ + View: KanbanView, + model: 'foo', + data: this.data, + arch: '' + + '
' + + '' + + '
' + + '
', + }); + + assert.notOk(kanban.$buttons.find('.o_button_import').is(':visible'), + "import button should be hidden"); + kanban.destroy(); +}); + +}); diff --git a/addons/base_import/static/tests/import_buttons_tests.js b/addons/base_import/static/tests/import_buttons_tests.js index 049c43fe8a0..e5326c1d25e 100644 --- a/addons/base_import/static/tests/import_buttons_tests.js +++ b/addons/base_import/static/tests/import_buttons_tests.js @@ -1,7 +1,6 @@ odoo.define('web.base_import_tests', function (require) { "use strict"; -var config = require('web.config'); var KanbanView = require('web.KanbanView'); var ListView = require('web.ListView'); var testUtils = require('web.test_utils'); @@ -107,50 +106,4 @@ QUnit.test('kanban without import button', function(assert) { kanban.destroy(); }); -QUnit.test('import button should be hidden in list on mobile screens', function (assert) { - assert.expect(1); - - var list = createView({ - View: ListView, - model: 'foo', - data: this.data, - arch: '', - config: { - device: { - size_class: config.device.SIZES.XS, - }, - }, - }); - - assert.notOk(list.$buttons.find('.o_button_import').is(':visible'), "import button should be hidden"); - list.destroy(); -}); - -QUnit.test('import button should be hidden in kanban on mobile screens', function (assert) { - assert.expect(1); - var done = assert.async(); - - // the kanban view is async in mobile mode, because it has to load an - // external additional library - testUtils.createAsyncView({ - View: KanbanView, - model: 'foo', - data: this.data, - arch: '' + - '
' + - '' + - '
' + - '
', - config: { - device: { - size_class: config.device.SIZES.XS, - }, - }, - }).then(function (kanban){ - assert.notOk(kanban.$buttons.find('.o_button_import').is(':visible'), "import button should be hidden"); - kanban.destroy(); - done(); - }); -}); - }); diff --git a/addons/base_import/views/base_import_templates.xml b/addons/base_import/views/base_import_templates.xml index fdb8e5f0d2b..2b4670f3805 100644 --- a/addons/base_import/views/base_import_templates.xml +++ b/addons/base_import/views/base_import_templates.xml @@ -10,11 +10,16 @@ - + + diff --git a/addons/web/static/tests/helpers/test_utils.js b/addons/web/static/tests/helpers/test_utils.js index 6b8ddfee91b..f20f183d799 100644 --- a/addons/web/static/tests/helpers/test_utils.js +++ b/addons/web/static/tests/helpers/test_utils.js @@ -438,7 +438,6 @@ function addMockEnvironment(widget, params) { initialConfig.device = _.clone(config.device); if ('device' in params.config) { _.extend(config.device, params.config.device); - config.device.isMobile = config.device.size_class <= config.device.SIZES.VSM; } if ('debug' in params.config) { config.debug = params.config.debug; diff --git a/addons/web/views/webclient_templates.xml b/addons/web/views/webclient_templates.xml index 80284eda520..4e9c32d5385 100644 --- a/addons/web/views/webclient_templates.xml +++ b/addons/web/views/webclient_templates.xml @@ -583,6 +583,7 @@ define.call(this, 'web.config.patch', function (require) { var config = require('web.config'); config.device.isMobile = true; + config.device.size_class = config.device.SIZES.XS; }); } };