From 91ea5a2ca449549ba50f12c4a778421510ef84fc Mon Sep 17 00:00:00 2001 From: Julien Mougenot Date: Fri, 23 Aug 2019 10:35:36 +0000 Subject: [REF] web,*: native event dispatching in test utils *: mail,partner_autocomplete: adapted tests Added a new function to trigger the adequate type of event on an element (native JS event to DOM Nodes and jQuery event to jQuery objects), and refactored the generic event-triggering functions to call this new function. --- addons/web/static/tests/fields/basic_fields_tests.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index a67d4e19cbc..112a1c74b7b 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -2967,17 +2967,17 @@ QUnit.module('basic_fields', { // switch to edit mode await testUtils.form.clickEdit(form); // open datepicker and select another value - testUtils.dom.openDatepicker(form.$('.o_datepicker')); - testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch').first()); - testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch:eq(1)')); - testUtils.dom.click($('.bootstrap-datetimepicker-widget .year').eq(11)); - testUtils.dom.click($('.bootstrap-datetimepicker-widget .month').eq(11)); - testUtils.dom.click($('.day:contains(31)')); + await testUtils.dom.openDatepicker(form.$('.o_datepicker')); + await testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch').first()); + await testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch:eq(1)')); + await testUtils.dom.click($('.bootstrap-datetimepicker-widget .year').eq(11)); + await testUtils.dom.click($('.bootstrap-datetimepicker-widget .month').eq(11)); + await testUtils.dom.click($('.day:contains(31)')); var $warn = form.$('.o_datepicker_warning:visible'); assert.strictEqual($warn.length, 1, "should have a warning in the form view"); - testUtils.fields.editSelect(form.$('.o_field_widget[name=date] input'), ''); // remove the value + await testUtils.fields.editSelect(form.$('.o_field_widget[name=date] input'), ''); // remove the value $warn = form.$('.o_datepicker_warning:visible'); assert.strictEqual($warn.length, 0, "the warning in the form view should be hidden"); @@ -3100,7 +3100,7 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('.o_datepicker_input').val(), '02/03/2017', 'the date should be correct in edit mode'); - testUtils.fields.editAndTrigger(form.$('.o_datepicker_input'), '', ['input', 'change', 'focusout']); + await testUtils.fields.editAndTrigger(form.$('.o_datepicker_input'), '', ['input', 'change', 'focusout']); assert.strictEqual(form.$('.o_datepicker_input').val(), '', 'should have correctly removed the value'); -- cgit v1.2.3 From fbbfa6ddcaf5cb8ef75672a73d1a928704484850 Mon Sep 17 00:00:00 2001 From: Harpritsinh Sisodiya Date: Wed, 28 Aug 2019 11:47:37 +0000 Subject: [FIX] web: datepicker: crash on invalid date There is an open issue on the tempusdominus lib: https://github.com/tempusdominus/bootstrap-4/issues/223 It occurs when there is a valid value in a date(time) field, and the user unsets it by setting an invalid one. This rev. fixes the issue in Odoo by preventing to reach the buggy piece of code in the lib. In a few words, when the user sets an invalid date, we reset the previous valid date (which is what the lib tries to do anyway). Task 2057009 closes odoo/odoo#36211 Signed-off-by: Aaron Bohy (aab) Co-authored-by: Aaron Bohy --- .../web/static/tests/fields/basic_fields_tests.js | 39 +++++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 7fae0f7963a..84a5844b8c0 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -2696,8 +2696,32 @@ QUnit.module('basic_fields', { form.destroy(); }); - QUnit.test('date field should remove the date if the date is not valid', function (assert) { - assert.expect(1); + QUnit.test('date field: set an invalid date when the field is already set', function (assert) { + assert.expect(2); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
', + res_id: 1, + viewOptions: { + mode: 'edit', + }, + }); + + var $input = form.$('.o_field_widget[name=date] input'); + + assert.strictEqual($input.val(), "02/03/2017"); + + $input.val('mmmh').trigger('change'); + assert.strictEqual($input.val(), "02/03/2017", "should have reset the original value"); + + form.destroy(); + }); + + QUnit.test('date field: set an invalid date when the field is not set yet', function (assert) { + assert.expect(2); var form = createView({ View: FormView, @@ -2705,13 +2729,18 @@ QUnit.module('basic_fields', { data: this.data, arch: '
', res_id: 4, + viewOptions: { + mode: 'edit', + }, }); - // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); - // set an invalid date + var $input = form.$('.o_field_widget[name=date] input'); + + assert.strictEqual($input.text(), ""); + $input.val('mmmh').trigger('change'); assert.strictEqual($input.text(), "", "The date field should be empty"); + form.destroy(); }); -- cgit v1.2.3 From 707882497b397ce908c49fe0b9ed0e1911f3e6a4 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 6 Sep 2019 10:56:46 +0000 Subject: [FIX] web: tests: load template before FieldColor tests The ColorPickerDialog lazyloads its template. In the test environment, nothing was done (except for a single nextTick) to ensure that the template has been loaded before interacting with the dialog. This led to non deterministic failing runbot builds. Also correctly load the signature template before running its tests instead of doing two chelou nextTick(); closes odoo/odoo#36511 Signed-off-by: David Monjoie (dmo) --- addons/web/static/tests/fields/basic_fields_tests.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 112a1c74b7b..a5620212500 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1,6 +1,7 @@ odoo.define('web.basic_fields_tests', function (require) { "use strict"; +var ajax = require('web.ajax'); var basicFields = require('web.basic_fields'); var concurrency = require('web.concurrency'); var config = require('web.config'); @@ -12,7 +13,6 @@ var session = require('web.session'); var testUtils = require('web.test_utils'); var field_registry = require('web.field_registry'); -var createView = testUtils.createView; var createView = testUtils.createView; var DebouncedField = basicFields.DebouncedField; var JournalDashboardGraph = basicFields.JournalDashboardGraph; @@ -5817,7 +5817,11 @@ QUnit.module('basic_fields', { form.destroy(); }); - QUnit.module('FieldColor'); + QUnit.module('FieldColor', { + before: function () { + return ajax.loadXML('/web/static/src/xml/colorpicker_dialog.xml', core.qweb); + }, + }); QUnit.test('Field Color: default widget state', async function (assert) { assert.expect(3); @@ -5837,7 +5841,6 @@ QUnit.module('basic_fields', { }); await testUtils.dom.click(form.$('.o_field_color')); - await testUtils.nextTick(); assert.containsOnce($, '.modal'); assert.containsNone($('.modal'), '.o_opacity_slider', "Opacity slider should not be present"); -- cgit v1.2.3 From 029dd1a214f727e25b479610df96b7ee94dd8127 Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Tue, 20 Aug 2019 07:46:52 +0000 Subject: [IMP] web: edit translations in new dialog Before this commit, translations were edited in a list view with a filter on the field that needed to be translated. After this commit, the translations for each fields are translated in a dedicated dialog. The changes done to the current language are taken into account immediately, both ways, from the dialog to the form and from the form to the dialog. Translating terms is also available in create mode, the user will be prompted to save before editing a translation Task ID: 2028152 closes odoo/odoo#36185 Signed-off-by: VincentSchippefilt --- .../web/static/tests/fields/basic_fields_tests.js | 70 +++++++++++++++++++--- 1 file changed, 61 insertions(+), 9 deletions(-) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index a5620212500..e8060e23e58 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -124,6 +124,19 @@ QUnit.module('basic_fields', { position: "after", }] }, + "ir.translation": { + fields: { + lang_code: {type: "char"}, + value: {type: "char"}, + res_id: {type: "integer"} + }, + records: [{ + id: 99, + res_id: 37, + value: '', + lang_code: 'en_US' + }] + }, }; } }, function () { @@ -1059,7 +1072,7 @@ QUnit.module('basic_fields', { }); QUnit.test('char field translatable', async function (assert) { - assert.expect(3); + assert.expect(4); this.data.partner.fields.foo.translate = true; @@ -1081,7 +1094,13 @@ QUnit.module('basic_fields', { mockRPC: function (route, args) { if (route === "/web/dataset/call_button" && args.method === 'translate_fields') { assert.deepEqual(args.args, ["partner",1,"foo"], 'should call "call_button" route'); - return Promise.resolve(); + return Promise.resolve({ + domain: [], + context: {search_default_name: 'partnes,foo'}, + }); + } + if (route === "/web/dataset/call_kw/res.lang/get_installed") { + return Promise.resolve([["en_US"], ["fr_BE"]]); } return this._super.apply(this, arguments); }, @@ -1089,10 +1108,27 @@ QUnit.module('basic_fields', { await testUtils.form.clickEdit(form); var $button = form.$('input[type="text"].o_field_char + .o_field_translate'); assert.strictEqual($button.length, 1, "should have a translate button"); + assert.strictEqual($button.text(), 'EN', 'the button should have as test the current language'); await testUtils.dom.click($button); + await testUtils.nextTick(); + + assert.containsOnce($(document), '.modal', 'a translate modal should be visible'); + form.destroy(); - form = await createView({ + _t.database.multi_lang = multiLang; + }); + + QUnit.test('char field translatable in create mode', async function (assert) { + assert.expect(1); + + this.data.partner.fields.foo.translate = true; + + var multiLang = _t.database.multi_lang; + _t.database.multi_lang = true; + + + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1104,8 +1140,8 @@ QUnit.module('basic_fields', { '' + '', }); - $button = form.$('input[type="text"].o_field_char + .o_field_translate'); - assert.strictEqual($button.length, 0, "should not have a translate button in create mode"); + var $button = form.$('input[type="text"].o_field_char + .o_field_translate'); + assert.strictEqual($button.length, 1, "should have a translate button in create mode"); form.destroy(); _t.database.multi_lang = multiLang; @@ -1716,7 +1752,13 @@ QUnit.module('basic_fields', { mockRPC: function (route, args) { if (route === "/web/dataset/call_button" && args.method === 'translate_fields') { assert.deepEqual(args.args, ["partner",1,"txt"], 'should call "call_button" route'); - return Promise.resolve(); + return Promise.resolve({ + domain: [], + context: {search_default_name: 'partnes,foo'}, + }); + } + if (route === "/web/dataset/call_kw/res.lang/get_installed") { + return Promise.resolve([["en_US"], ["fr_BE"]]); } return this._super.apply(this, arguments); }, @@ -1725,9 +1767,19 @@ QUnit.module('basic_fields', { var $button = form.$('textarea + .o_field_translate'); assert.strictEqual($button.length, 1, "should have a translate button"); await testUtils.dom.click($button); + assert.containsOnce($(document), '.modal', 'there should be a translation modal'); form.destroy(); + _t.database.multi_lang = multiLang; + }); + + QUnit.test('text field translatable in create mode', async function (assert) { + assert.expect(1); + + this.data.partner.fields.txt.translate = true; - form = await createView({ + var multiLang = _t.database.multi_lang; + _t.database.multi_lang = true; + var form = await createView({ View: FormView, model: 'partner', data: this.data, @@ -1739,8 +1791,8 @@ QUnit.module('basic_fields', { '' + '', }); - $button = form.$('textarea + .o_field_translate'); - assert.strictEqual($button.length, 0, "should not have a translate button in create mode"); + var $button = form.$('textarea + .o_field_translate'); + assert.strictEqual($button.length, 1, "should have a translate button in create mode"); form.destroy(); _t.database.multi_lang = multiLang; -- cgit v1.2.3