diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-11-22 20:06:48 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-11-22 20:06:48 +0100 |
| commit | b4e1be8ab07d883637a7f0f00c37d9bbf5ef6ee8 (patch) | |
| tree | 591d7ce8d61d9a9e5d35a695f6a2276066f1a4a3 /addons/web/static/tests | |
| parent | 1c4d49330e7f9719e372040f0c8729d3cf3d09fa (diff) | |
| parent | b09f624f20781d65baf2060df40383898e6f86e5 (diff) | |
[MERGE] forward port branch saas-11.3 up to b09f624f207
Diffstat (limited to 'addons/web/static/tests')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 89 | ||||
| -rw-r--r-- | addons/web/static/tests/views/list_tests.js | 93 |
2 files changed, 182 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 9c7c6363a40..52f181a24ec 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -10346,6 +10346,95 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('onchange on unloaded record clearing posterious change', function (assert) { + // when we got onchange result for fields of record that were not + // already available because they were in a inline view not already + // opened, in a given configuration the change were applied ignoring + // posteriously changed data, thus an added/removed/modified line could + // be reset to the original onchange data + assert.expect(5); + + var numUserOnchange = 0; + + this.data.user.onchanges = { + partner_ids: function (obj) { + // simulate actual server onchange after save of modal with new record + if (numUserOnchange === 0) { + obj.partner_ids = _.clone(obj.partner_ids); + obj.partner_ids.unshift([5]); + obj.partner_ids[1][2].turtles.unshift([5]); + obj.partner_ids[2] = [1, 2, { + display_name: 'second record', + trululu: 1, + turtles: [[5]], + }]; + } else if (numUserOnchange === 1) { + obj.partner_ids = _.clone(obj.partner_ids); + obj.partner_ids.unshift([5]); + obj.partner_ids[1][2].turtles.unshift([5]); + obj.partner_ids[2][2].turtles.unshift([5]); + } + numUserOnchange++; + }, + }; + + var form = createView({ + View: FormView, + model: 'user', + data: this.data, + arch: '<form><sheet><group>' + + '<field name="partner_ids">' + + '<form>'+ + '<field name="trululu"/>' + + '<field name="turtles">' + + '<tree editable="bottom">' + + '<field name="display_name"/>' + + '</tree>' + + '</field>' + + '</form>' + + '<tree>' + + '<field name="display_name"/>' + + '</tree>' + + '</field>' + + '</group></sheet></form>', + res_id: 17, + }); + + // open first partner and change turtle name + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_data_row:eq(0)').click(); + $('.modal .o_data_cell:eq(0)').click(); + $('.modal input[name="display_name"]').val('Donatello').change(); + $('.modal .btn-primary').click(); + + // open second partner and add a turtle + form.$('.o_data_row:eq(1)').click(); + $('.modal .o_field_x2many_list_row_add a').click(); + $('.modal input[name="display_name"]').val('Michelangelo').change(); + $('.modal .btn-primary').click(); + + assert.strictEqual(numUserOnchange, 2, + 'there should 2 and only 2 onchange from closing the partner modal'); + + // check first record still has change + form.$('.o_data_row:eq(0)').click(); + assert.strictEqual($('.modal .o_data_row').length, 1, + 'only 1 turtle for first partner'); + assert.strictEqual($('.modal .o_data_row').text(), 'Donatello', + 'first partner turtle is Donatello'); + $('.modal .o_form_button_cancel').click(); + + // check second record still has changes + form.$('.o_data_row:eq(1)').click(); + assert.strictEqual($('.modal .o_data_row').length, 1, + 'only 1 turtle for second partner'); + assert.strictEqual($('.modal .o_data_row').text(), 'Michelangelo', + 'second partner turtle is Michelangelo'); + $('.modal .o_form_button_cancel').click(); + + form.destroy(); + }); + QUnit.test('click on URL should not open the record', function (assert) { assert.expect(2); diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 030a676f4eb..76f4d3f6808 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -378,6 +378,99 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('ordered list, sort attribute in context', function (assert) { + assert.expect(1); + // Equivalent to saving a custom filter + + this.data.foo.fields.foo.sortable = true; + this.data.foo.fields.date.sortable = true; + + var list = createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: '<tree>' + + '<field name="foo"/>' + + '<field name="date"/>' + + '</tree>', + }); + + // Descending order on Foo + list.$('th.o_column_sortable:contains("Foo")').click(); + list.$('th.o_column_sortable:contains("Foo")').click(); + + // Ascending order on Date + list.$('th.o_column_sortable:contains("Date")').click(); + + var listContext = list.getContext(); + assert.deepEqual(listContext, + { + orderedBy: [{ + name: 'date', + asc: true, + }, { + name: 'foo', + asc: false, + }] + }, 'the list should have the right orderedBy in context'); + list.destroy(); + }); + + QUnit.test('Loading a filter with a sort attribute', function (assert) { + assert.expect(2); + + this.data.foo.fields.foo.sortable = true; + this.data.foo.fields.date.sortable = true; + + var searchReads = 0; + var list = createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: '<tree>' + + '<field name="foo"/>' + + '<field name="date"/>' + + '</tree>', + context: { + orderedBy: [{ + name: 'date', + asc: true, + }, { + name: 'foo', + asc: false, + }] + }, + mockRPC: function (route, args) { + if (route === '/web/dataset/search_read') { + if (searchReads === 0) { + assert.strictEqual(args.sort, 'date ASC, foo DESC', + 'The sort attribute of the filter should be used by the initial search_read'); + } else if (searchReads === 1) { + assert.strictEqual(args.sort, 'date DESC, foo ASC', + 'The sort attribute of the filter should be used by the next search_read'); + } + searchReads += 1; + } + return this._super.apply(this,arguments); + }, + }); + + // Simulate loading a filter + list.update({ + context: { + orderedBy: [{ + name: 'date', + asc: false, + }, { + name: 'foo', + asc: true, + }] + } + }); + + list.destroy() + }); + QUnit.test('many2one field rendering', function (assert) { assert.expect(1); |
