diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-07-20 11:48:49 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-07-20 11:48:49 +0200 |
| commit | fa3e89064a503c95ab2b283e5d5b39ca182f8f47 (patch) | |
| tree | d638f0cb99fc973169d670ff0bafd1b9474b4771 /addons/web/static/tests/fields/relational_fields_tests.js | |
| parent | 0ae679e433ee4c5ca32ae1302d87d7fb33e0c78d (diff) | |
| parent | 104dfe3c07d36a6487f045f31d0999cc429cb5bb (diff) | |
[MERGE] forward port branch saas-16 up to 104dfe3c07d
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 104 |
1 files changed, 98 insertions, 6 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index aacbb744252..1a7badd353f 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -1,11 +1,13 @@ odoo.define('web.relational_fields_tests', function (require) { "use strict"; +var BasicModel = require('web.BasicModel'); var concurrency = require('web.concurrency'); var FormView = require('web.FormView'); var ListView = require('web.ListView'); var relationalFields = require('web.relational_fields'); var testUtils = require('web.test_utils'); +var Widget = require('web.Widget'); var createView = testUtils.createView; @@ -361,7 +363,6 @@ QUnit.module('relational_fields', { form.destroy(); }); - QUnit.test('many2one readonly fields with option "no_open"', function (assert) { assert.expect(1); @@ -564,10 +565,71 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('many2one field with option standalone', function (assert) { + assert.expect(3); + var done = assert.async(); + + var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY; + relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0; + + var fixture = $('#qunit-fixture'); + var self = this; + + var model = testUtils.createModel({ + Model: BasicModel, + data: this.data, + }); + + model.makeRecord('coucou', [{ + name: 'partner_id', + relation: 'partner', + type: 'many2one', + value: [1, 'first partner'], + }], { + partner_id: { + options: { + no_open: true, + }, + }, + }).then(function (recordID) { + var record = model.get(recordID); + var parent = new Widget(); + testUtils.addMockEnvironment(parent, { + data: self.data, + mockRPC: function (route, args) { + assert.step(args.method); + return this._super.apply(this, arguments); + }, + }); + + var relField = new relationalFields.FieldMany2One(parent, + 'partner_id', + record, + { + mode: 'edit', + standalone: true, + }); + + relField.appendTo(fixture); + $('input.o_input').val('xyzzrot').trigger('input'); + + concurrency.delay(0).then(function () { + var $dropdown = $('input.o_input').autocomplete('widget'); + $dropdown.find('.o_m2o_dropdown_option:contains(Create)') + .first().mouseenter().click(); + assert.verifySteps(['name_search', 'name_create']); + parent.destroy(); + model.destroy(); + relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY; + done(); + }); + }); + }); + // QUnit.test('onchange on a many2one to a different model', function (assert) { - // This test is commented because the mock server does not give the correct response. - // It should return a couple [id, display_name], but I don't know the logic used - // by the server, so it's hard to emulate it correctly + // This test is commented because the mock server does not give the correct response. + // It should return a couple [id, display_name], but I don't know the logic used + // by the server, so it's hard to emulate it correctly // assert.expect(2); // this.data.partner.records[0].product_id = 41; @@ -995,14 +1057,16 @@ QUnit.module('relational_fields', { assert.deepEqual( args.kwargs.context, {hey: "ho", hello: "world", test: "yop"}, - 'the field attr context should have been used for the ' - + 'RPC (evaluated and merged with the session one)'); + 'the field attr context should have been used for the ' + + 'RPC (evaluated and merged with the session one)'); + return $.when([]); } if (args.method === 'name_search' && args.model === 'partner') { assert.deepEqual(args.kwargs.args, [['id', 'in', [12]]], 'the field attr domain should have been used for the RPC (and evaluated)'); assert.deepEqual(args.kwargs.context, {hey: 'ho', timmy: [[6, false, [12]]]}, 'the field attr context should have been used for the RPC (and evaluated)'); + return $.when([]); } return this._super.apply(this, arguments); }, @@ -3652,6 +3716,34 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('id in one2many obtained in onchange is properly set', function (assert) { + assert.expect(1); + + this.data.partner.onchanges.turtles = function (obj) { + obj.turtles = [ + [5], + [1, 3, {turtle_foo: "kawa"}] + ]; + }; + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<field name="turtles">' + + '<tree>' + + '<field name="id"/>' + + '<field name="turtle_foo"/>' + + '</tree>' + + '</field>' + + '</form>', + }); + + assert.strictEqual(form.$('tr.o_data_row').text(), '3kawa', + "should have properly displayed id and foo field"); + form.destroy(); + }); + QUnit.test('sub form view with a required field', function (assert) { assert.expect(2); this.data.partner.fields.foo.required = true; |
