summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields_tests.js
diff options
context:
space:
mode:
authorElkasitu <adt@odoo.com>2017-07-17 11:09:35 +0200
committerElkasitu <adt@odoo.com>2017-07-18 15:12:55 +0200
commite83c3e2678500c9bf2c17b4d23ae9a294ebafaa7 (patch)
treeccdbcd92402deb11b9c68b76689ab8e2448cbd82 /addons/web/static/tests/fields/relational_fields_tests.js
parentf7dd085e80c463c828396408f37c12700fec36de (diff)
[FIX] web: Fix actions for widgets w/o controllers
Execution of actions is usually done with trigger_up, which delegates the action execution to the widget's controller. This is troublesome for actions done on widgets that have no controllers, like widgets in Studio for example. The commit fixes this by adding a standalone option for AbstractFields, if the flag is true when instantiating a widget, the action will be called directly from within the widget object and will not be propagated upwards. A test to verify that this works properly has been added as well
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js70
1 files changed, 66 insertions, 4 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index fdd8ffdd124..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;