summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields_tests.js
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-05-30 12:18:52 +0200
committerChristophe Simonis <chs@odoo.com>2018-05-30 12:18:52 +0200
commite008ef302a1b3fc584d4f0fb9956d237947f17d5 (patch)
tree7976948d25c1aa7aa23123ccabb37b5eaae8e8e3 /addons/web/static/tests/fields/relational_fields_tests.js
parentf36e6917bd73a56dc0c7468b4849920df4088154 (diff)
parent53300648edef8f87bfd0bff6b52536efdd1cc82c (diff)
[MERGE] forward port branch saas-11.3 up to 53300648ede
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js111
1 files changed, 111 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 1012974bb58..9e1ca77a05c 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -2551,6 +2551,117 @@ QUnit.module('relational_fields', {
QUnit.module('FieldOne2Many');
+ QUnit.test('O2M List with pager, decoration and default_order: add and cancel adding', function (assert) {
+ assert.expect(3);
+
+ // The decoration on the list implies that its condition will be evaluated
+ // against the data of the field (actual records *displayed*)
+ // If one data is wrongly formed, it will crash
+ // This test adds then cancels a record in a paged, ordered, and decorated list
+ // That implies prefetching of records for sorting
+ // and evaluation of the decoration against *visible records*
+
+ this.data.partner.records[0].p = [2,4];
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<field name="p">' +
+ '<tree editable="bottom" limit="1" decoration-muted="foo != False" default_order="display_name">' +
+ '<field name="foo" invisible="1"/>' +
+ '<field name="display_name" />' +
+ '</tree>' +
+ '</field>' +
+ '</form>',
+ res_id: 1,
+ viewOptions: {
+ mode: 'edit',
+ },
+ });
+
+ form.$('.o_field_x2many_list .o_field_x2many_list_row_add a').click();
+
+ var $dataRows = form.$('.o_field_x2many_list .o_data_row');
+ assert.equal($dataRows.length, 2,
+ 'There should be 2 rows');
+
+ var $expectedSelectedRow = $dataRows.eq(1);
+ var $actualSelectedRow = form.$('.o_selected_row');
+ assert.equal($actualSelectedRow[0], $expectedSelectedRow[0],
+ 'The selected row should be the new one');
+
+ // Cancel Creation
+ var escapeKey = $.ui.keyCode.ESCAPE;
+ $actualSelectedRow.find('input').trigger(
+ $.Event('keydown', {which: escapeKey, keyCode: escapeKey}));
+
+ $dataRows = form.$('.o_field_x2many_list .o_data_row');
+ assert.equal($dataRows.length, 1,
+ 'There should be 1 row');
+
+ form.destroy();
+ });
+
+ QUnit.test('O2M with parented m2o and domain on parent.m2o', function (assert) {
+ assert.expect(3);
+
+ /* records in an o2m can have a m2o pointing to themselves
+ * in that case, a domain evaluation on that field followed by name_search
+ * shouldn't send virtual_ids to the server
+ */
+
+ this.data.turtle.fields.parent_id = {string: "Parent", type: "many2one", relation: 'turtle'};
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<field name="turtles">' +
+ '<tree>' +
+ '<field name="parent_id" />' +
+ '</tree>' +
+ '</field>' +
+ '</form>',
+ archs: {
+ 'turtle,false,form': '<form><field name="parent_id" domain="[(\'id\', \'in\', parent.turtles)]"/></form>',
+ },
+
+ mockRPC: function(route, args) {
+ if (route === '/web/dataset/call_kw/turtle/name_search') {
+ // We are going to pass twice here
+ // First time, we really have nothing
+ // Second time, a virtual_id has been created
+ assert.deepEqual(args.kwargs.args, [['id', 'in', []]]);
+ }
+ return this._super(route, args);
+ }
+ });
+
+ form.$('.o_field_x2many_list[name=turtles] .o_field_x2many_list_row_add a').click();
+ var $modal = $('.modal-content');
+
+ var $turtleParent = $modal.find('.o_field_many2one input');
+ var $dropdown = $turtleParent.autocomplete('widget');
+
+ $turtleParent.click();
+
+ $dropdown.find('li.o_m2o_dropdown_option:contains(Create)').first().mouseenter().click();
+
+ $modal = $('.modal-content');
+
+ $modal.eq(1).find('.modal-footer .btn-primary').eq(0).click(); // Confirm new Record
+ $modal.eq(0).find('.modal-footer .btn-primary').eq(1).click(); // Save & New
+
+ assert.equal(form.$('.o_data_row').length, 1,
+ 'The main record should have the new record in its o2m');
+
+ $modal = $('.modal-content');
+ $modal.find('.o_field_many2one input').click();
+
+ form.destroy();
+ });
+
QUnit.test('one2many list editable with cell readonly modifier', function (assert) {
assert.expect(4);