From 7ea6f653df0863e9c0dbaf0b07800c0277b962b1 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 26 Jun 2017 09:04:25 +0200 Subject: [FIX] web: MonetaryField: rerender with currency The MonetaryField can be rendered with or without a currency. The currency can change during the lifecyle of the widget (e.g. currency field in the view, whose value is set by an onchange). More precisely, the widget can be instantiated without currency, then a change on another field can trigger an onchange which sets the currency, and our monetary widget is re-rendered with a currency. Before this rev., this wasn't supported in edit mode because the $el's root node was different if there were a currency or not (it was an input if there were no currency, and a div containing an input and a span otherwise). This root node being rendered only once (at the creation of the widget), the widget wasn't re-rendered correctly if the currency was suddenly set or unset. This fix makes the widget behave uniformly whether or not there is a currency, so now it is always a div containing an input (and optionally a span if there is a currency). --- .../web/static/tests/fields/basic_fields_tests.js | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) (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 c492537c63f..8f26c922a83 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1973,6 +1973,63 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('monetary field with currency set by an onchange', function (assert) { + // this test ensures that the monetary field can be re-rendered with and + // without currency (which can happen as the currency can be set by an + // onchange) + assert.expect(8); + + this.data.partner.onchanges = { + int_field: function (obj) { + obj.currency_id = obj.int_field ? 2 : null; + }, + }; + + var list = createView({ + View: ListView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '' + + '' + + '', + session: { + currencies: _.indexBy(this.data.currency.records, 'id'), + }, + }); + + list.$buttons.find('.o_list_button_add').click(); + assert.strictEqual(list.$('div.o_field_widget[name=qux] input').length, 1, + "monetary field should have been rendered correctly (without currency)"); + assert.strictEqual(list.$('.o_field_widget[name=qux] span').length, 0, + "monetary field should have been rendered correctly (without currency)"); + + // set a value for int_field -> should set the currency and re-render qux + list.$('.o_field_widget[name=int_field]').click().val('7').trigger('input'); + assert.strictEqual(list.$('div.o_field_widget[name=qux] input').length, 1, + "monetary field should have been re-rendered correctly (with currency)"); + assert.strictEqual(list.$('.o_field_widget[name=qux] span:contains(€)').length, 1, + "monetary field should have been re-rendered correctly (with currency)"); + var $quxInput = list.$('.o_field_widget[name=qux] input'); + $quxInput.click(); // check that the field is focusable + assert.strictEqual(document.activeElement, $quxInput[0], + "focus should be on the qux field's input"); + + // unset the value of int_field -> should unset the currency and re-render qux + list.$('.o_field_widget[name=int_field]').click().val('0').trigger('input'); + $quxInput = list.$('div.o_field_widget[name=qux] input'); + assert.strictEqual($quxInput.length, 1, + "monetary field should have been re-rendered correctly (without currency)"); + assert.strictEqual(list.$('.o_field_widget[name=qux] span').length, 0, + "monetary field should have been re-rendered correctly (without currency)"); + $quxInput.click(); // check that the field is still focusable + assert.strictEqual(document.activeElement, $quxInput[0], + "focus should be on the qux field's input"); + + list.destroy(); + }); + QUnit.module('FieldInteger'); QUnit.test('integer field when unset', function (assert) { -- cgit v1.2.3 From 157732cfb15d743c66c36a1bdcb350026a0473e4 Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Tue, 27 Jun 2017 17:56:00 +0200 Subject: [FIX] web: FieldText: keep editing the textarea after enter In the editable list, when pressing enter, the cursor goes to the next line and the current row is saved. This should not be the case for a textarea (i.e. in the FieldText widget). In this particular case, we just want to continue editing the textarea. --- .../web/static/tests/fields/basic_fields_tests.js | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (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 8f26c922a83..50daedb7dcb 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1043,6 +1043,40 @@ QUnit.module('basic_fields', { _t.database.multi_lang = multiLang; }); + QUnit.test('go to next line (and not the next row) when pressing enter', function (assert) { + assert.expect(4); + + this.data.partner.fields.foo.type = 'text'; + var list = createView({ + View: ListView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '' + + '' + + '', + }); + + list.$('tbody tr:first .o_list_text').click(); + var $textarea = list.$('textarea.o_field_text'); + assert.strictEqual($textarea.length, 1, "should have a text area"); + assert.strictEqual($textarea.val(), 'yop', 'should still be "yop" in edit'); + + assert.strictEqual(list.$('textarea').get(0), document.activeElement, + "text area should have the focus"); + + // click on enter + list.$('textarea') + .trigger({type: "keydown", which: $.ui.keyCode.ENTER}) + .trigger({type: "keyup", which: $.ui.keyCode.ENTER}); + + assert.strictEqual(list.$('textarea').first().get(0), document.activeElement, + "text area should still have the focus"); + + list.destroy(); + }); + QUnit.module('FieldBinary'); QUnit.test('binary fields are correctly rendered', function (assert) { -- cgit v1.2.3 From 514c8e5cd3adeed1427745a80ee6d368bda63692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 29 Jun 2017 11:30:09 +0200 Subject: [FIX] web: prevent dirty state after test The test changed in this commit had a big issue: it did not properly destroy the second form view that it created. Because of that, it was still alive and could interact with other tests, such as the barcode tests. This is what happened: 1. var form was assigned to a form view 2. form was destroyed 3. in a try catch, form was reassigned to the result of createView, but the evaluation of createView crashed (after creating a form view), so the assignation was not done, and the var form was still pointing to the first form view 4. form.destroy is called, which did nothing for the second form view. There is no easy way to get the reference to the form view created by createView without changing some other code, so we simply remove the second part of the test, which was not particularly important. --- addons/web/static/tests/fields/basic_fields_tests.js | 10 +--------- 1 file changed, 1 insertion(+), 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 50daedb7dcb..c732fe35ce6 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -2115,7 +2115,7 @@ QUnit.module('basic_fields', { }); QUnit.test('integer field in form view with virtual id', function (assert) { - assert.expect(2); + assert.expect(1); var params = { View: FormView, model: 'partner', @@ -2127,15 +2127,7 @@ QUnit.module('basic_fields', { var form = createView(params); assert.strictEqual(form.$('.o_field_widget').text(), "2-20170808020000", "Should display virtual id"); - form.destroy(); - params.res_id = this.data.partner.records[1].id = "2.65-20170808020000"; - try { - form = createView(params); - } catch (error) { - assert.strictEqual(error.message, '"2.65-20170808020000" is not an integer or a virtual id', - "Should throw an exception because it's a wrong value"); - } form.destroy(); }); -- cgit v1.2.3