[FIX] web: list: keep header checkbox selected

... when toggling an optional field.

This bug wasn't really important until now, but with the new
selection mechanism, it could lead to weird situations (e.g. the
selection box says that all records are selected, but the thead
checkbox isn't checked).

Part of task 2185145
This commit is contained in:
Aaron Bohy
2020-03-30 13:33:40 +00:00
parent 4fd30ecbc1
commit 009fe3e81b
2 changed files with 52 additions and 0 deletions
@@ -989,6 +989,9 @@ var ListRenderer = BasicRenderer.extend({
return _.contains(self.selection, $(el).data('id'));
});
$checked_rows.find('.o_list_record_selector input').prop('checked', true);
if ($checked_rows.length === self.$('.o_data_row').length) { // all rows are checked
self.$('thead .o_list_record_selector input').prop('checked', true);
}
}
});
return Promise.all([this._super.apply(this, arguments), prom]);
@@ -8839,6 +8839,55 @@ QUnit.module('Views', {
list.destroy();
});
QUnit.test('selection is kept when optional fields are toggled', async function (assert) {
assert.expect(7);
var RamStorageService = AbstractStorageService.extend({
storage: new RamStorage(),
});
var list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree>' +
'<field name="foo"/>' +
'<field name="m2o" optional="hide"/>' +
'</tree>',
services: {
local_storage: RamStorageService,
},
});
assert.containsN(list, 'th', 2);
// select a record
await testUtils.dom.click(list.$('.o_data_row .o_list_record_selector input:first'));
assert.containsOnce(list, '.o_list_record_selector input:checked');
// add an optional field
await testUtils.dom.click(list.$('table .o_optional_columns_dropdown_toggle'));
await testUtils.dom.click(list.$('div.o_optional_columns div.dropdown-item:first input'));
assert.containsN(list, 'th', 3);
assert.containsOnce(list, '.o_list_record_selector input:checked');
// select all records
await testUtils.dom.click(list.$('thead .o_list_record_selector input'));
assert.containsN(list, '.o_list_record_selector input:checked', 5);
// remove an optional field
await testUtils.dom.click(list.$('table .o_optional_columns_dropdown_toggle'));
await testUtils.dom.click(list.$('div.o_optional_columns div.dropdown-item:first input'));
assert.containsN(list, 'th', 2);
assert.containsN(list, '.o_list_record_selector input:checked', 5);
list.destroy();
});
QUnit.test('change the viewType of the current action', async function (assert) {
assert.expect(25);