diff options
| author | Christophe Matthieu <chm@odoo.com> | 2017-12-06 10:09:02 +0100 |
|---|---|---|
| committer | Martin Geubelle <mge@odoo.com> | 2018-01-05 17:34:25 +0100 |
| commit | b7ee1aa4b1ea906195c234020cb708a1da9de6a7 (patch) | |
| tree | d6c7263b6b4f40e89ede6b3a55b86909e9ffba15 /addons/web/static/tests/fields/relational_fields_tests.js | |
| parent | d3cebdc4a2c8cb5c31cc56a79821b09a4d4712a8 (diff) | |
[FIX] web: sort and onchange in tabbed editable x2m
Two attempts of dealing with sorting (and resequencing) in tabbed (multi-pages)
x2many editable lists (see odoo/odoo@c2563db and odoo/odoo@983c7ae) have been
previously done, using a static attribute (`keepChangesUnsorted`) on the
datapoint.
This solution sadly only covers both cases separately, not if they are combined.
Morever, onchanges were not correctly managed in neither of these two cases.
A new approach is used here, by "freezing" and "unfreezing" the datapoint when
needed, which is more flexible.
Some modifications have been introduced:
- when ordering a x2many, all records are now considered (and not only the
records on the current page) ; an additional read is thus done on the sorted
field for all records in the x2many relation
- `setSort` is now asynchronous as a `read` might be needed
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 175 |
1 files changed, 160 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 505d0e0571e..208f00298d3 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -2271,7 +2271,7 @@ QUnit.module('relational_fields', { }); QUnit.test('embedded one2many with handle widget', function (assert) { - assert.expect(7); + assert.expect(8); this.data.partner.records[0].turtles = [1, 2, 3]; @@ -2321,6 +2321,15 @@ QUnit.module('relational_fields', { "should have the 3 rows in the new order"); form.$buttons.find('.o_form_button_save').click(); + + assert.deepEqual(_.map(this.data.turtle.records, function(turtle) { + return _.pick(turtle, 'id', 'turtle_foo', 'turtle_int'); + }), [ + {id: 1, turtle_foo: "yop", turtle_int: 1}, + {id: 2, turtle_foo: "blip", turtle_int:0}, + {id: 3, turtle_foo: "kawa", turtle_int:21} + ], "should have save the changed sequence"); + assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "blipyopkawa", "should still have the 3 rows in the new order"); @@ -2415,7 +2424,7 @@ QUnit.module('relational_fields', { res_id: 1, mockRPC: function (route, args) { if (args.method === 'write') { - assert.deepEqual(args.args[1].turtles, [[1,1,{"turtle_int":2}],[4,2,false],[1,3,{"turtle_int":3}]], + assert.deepEqual(args.args[1].turtles, [[4,2,false],[1,1,{"turtle_int":2}],[1,3,{"turtle_int":3}]], "should change all lines that have changed (the first one doesn't change because it has the same sequence)"); } return this._super.apply(this, arguments); @@ -2444,9 +2453,20 @@ QUnit.module('relational_fields', { }); QUnit.test('onchange (with command 5) for embedded one2many with handle widget', function (assert) { - assert.expect(2); + assert.expect(3); - this.data.partner.records[0].turtles = [1, 2, 3]; + var ids = []; + for (var i=10; i<50; i++) { + var id = 10 + i; + ids.push(id); + this.data.turtle.records.push({ + id: id, + turtle_int: 0, + turtle_foo: "#" + id, + }); + } + ids.push(1, 2, 3); + this.data.partner.records[0].turtles = ids; this.data.partner.onchanges = { turtles: function (obj) { obj.turtles = [[5]].concat(obj.turtles); @@ -2472,6 +2492,7 @@ QUnit.module('relational_fields', { res_id: 1, }); + form.$('.o_pager_next').click(); assert.strictEqual(form.$('td.o_data_cell:not(.o_handle_cell)').text(), "yopblipkawa", "should have the 3 rows in the correct order"); @@ -2486,7 +2507,10 @@ QUnit.module('relational_fields', { {position: 'top'} ); + assert.strictEqual(form.$('.o_data_cell').text(), "blurpkawablip", "should display to record in 'turtle_int' order"); + form.$buttons.find('.o_form_button_save').click(); + form.$('.o_pager_next').click(); assert.strictEqual(form.$('.o_data_cell:not(.o_handle_cell)').text(), "blurpkawablip", "should display to record in 'turtle_int' order"); @@ -2494,6 +2518,126 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('onchange followed by edition on the second page', function (assert) { + assert.expect(20); + + var ids = []; + for (var i=1; i<85; i++) { + var id = 10 + i; + ids.push(id); + this.data.turtle.records.push({ + id: id, + turtle_int: id/3|0, + turtle_foo: "#" + i, + }); + } + ids.splice(41, 0, 1, 2, 3); + this.data.partner.records[0].turtles = ids; + this.data.partner.onchanges = { + turtles: function (obj) { + obj.turtles = [[5]].concat(obj.turtles); + }, + }; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'<form string="Partners">' + + '<sheet>' + + '<group>' + + '<field name="turtles">' + + '<tree editable="top" default_order="turtle_int">' + + '<field name="turtle_int" widget="handle"/>' + + '<field name="turtle_foo"/>' + + '</tree>' + + '</field>' + + '</group>' + + '</sheet>' + + '</form>', + res_id: 1, + }); + + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_pager_next').click(); + + form.$('.o_field_one2many .o_list_view tbody tr:eq(1) td:first').click(); + form.$('.o_field_one2many .o_list_view tbody tr:eq(1) input:first').val('value 1').trigger('input'); + form.$('.o_field_one2many .o_list_view tbody tr:eq(2) td:first').click(); + form.$('.o_field_one2many .o_list_view tbody tr:eq(2) input:first').val('value 2').trigger('input'); + + assert.strictEqual(form.$('.o_data_row').length, 40, "should display 40 records"); + assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#39))').index(), 0, "should display '#39' at the first line"); + + form.$('.o_field_x2many_list_row_add a').click(); + + assert.strictEqual(form.$('.o_data_row').length, 40, "should display 39 records and the create line"); + assert.strictEqual(form.$('.o_data_row:first .o_field_char').length, 1, "should display the create line in first position"); + assert.strictEqual(form.$('.o_data_row:first .o_field_char').val(), "", "should an empty input"); + assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#39))').index(), 1, "should display '#39' at the second line"); + + form.$('.o_data_row input:first').val('value 3').trigger('input'); + + assert.strictEqual(form.$('.o_data_row:first .o_field_char').length, 1, "should display the create line in first position after onchange"); + assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#39))').index(), 1, "should display '#39' at the second line after onchange"); + + form.$('.o_field_x2many_list_row_add a').click(); + + assert.strictEqual(form.$('.o_data_row').length, 40, "should display 39 records and the create line"); + assert.strictEqual(form.$('.o_data_row:first .o_field_char').length, 1, "should display the create line in first position"); + assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(value 3))').index(), 1, "should display the created line at the second position"); + assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#39))').index(), 2, "should display '#39' at the third line"); + + form.destroy(); + + // bottom order + + form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'<form string="Partners">' + + '<sheet>' + + '<group>' + + '<field name="turtles">' + + '<tree editable="bottom" default_order="turtle_int">' + + '<field name="turtle_int" widget="handle"/>' + + '<field name="turtle_foo"/>' + + '</tree>' + + '</field>' + + '</group>' + + '</sheet>' + + '</form>', + res_id: 1, + }); + + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_pager_next').click(); + + form.$('.o_field_one2many .o_list_view tbody tr:eq(1) td:first').click(); + form.$('.o_field_one2many .o_list_view tbody tr:eq(1) input:first').val('value 1').trigger('input'); + form.$('.o_field_one2many .o_list_view tbody tr:eq(2) td:first').click(); + form.$('.o_field_one2many .o_list_view tbody tr:eq(2) input:first').val('value 2').trigger('input'); + + assert.strictEqual(form.$('.o_data_row').length, 40, "should display 40 records"); + assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#77))').index(), 39, "should display '#77' at the last line"); + + form.$('.o_field_x2many_list_row_add a').click(); + + assert.strictEqual(form.$('.o_data_row').length, 40, "should display 39 records and the create line"); + assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#76))').index(), 38, "should display '#76' at the penultimate line"); + assert.strictEqual(form.$('.o_data_row:has(.o_field_char)').index(), 39, "should display the create line at the last position"); + + form.$('.o_data_row input:first').val('value 3').trigger('input'); + form.$('.o_field_x2many_list_row_add a').click(); + + assert.strictEqual(form.$('.o_data_row').length, 40, "should display 39 records and the create line"); + assert.strictEqual(form.$('.o_data_row:has(.o_data_cell:contains(#76))').index(), 38, "should display '#76' at the penultimate line"); + assert.strictEqual(form.$('.o_data_row:has(.o_field_char)').index(), 39, "should display the create line at the last position"); + + form.destroy(); + }); + QUnit.test('embedded one2many with handle widget with minimum setValue calls', function (assert) { var done = assert.async(); assert.expect(20); @@ -5656,9 +5800,9 @@ QUnit.module('relational_fields', { // enable the many2many onchange and generate it form.$('input.o_field_integer[name="int_field"]').val('10').trigger('input'); - assert.strictEqual(form.$('.o_data_cell.o_required_modifier').text(), "xphonexenomorphe", + assert.strictEqual(form.$('.o_data_cell.o_required_modifier').text(), "xenomorphexphone", 'should display the product xphone and xenomorphe'); - assert.strictEqual(form.$('.o_data_row').text().replace(/\s+/g, ' '), "new linexphone first record firstxenomorphe second record ", + assert.strictEqual(form.$('.o_data_row').text().replace(/\s+/g, ' '), "firstxenomorphe second record new linexphone first record ", 'should display the name, one2many and many2many value'); // disable the many2many onchange @@ -5688,19 +5832,19 @@ QUnit.module('relational_fields', { // put list in readonly mode form.$('input.o_field_integer[name="int_field"]').click(); - assert.strictEqual(form.$('.o_data_cell.o_required_modifier').text(), "xphonexenomorphe", + assert.strictEqual(form.$('.o_data_cell.o_required_modifier').text(), "xenomorphexphone", 'should display the product xphone and xenomorphe'); - assert.strictEqual(form.$('.o_field_many2manytags:not(.o_input) .o_badge_text').text(), "first recordsecond record", + assert.strictEqual(form.$('.o_field_many2manytags:not(.o_input) .o_badge_text').text(), "second recordfirst record", 'should display the tag in readonly (first record and second record)'); form.$('input.o_field_integer[name="int_field"]').val('10').trigger('input'); - assert.strictEqual(form.$('.o_data_row').text().replace(/\s+/g, ' '), "new linexphone first record firstxenomorphe second record ", + assert.strictEqual(form.$('.o_data_row').text().replace(/\s+/g, ' '), "firstxenomorphe second record new linexphone first record ", 'should display the name, one2many and many2many value'); form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.o_data_row').text().replace(/\s+/g, ' '), "new linexphone first record firstxenomorphe second record ", + assert.strictEqual(form.$('.o_data_row').text().replace(/\s+/g, ' '), "firstxenomorphe second record new linexphone first record ", 'should display the name, one2many and many2many value after save'); form.destroy(); @@ -6838,8 +6982,8 @@ QUnit.module('relational_fields', { mockRPC: function (route, args) { assert.step(args.method); if (args.method === 'write') { - assert.strictEqual(args.args[1].turtles[42][0], 0); - assert.deepEqual(args.args[1].turtles[42][2], {turtle_foo: 'rainbow dash'}); + assert.strictEqual(args.args[1].turtles[40][0], 0, 'should send a create command'); + assert.deepEqual(args.args[1].turtles[40][2], {turtle_foo: 'rainbow dash'}); } return this._super.apply(this, arguments); }, @@ -6892,8 +7036,8 @@ QUnit.module('relational_fields', { mockRPC: function (route, args) { assert.step(args.method); if (args.method === 'write') { - assert.strictEqual(args.args[1].turtles[0][0], 0); - assert.deepEqual(args.args[1].turtles[0][2], {turtle_foo: 'rainbow dash'}); + assert.strictEqual(args.args[1].turtles[40][0], 0); + assert.deepEqual(args.args[1].turtles[40][2], {turtle_foo: 'rainbow dash'}); } return this._super.apply(this, arguments); }, @@ -6909,7 +7053,8 @@ QUnit.module('relational_fields', { form.$('.o_field_x2many_list_row_add a').click(); assert.strictEqual(form.$('tr.o_data_row').length, 3, - "should have 3 data rows on the current page"); + "should have 3 data rows on the current page (2 records and the created line)"); + assert.ok(form.$('tr.o_data_row').first().hasClass('o_selected_row'), "first row should be selected"); |
