From bbc8c9fc26839d0be81804fa193d25677882d6e3 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Tue, 4 Jun 2019 14:27:51 +0000 Subject: [PATCH] [FIX] web: fix form resequence test e61639723 In 12.3 when lines are resequenced, the position of the current line does not take into account that it could have been changed (because of drag and dropping a line before or after). opw-1966589 closes #33878 --- .../src/js/views/list/list_editable_renderer.js | 5 +++++ addons/web/static/tests/views/form_tests.js | 16 ++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/views/list/list_editable_renderer.js b/addons/web/static/src/js/views/list/list_editable_renderer.js index dc312d34f5a..e876a8acd28 100644 --- a/addons/web/static/src/js/views/list/list_editable_renderer.js +++ b/addons/web/static/src/js/views/list/list_editable_renderer.js @@ -911,6 +911,11 @@ ListRenderer.include({ _resequence: function (event, ui) { var self = this; var movedRecordID = ui.item.data('id'); + // update currentID taking moved line into account + if (this.currentRow !== null) { + var currentID = self.state.data[self.currentRow].id; + this.currentRow = this._getRow(currentID).index(); + } self.unselectRow().then(function () { var rows = self.state.data; var row = self._getRecord(movedRecordID); diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 890c3d1e056..5b13568192b 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -8119,16 +8119,18 @@ QUnit.module('Views', { assert.strictEqual(form.$('[name="foo"]').val(), "0", "onchange worked there is 0 line"); // Add one line - form.$('.o_field_x2many_list_row_add a').click(); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); form.$('.o_field_one2many input:first').focus(); + await testUtils.nextTick(); form.$('.o_field_one2many input:first').val('first line').trigger('input'); - form.$('input[name="foo"]').click(); + await testUtils.nextTick(); + await testUtils.dom.click(form.$('input[name="foo"]')); assert.strictEqual(onchangeNum, 2, "one onchange happens when a line is added"); assert.strictEqual(form.$('[name="foo"]').val(), "1", "onchange worked there is 1 line"); // Drag and drop second line before first one (with 1 draft and invalid line) - form.$('.o_field_x2many_list_row_add a').click(); - await testUtils.dragAndDrop( + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.dom.dragAndDrop( form.$('.ui-sortable-handle').eq(0), form.$('.o_data_row').last(), {position: 'bottom'} @@ -8137,10 +8139,12 @@ QUnit.module('Views', { assert.strictEqual(form.$('[name="foo"]').val(), "1", "onchange worked there is 1 line"); // Add a second line - form.$('.o_field_x2many_list_row_add a').click(); + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); form.$('.o_field_one2many input:first').focus(); + await testUtils.nextTick(); form.$('.o_field_one2many input:first').val('second line').trigger('input'); - form.$('input[name="foo"]').click(); + await testUtils.nextTick(); + await testUtils.dom.click(form.$('input[name="foo"]')); assert.strictEqual(onchangeNum, 4, "one onchange happens when a line is added"); assert.strictEqual(form.$('[name="foo"]').val(), "2", "onchange worked there is 2 lines");