diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-09-06 17:40:59 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-09-06 17:40:59 +0200 |
| commit | d5382abeaad4d93b8def7e63cd47a86baaba8f0b (patch) | |
| tree | 6364ff760709b541eebdde4b04494b480dec87fb /addons/web/static/tests/views | |
| parent | c75fe95dfca366bf6c3b6a51908677039488aa4f (diff) | |
| parent | b8dd34fcbb895b8d62f3e133dcf5ee6f40a1400d (diff) | |
[MERGE] forward port branch saas-17 up to b8dd34fcbb8
Diffstat (limited to 'addons/web/static/tests/views')
| -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 |
2 files changed, 181 insertions, 0 deletions
diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js index 2c5f6fe8993..a4a19ab620d 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); |
