diff options
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 77 |
1 files changed, 62 insertions, 15 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index b981a4241c6..f21db07f088 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -1070,7 +1070,9 @@ QUnit.module('relational_fields', { assert.deepEqual( obj.turtles, [ + [4, 2, false], [1, 2, {turtle_foo: 'blip'}], + [4, 3, false], [1, 3, {turtle_foo: 'kawa'}] ], "should have properly created the x2many command list"); @@ -1099,7 +1101,9 @@ QUnit.module('relational_fields', { // unchanged state with the command 1, but this seems more // difficult. assert.deepEqual(args.args[0].turtles, [ + [4, 2, false], [1, 2, {turtle_foo: 'blip'}], + [4, 3, false], [1, 3, {turtle_foo: 'kawa'}] ], 'should send proper commands to create method'); } @@ -6474,10 +6478,50 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('default value for nested one2manys (coming from onchange)', function (assert) { + assert.expect(3); + + this.data.partner.onchanges.p = function (obj) { + obj.p = [ + [5], + [0, 0, {turtles: [[5], [4, 1]]}], // link record 1 by default + ]; + }; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form>' + + '<sheet>' + + '<field name="p">' + + '<tree><field name="turtles"/></tree>' + + '</field>' + + '</sheet>' + + '</form>', + mockRPC: function (route, args) { + if (args.method === 'create') { + assert.strictEqual(args.args[0].p[0][0], 0, + "should send a command 0 (CREATE) for p"); + assert.deepEqual(args.args[0].p[0][2], {turtles: [[4, 1, false]]}, + "should send the correct values"); + } + return this._super.apply(this, arguments); + }, + }); + + assert.strictEqual(form.$('.o_data_cell').text(), '1 record', + "should correctly display the value of the inner o2m"); + + form.$buttons.find('.o_form_button_save').click(); + + form.destroy(); + }); + QUnit.test('display correct value after validation error', function (assert) { assert.expect(4); - this.data.partner.onchanges.turtles = true; + this.data.partner.onchanges.turtles = function () { }; var form = createView({ View: FormView, @@ -6494,17 +6538,17 @@ QUnit.module('relational_fields', { '</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.args[1].turtles[0][2].turtle_foo === 'pinky') { + // 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(); + 'should send the "good" value'); } return this._super.apply(this, arguments); }, @@ -6514,21 +6558,25 @@ QUnit.module('relational_fields', { assert.strictEqual(form.$('.o_data_row .o_data_cell:nth(0)').text(), 'blip', "initial text should be correct"); + + // click and edit value to 'foo', which will trigger onchange form.$('.o_data_row .o_data_cell:nth(0)').click(); form.$('.o_field_widget[name=turtle_foo]').val('foo').trigger('input'); + form.$el.click(); + assert.strictEqual(form.$('.o_data_row .o_data_cell:nth(0)').text(), 'foo', + "field should have been changed to foo"); - // 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. + // click and edit value to 'pinky', which trigger a failed onchange + form.$('.o_data_row .o_data_cell:nth(0)').click(); + form.$('.o_field_widget[name=turtle_foo]').val('pinky').trigger('input'); 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)"); + "turtle_foo text should now be set back to foo"); // 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(); }); @@ -6628,7 +6676,6 @@ QUnit.module('relational_fields', { form.destroy(); }); - QUnit.module('FieldMany2Many'); QUnit.test('many2many kanban: edition', function (assert) { |
