summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields_tests.js
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2017-10-25 14:57:24 +0200
committerChristophe Simonis <chs@odoo.com>2017-10-25 14:57:24 +0200
commit693f8dc68add34663f798370b4aea305f573f16d (patch)
treedbd47871d9412317dc96fd4ba349196badab199c /addons/web/static/tests/fields/relational_fields_tests.js
parentc7a6409fac80a2d33006ab56fe40d27f2acd2cfd (diff)
parent7bfde6e05d12be959d04f4842237bfcc05f3c93f (diff)
[MERGE] forward port branch saas-16 up to 7bfde6e05d1
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js208
1 files changed, 194 insertions, 14 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index 2d328f0b7ff..594dd6103d5 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -2003,9 +2003,10 @@ QUnit.module('relational_fields', {
});
QUnit.test('embedded one2many with handle widget', function (assert) {
- assert.expect(8);
+ assert.expect(7);
+
+ this.data.partner.records[0].turtles = [1, 2, 3];
- this.data.partner.records[0].p = [1, 2, 4];
var form = createView({
View: FormView,
model: 'partner',
@@ -2014,10 +2015,10 @@ QUnit.module('relational_fields', {
'<sheet>' +
'<notebook>' +
'<page string="P page">' +
- '<field name="p">' +
- '<tree default_order="int_field">' +
- '<field name="int_field" widget="handle"/>' +
- '<field name="foo"/>' +
+ '<field name="turtles">' +
+ '<tree default_order="turtle_int">' +
+ '<field name="turtle_int" widget="handle"/>' +
+ '<field name="turtle_foo"/>' +
'</tree>' +
'</field>' +
'</page>' +
@@ -2028,14 +2029,14 @@ QUnit.module('relational_fields', {
});
testUtils.intercept(form, "field_changed", function (event) {
- assert.step(event.data.changes.p.data.int_field.toString());
+ assert.step(event.data.changes.turtles.data.turtle_int.toString());
}, true);
- assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "My little Foo Valueblipyop",
+ assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "yopblipkawa",
"should have the 3 rows in the correct order");
form.$buttons.find('.o_form_button_edit').click();
- assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "My little Foo Valueblipyop",
+ assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "yopblipkawa",
"should still have the 3 rows in the correct order");
// Drag and drop the fourth line in second position
@@ -2045,21 +2046,169 @@ QUnit.module('relational_fields', {
{position: 'top'}
);
- assert.verifySteps(["0", "1", "2"],
+ assert.verifySteps(["0", "1"],
"sequences values should be incremental starting from the previous minimum one");
- assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "blipMy little Foo Valueyop",
+ assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "blipyopkawa",
"should have the 3 rows in the new order");
form.$buttons.find('.o_form_button_save').click();
- assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "blipMy little Foo Valueyop",
+ assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "blipyopkawa",
"should still have the 3 rows in the new order");
form.destroy();
});
+ QUnit.test('onchange for embedded one2many with handle widget', function (assert) {
+ assert.expect(2);
+
+ this.data.partner.records[0].turtles = [1, 2, 3];
+ var partnerOnchange = 0;
+ this.data.partner.onchanges = {
+ turtles: function (obj) {
+ partnerOnchange++;
+ },
+ };
+ var turtleOnchange = 0;
+ this.data.turtle.onchanges = {
+ turtle_int: function (obj) {
+ turtleOnchange++;
+ },
+ };
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<sheet>' +
+ '<notebook>' +
+ '<page string="P page">' +
+ '<field name="turtles">' +
+ '<tree default_order="turtle_int">' +
+ '<field name="turtle_int" widget="handle"/>' +
+ '<field name="turtle_foo"/>' +
+ '</tree>' +
+ '</field>' +
+ '</page>' +
+ '</notebook>' +
+ '</sheet>' +
+ '</form>',
+ res_id: 1,
+ });
+
+ form.$buttons.find('.o_form_button_edit').click();
+
+ // Drag and drop the fourth line in second position
+ testUtils.dragAndDrop(
+ form.$('.ui-sortable-handle').eq(1),
+ form.$('tbody tr').first(),
+ {position: 'top'}
+ );
+
+ assert.strictEqual(turtleOnchange, 2, "should trigger one onchange per line updated");
+ assert.strictEqual(partnerOnchange, 1, "should trigger only one onchange on the parent");
+
+ form.destroy();
+ });
+
+ QUnit.test('embedded one2many with handle widget with minimum setValue calls', function (assert) {
+ var done = assert.async();
+ assert.expect(20);
+
+
+ this.data.turtle.records[0].turtle_int = 6;
+ this.data.turtle.records.push({
+ id: 4,
+ turtle_int: 20,
+ turtle_foo: "a1",
+ }, {
+ id: 5,
+ turtle_int: 9,
+ turtle_foo: "a2",
+ }, {
+ id: 6,
+ turtle_int: 2,
+ turtle_foo: "a3",
+ }, {
+ id: 7,
+ turtle_int: 11,
+ turtle_foo: "a4",
+ });
+ this.data.partner.records[0].turtles = [1, 2, 3, 4, 5, 6, 7];
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<sheet>' +
+ '<notebook>' +
+ '<page string="P page">' +
+ '<field name="turtles">' +
+ '<tree default_order="turtle_int">' +
+ '<field name="turtle_int" widget="handle"/>' +
+ '<field name="turtle_foo"/>' +
+ '</tree>' +
+ '</field>' +
+ '</page>' +
+ '</notebook>' +
+ '</sheet>' +
+ '</form>',
+ res_id: 1,
+ });
+
+ testUtils.intercept(form, "field_changed", function (event) {
+ assert.step(form.model.get(event.data.changes.turtles.id).res_id);
+ }, true);
+
+ form.$buttons.find('.o_form_button_edit').click();
+
+ var steps = [];
+ var positions = [
+ [6, 0, 'top', [3, 6, 1, 2, 5, 7, 4]], // move the last to the first line
+ [5, 1, 'top', [7, 6, 1, 2, 5]], // move the penultimate to the second line
+ [2, 5, 'center', [1, 2, 5, 6]], // move the third to the penultimate line
+ ];
+ function dragAndDrop() {
+ var pos = positions.shift();
+
+ testUtils.dragAndDrop(
+ form.$('.ui-sortable-handle').eq(pos[0]),
+ form.$('tbody tr').eq(pos[1]),
+ {position: pos[2]}
+ );
+
+ steps = steps.concat(pos[3]);
+ assert.verifySteps(steps,
+ "sequences values should be apply from the begin index to the drop index");
+
+ if (positions.length) {
+
+ setTimeout(dragAndDrop, 10);
+
+ } else {
+
+ assert.deepEqual(_.pluck(form.model.get(form.handle).data.turtles.data, 'data'), [
+ { id: 3, turtle_foo: "kawa", turtle_int: 2 },
+ { id: 7, turtle_foo: "a4", turtle_int: 3 },
+ { id: 1, turtle_foo: "yop", turtle_int: 4 },
+ { id: 2, turtle_foo: "blip", turtle_int: 5 },
+ { id: 5, turtle_foo: "a2", turtle_int: 6 },
+ { id: 6, turtle_foo: "a3", turtle_int: 7 },
+ { id: 4, turtle_foo: "a1", turtle_int: 8 }
+ ], "sequences must be apply correctly");
+
+ form.destroy();
+ done();
+ }
+ }
+
+ dragAndDrop();
+ });
+
QUnit.test('embedded one2many (editable list) with handle widget', function (assert) {
- assert.expect(9);
+ assert.expect(8);
this.data.partner.records[0].p = [1, 2, 4];
var form = createView({
@@ -2101,7 +2250,7 @@ QUnit.module('relational_fields', {
{position: 'top'}
);
- assert.verifySteps(["0", "1", "2"],
+ assert.verifySteps(["0", "1"],
"sequences values should be incremental starting from the previous minimum one");
assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "blipMy little Foo Valueyop",
@@ -5904,6 +6053,7 @@ QUnit.module('relational_fields', {
if (args.method === 'read' && args.model === 'partner_type') {
assert.deepEqual(args.kwargs.context, {
key: 'yop',
+ active_field: 2,
someKey: 'some value',
}, "sent context should be correct");
}
@@ -6383,6 +6533,36 @@ QUnit.module('relational_fields', {
form.destroy();
});
+ QUnit.test('propagate context to sub views', function (assert) {
+ assert.expect(5);
+
+ 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) {
+ assert.strictEqual(args.kwargs.context.flutter, 'shy',
+ 'view context key should be used for every rpcs');
+ return this._super.apply(this, arguments);
+ },
+ viewOptions: {context: {flutter: 'shy'}},
+ });
+ form.$('.o_field_x2many_list_row_add a').click();
+ form.$('input[name="turtle_foo"]').val('pinky pie').trigger('input');
+ form.$buttons.find('.o_form_button_save').click();
+
+ form.destroy();
+ });
+
QUnit.module('FieldMany2Many');