diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-10-21 15:22:36 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-10-21 15:22:36 +0200 |
| commit | de987831da237ed5f9c96d50a9e51d083e072aa0 (patch) | |
| tree | ef714d2d98693eae3446620d28bb48314573018a /addons/web/static/tests/fields | |
| parent | ea2a976f31b2611b6b4ff69f4a5cdc2ffc7798fe (diff) | |
| parent | d70518d04f8f8061c8c683ea4ba8c95ae631ae45 (diff) | |
[MERGE] forward port branch 11.0 up to d70518d04f8
Diffstat (limited to 'addons/web/static/tests/fields')
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 106 | ||||
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 168 |
2 files changed, 267 insertions, 7 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index f01f2d8b589..1e623e54d9a 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1462,6 +1462,42 @@ QUnit.module('basic_fields', { } }); + QUnit.module('FieldImage'); + + QUnit.test('image fields are correctly rendered', function (assert) { + assert.expect(5); + + this.data.partner.records[0].document = 'myimage'; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<field name="document" widget="image" options="{\'size\': [90, 90]}"/> ' + + '</form>', + res_id: 1, + mockRPC: function (route) { + if (route === 'data:image/png;base64,myimage') { + assert.ok(true, "should called the correct route"); + return $.when('wow'); + } + return this._super.apply(this, arguments); + }, + }); + + assert.ok(form.$('div[name="document"]').hasClass('o_field_image'), + "the widget should have the correct class"); + assert.strictEqual(form.$('div[name="document"] > img').length, 1, + "the widget should contain an image"); + assert.ok(form.$('div[name="document"] > img').hasClass('img-responsive'), + "the image should have the correct class"); + assert.strictEqual(form.$('div[name="document"] > img').attr('width'), "90", + "the image should correctly set its attributes"); + form.destroy(); + + }); + QUnit.module('JournalDashboardGraph'); QUnit.test('graph dashboard widget is rendered correctly', function (assert) { @@ -1844,6 +1880,39 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('do not trigger a field_changed for datetime field with date widget', function (assert) { + assert.expect(3); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'<form string="Partners"><field name="datetime" widget="date"/></form>', + translateParameters: { // Avoid issues due to localization formats + date_format: '%m/%d/%Y', + time_format: '%H:%M:%S', + }, + res_id: 1, + viewOptions: { + mode: 'edit', + }, + mockRPC: function (route, args) { + assert.step(args.method); + return this._super.apply(this, arguments); + }, + }); + + assert.strictEqual(form.$('.o_datepicker_input').val(), '02/08/2017', + 'the date should be correct'); + + form.$('input[name="datetime"]').val('02/08/2017').trigger('input').trigger('change'); + form.$buttons.find('.o_form_button_save').click(); + + assert.verifySteps(['read']); // should not have save as nothing changed + + form.destroy(); + }); + QUnit.module('FieldDatetime'); QUnit.test('datetime field in form view', function (assert) { @@ -2828,6 +2897,33 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('use TAB to navigate to a phone field', function (assert) { + assert.expect(2); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'<form string="Partners">' + + '<sheet>' + + '<group>' + + '<field name="display_name"/>' + + '<field name="foo" widget="phone"/>' + + '</group>' + + '</sheet>' + + '</form>', + }); + + form.$('input[name=display_name]').click(); + assert.strictEqual(form.$('input[name="display_name"]')[0], document.activeElement, + "display_name should be focused"); + form.$('input[name="display_name"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); + assert.strictEqual(form.$('input[name="foo"]')[0], document.activeElement, + "foo should be focused"); + + form.destroy(); + }); + QUnit.module('PriorityWidget'); QUnit.test('priority widget when not set', function (assert) { @@ -3939,7 +4035,7 @@ QUnit.module('basic_fields', { }); QUnit.test('domain field: handle false domain as []', function (assert) { - assert.expect(2); + assert.expect(3); this.data.partner.records[0].foo = false; this.data.partner.fields.bar.type = "char"; @@ -3965,11 +4061,13 @@ QUnit.module('basic_fields', { return this._super.apply(this, arguments); }, res_id: 1, - viewOptions: { - mode: 'edit', - }, }); + assert.strictEqual(form.$('.o_field_widget[name=foo]:not(.o_field_empty)').length, 1, + "there should be a domain field, not considered empty"); + + form.$buttons.find('.o_form_button_edit').click(); + var $warning = form.$('.o_field_widget[name=foo] .text-warning'); assert.strictEqual($warning.length, 0, "should not display that the domain is invalid"); diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 641546b3fc1..2d328f0b7ff 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -1064,14 +1064,14 @@ QUnit.module('relational_fields', { }); QUnit.test('list in form: default_get with x2many create and onchange', function (assert) { - assert.expect(1); + assert.expect(2); this.data.partner.onchanges.turtles = function (obj) { assert.deepEqual( obj.turtles, [ - [0, 2, {turtle_foo: 'blip', id: 2}], - [0, 3, {turtle_foo: 'kawa', id: 3}] + [1, 2, {turtle_foo: 'blip'}], + [1, 3, {turtle_foo: 'kawa'}] ], "should have properly created the x2many command list"); }; @@ -1094,10 +1094,21 @@ QUnit.module('relational_fields', { if (args.method === 'default_get') { return $.when({turtles: [[6, 0, [2,3]]]}); } + if (args.method === 'create') { + // it would be even better if we did not send the current + // unchanged state with the command 1, but this seems more + // difficult. + assert.deepEqual(args.args[0].turtles, [ + [1, 2, {turtle_foo: 'blip'}], + [1, 3, {turtle_foo: 'kawa'}] + ], 'should send proper commands to create method'); + } return this._super.apply(this, arguments); }, }); + form.$buttons.find('.o_form_button_save').click(); + form.destroy(); }); @@ -6248,6 +6259,35 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('checkbox in an x2many that triggers an onchange', function (assert) { + assert.expect(1); + + this.data.partner.onchanges = { + bar: function () {} + }; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<field name="p">' + + '<tree editable="bottom">' + + '<field name="bar"/>' + + '</tree>' + + '</field>' + + '</form>', + }); + + form.$('.o_field_x2many_list_row_add a').click(); + + form.$('.o_field_widget[name=bar] input').click(); + assert.notOk(form.$('.o_field_widget[name=bar] input').prop('checked'), + "the checkbox should be unticked"); + + form.destroy(); + }); + QUnit.test('one2many with default value: edit line to make it invalid', function (assert) { assert.expect(3); @@ -6284,6 +6324,66 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('display correct value after validation error', function (assert) { + assert.expect(4); + + this.data.partner.onchanges.turtles = true; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form>' + + '<sheet>' + + '<field name="turtles">' + + '<tree editable="bottom">' + + '<field name="turtle_foo"/>' + + '</tree>' + + '</field>' + + '</sheet>' + + '</form>', + mockRPC: function (route, args) { + if (args.method === 'onchange') { + // we simulate a validation error. In the 'real' web client, + // the server error will be used by the session to display + // an error dialog. From the point of view of the basic + // model, the deferred is just rejected. + return $.Deferred().reject(); + } + if (args.method === 'write') { + assert.deepEqual(args.args[1].turtles[0], [1,2,{turtle_foo: 'foo'}], + 'should send the "bad" value'); + // we simulate a validation error + return $.Deferred().reject(); + } + return this._super.apply(this, arguments); + }, + viewOptions: {mode: 'edit'}, + res_id: 1, + }); + + assert.strictEqual(form.$('.o_data_row .o_data_cell:nth(0)').text(), 'blip', + "initial text should be correct"); + form.$('.o_data_row .o_data_cell:nth(0)').click(); + form.$('.o_field_widget[name=turtle_foo]').val('foo').trigger('input'); + + // we try to validate the line. This triggers an onchange which will be + // rejected. The line will be returned to readonly mode, but with the + // new invalid value. + form.$el.click(); + + assert.strictEqual(form.$('.o_data_row .o_data_cell:nth(0)').text(), 'foo', + "turtle_foo text should now be foo (invalid value)"); + + // we make sure here that when we save, the values are the current + // values displayed in the field. + form.$buttons.find('.o_form_button_save').click(); + assert.strictEqual(form.mode, 'edit', "form view should still be in edit mode"); + + form.destroy(); + }); + + QUnit.module('FieldMany2Many'); QUnit.test('many2many kanban: edition', function (assert) { @@ -7128,6 +7228,42 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('default_get, onchange, onchange on m2m', function (assert) { + assert.expect(1); + + this.data.partner.onchanges.int_field = function (obj) { + if (obj.int_field === 2) { + assert.deepEqual(obj.timmy, [ + [6, false, [12]], + [1, 12, {display_name: 'gold'}] + ]); + } + obj.timmy = [ + [5], + [1, 12, {display_name: 'gold'}] + ]; + }; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form>' + + '<sheet>' + + '<field name="timmy">' + + '<tree>' + + '<field name="display_name"/>' + + '</tree>' + + '</field>' + + '<field name="int_field"/>' + + '</sheet>' + + '</form>', + }); + + form.$('.o_field_widget[name=int_field]').val(2).trigger('input'); + form.destroy(); + }); + QUnit.module('FieldStatus'); QUnit.test('static statusbar widget on many2one field', function (assert) { @@ -8288,6 +8424,32 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('widget many2many_checkboxes: start non empty, then remove twice', function (assert) { + assert.expect(2); + + this.data.partner.records[0].timmy = [12,14]; + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'<form string="Partners">' + + '<group><field name="timmy" widget="many2many_checkboxes"/></group>' + + '</form>', + res_id: 1, + viewOptions: {mode: 'edit'}, + }); + + form.$('div.o_field_widget div.o_checkbox input').eq(0).click(); + form.$('div.o_field_widget div.o_checkbox input').eq(1).click(); + form.$buttons.find('.o_form_button_save').click(); + assert.notOk(form.$('div.o_field_widget div.o_checkbox input').eq(0).prop('checked'), + "first checkbox should not be checked"); + assert.notOk(form.$('div.o_field_widget div.o_checkbox input').eq(1).prop('checked'), + "second checkbox should not be checked"); + + form.destroy(); + }); + QUnit.module('FieldMany2ManyBinaryMultiFiles'); QUnit.test('widget many2many_binary', function (assert) { |
