diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-09-06 13:29:05 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-09-06 13:29:05 +0200 |
| commit | b8dd34fcbb895b8d62f3e133dcf5ee6f40a1400d (patch) | |
| tree | 196c99a14d51d88a2f81f12be98fb8ff2c4359f7 /addons/web/static/tests | |
| parent | 16541ae2ae953195f1bd0036e474aac0014aee4b (diff) | |
| parent | 64d56995e049d7e7bc3aa7af5a16603220b0d4bc (diff) | |
[MERGE] forward port branch saas-16 up to 64d56995e04
Diffstat (limited to 'addons/web/static/tests')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 113 | ||||
| -rw-r--r-- | addons/web/static/tests/views/basic_model_tests.js | 34 | ||||
| -rw-r--r-- | addons/web/static/tests/views/list_tests.js | 147 |
3 files changed, 294 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 6337d74326e..5b356ac25c3 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -1474,6 +1474,7 @@ QUnit.module('relational_fields', { assert.strictEqual($('.modal').length, 1, "should have one modal in body"); form.destroy(); + relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY; done(); }); }); @@ -5406,6 +5407,118 @@ QUnit.module('relational_fields', { }); + QUnit.test('editing tabbed one2many (editable=bottom)', function (assert) { + assert.expect(11); + + this.data.partner.records[0].turtles = []; + for (var i = 0; i < 42; i++) { + var id = 100 + i; + this.data.turtle.records.push({id: id, turtle_foo: 'turtle' + (id-99)}); + this.data.partner.records[0].turtles.push(id); + } + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'<form string="Partners">' + + '<sheet>' + + '<field name="turtles">' + + '<tree editable="bottom">' + + '<field name="turtle_foo"/>' + + '</tree>' + + '</field>' + + '</sheet>' + + '</form>', + res_id: 1, + mockRPC: function (route, args) { + assert.step(args.method); + if (args.method === 'write') { + assert.deepEqual(args.args[1].turtles[42], [0, false, {turtle_foo: 'rainbow dash'}]); + } + return this._super.apply(this, arguments); + }, + }); + + + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_field_x2many_list_row_add a').click(); + + assert.strictEqual(form.$('tr.o_data_row').length, 41, + "should have 41 data rows on the current page"); + assert.ok(form.$('tr.o_data_row').last().hasClass('o_selected_row'), + "last row should be selected"); + + form.$('.o_data_row input[name="turtle_foo"]').val('rainbow dash').trigger('input'); + form.$buttons.find('.o_form_button_save').click(); + + assert.strictEqual(form.$('tr.o_data_row').length, 40, + "should have 40 data rows on the current page"); + + assert.verifySteps(['read', 'read', 'default_get', 'write', 'read', 'read']); + form.destroy(); + }); + + QUnit.test('editing tabbed one2many (editable=top)', function (assert) { + assert.expect(14); + + this.data.partner.records[0].turtles = []; + this.data.turtle.fields.turtle_foo.default = "default foo"; + for (var i = 0; i < 42; i++) { + var id = 100 + i; + this.data.turtle.records.push({id: id, turtle_foo: 'turtle' + (id-99)}); + this.data.partner.records[0].turtles.push(id); + } + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'<form string="Partners">' + + '<sheet>' + + '<field name="turtles">' + + '<tree editable="top">' + + '<field name="turtle_foo"/>' + + '</tree>' + + '</field>' + + '</sheet>' + + '</form>', + res_id: 1, + mockRPC: function (route, args) { + assert.step(args.method); + if (args.method === 'write') { + assert.deepEqual(args.args[1].turtles[0], [0, false, {turtle_foo: 'rainbow dash'}]) + } + return this._super.apply(this, arguments); + }, + }); + + + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_pager_next').click(); + + assert.strictEqual(form.$('tr.o_data_row').length, 2, + "should have 2 data rows on the current page"); + + 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"); + assert.ok(form.$('tr.o_data_row').first().hasClass('o_selected_row'), + "first row should be selected"); + + assert.strictEqual(form.$('tr.o_data_row input').val(), 'default foo', + "selected input should have correct string"); + + form.$('.o_data_row input[name="turtle_foo"]').val('rainbow dash').trigger('input'); + form.$buttons.find('.o_form_button_save').click(); + + assert.strictEqual(form.$('tr.o_data_row').length, 40, + "should have 40 data rows on the current page"); + + assert.verifySteps(['read', 'read', 'read', 'default_get', 'write', 'read', 'read']); + form.destroy(); + }); QUnit.module('FieldMany2Many'); diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js index 318b715a504..b2a00f1ca09 100644 --- a/addons/web/static/tests/views/basic_model_tests.js +++ b/addons/web/static/tests/views/basic_model_tests.js @@ -2086,4 +2086,38 @@ QUnit.module('Views', { model.destroy(); }); + QUnit.test('only x2many lists (static) should be sorted client-side', function (assert) { + assert.expect(1); + + this.params.modelName = 'partner_type'; + this.params.res_id = undefined; + this.params.orderedBy = [{name: 'display_name', asc: true}]; + + var model = createModel({ + Model: BasicModel, + data: this.data, + mockRPC: function (route) { + if (route === '/web/dataset/search_read') { + // simulate randomn sort form the server + return $.when({ + length: 3, + records: [ + {id: 12, display_name: "gold", date: "2017-01-25"}, + {id: 15, display_name: "bronze"}, + {id: 14, display_name: "silver"}, + ], + }); + } + return this._super.apply(this, arguments); + }, + }); + + model.load(this.params).then(function (resultID) { + var list = model.get(resultID); + assert.deepEqual(_.map(list.data, 'res_id'), [12, 15, 14], + "should have kept the order from the server"); + }); + model.destroy(); + }); + });}); diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 2ac373dbcd0..ce246ef17d6 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -773,6 +773,153 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('use default_order on editable tree: sort on save', function (assert) { + assert.expect(8); + + this.data.foo.records[0].o2m = [1, 3]; + + var form = createView({ + View: FormView, + model: 'foo', + data: this.data, + arch: '<form>' + + '<sheet>' + + '<field name="o2m">' + + '<tree editable="bottom" default_order="display_name">' + + '<field name="display_name"/>' + + '</tree>' + + '</field>' + + '</sheet>' + + '</form>', + res_id: 1, + }); + + form.$buttons.find('.o_form_button_edit').click(); + assert.ok(form.$('tbody tr:first td:contains(Value 1)').length, + "Value 1 should be first"); + assert.ok(form.$('tbody tr:eq(1) td:contains(Value 3)').length, + "Value 3 should be second"); + + var $o2m = form.$('.o_field_widget[name=o2m]'); + form.$('.o_field_x2many_list_row_add a').click(); + $o2m.find('.o_field_widget').val("Value 2").trigger('input'); + assert.ok(form.$('tbody tr:first td:contains(Value 1)').length, + "Value 1 should be first"); + assert.ok(form.$('tbody tr:eq(1) td:contains(Value 3)').length, + "Value 3 should be second"); + assert.ok(form.$('tbody tr:eq(2) td input').val(), + "Value 2 should be third (shouldn't be sorted)"); + + form.$buttons.find('.o_form_button_save').click(); + assert.ok(form.$('tbody tr:first td:contains(Value 1)').length, + "Value 1 should be first"); + assert.ok(form.$('tbody tr:eq(1) td:contains(Value 2)').length, + "Value 2 should be second (should be sorted after saving)"); + assert.ok(form.$('tbody tr:eq(2) td:contains(Value 3)').length, + "Value 3 should be third"); + + form.destroy(); + }); + + QUnit.test('use default_order on editable tree: sort on demand', function (assert) { + assert.expect(8); + + this.data.foo.records[0].o2m = [1, 3]; + this.data.bar.fields = {name: {string: "Name", type: "char", sortable: true}}; + this.data.bar.records[0].name = "Value 1"; + this.data.bar.records[2].name = "Value 3"; + + var form = createView({ + View: FormView, + model: 'foo', + data: this.data, + arch: '<form>' + + '<sheet>' + + '<field name="o2m">' + + '<tree editable="bottom" default_order="name">' + + '<field name="name"/>' + + '</tree>' + + '</field>' + + '</sheet>' + + '</form>', + res_id: 1, + }); + + form.$buttons.find('.o_form_button_edit').click(); + assert.ok(form.$('tbody tr:first td:contains(Value 1)').length, + "Value 1 should be first"); + assert.ok(form.$('tbody tr:eq(1) td:contains(Value 3)').length, + "Value 3 should be second"); + + var $o2m = form.$('.o_field_widget[name=o2m]'); + form.$('.o_field_x2many_list_row_add a').click(); + $o2m.find('.o_field_widget').val("Value 2").trigger('input'); + assert.ok(form.$('tbody tr:first td:contains(Value 1)').length, + "Value 1 should be first"); + assert.ok(form.$('tbody tr:eq(1) td:contains(Value 3)').length, + "Value 3 should be second"); + assert.ok(form.$('tbody tr:eq(2) td input').val(), + "Value 2 should be third (shouldn't be sorted)"); + + $o2m.find('.o_column_sortable').click(); + assert.ok(form.$('tbody tr:first td:contains(Value 3)').length, + "Value 3 should be first"); + assert.ok(form.$('tbody tr:eq(1) td:contains(Value 2)').length, + "Value 2 should be second (should be sorted after saving)"); + assert.ok(form.$('tbody tr:eq(2) td:contains(Value 1)').length, + "Value 1 should be third"); + + form.destroy(); + }); + + QUnit.test('use default_order on editable tree: sort on demand in page', function (assert) { + assert.expect(4); + + this.data.bar.fields = {name: {string: "Name", type: "char", sortable: true}}; + + var ids = []; + for (var i=0; i<45; i++) { + var id = 4 + i; + ids.push(id); + this.data.bar.records.push({ + id: id, + name: "Value " + id, + }); + } + this.data.foo.records[0].o2m = ids; + + var form = createView({ + View: FormView, + model: 'foo', + data: this.data, + arch: '<form>' + + '<sheet>' + + '<field name="o2m">' + + '<tree editable="bottom" default_order="name">' + + '<field name="name"/>' + + '</tree>' + + '</field>' + + '</sheet>' + + '</form>', + res_id: 1, + }); + + // Change page + form.$('.o_pager_next').click(); + assert.ok(form.$('tbody tr:first td:contains(Value 44)').length, + "record 44 should be first"); + assert.ok(form.$('tbody tr:eq(4) td:contains(Value 48)').length, + "record 48 should be last"); + + form.$('.o_column_sortable').click(); + assert.ok(form.$('tbody tr:first td:contains(Value 48)').length, + "record 48 should be first"); + assert.ok(form.$('tbody tr:eq(4) td:contains(Value 44)').length, + "record 44 should be first"); + + form.destroy(); + }); + QUnit.test('can display button in edit mode', function (assert) { assert.expect(1); |
