[FIX] web: correctly display header tooltips in list

A traceback occured when displaying the tooltip (only visible in debug) on a list
view header if the field had a `widget` attribute (introduced in rev. odoo/odoo@5dc971b).

The issue here was linked to the fact that a widget is not always rendered in list view
(compared to form view) so the `Widget` property in the attributes was not there.

Task 1981757
This commit is contained in:
Martin Geubelle
2019-05-07 09:34:28 +00:00
parent 19a2797b2d
commit db64af9b9c
2 changed files with 18 additions and 8 deletions
@@ -716,7 +716,7 @@ var ListRenderer = BasicRenderer.extend({
name: name,
string: description || name,
record: this.state,
attrs: node.attrs,
attrs: _.extend({}, node.attrs, this.state.fieldsInfo.list[name]),
};
this._addFieldTooltip(fieldDescr, $th);
} else {
+17 -7
View File
@@ -1678,7 +1678,7 @@ QUnit.module('Views', {
});
QUnit.test('display a tooltip on a field', async function (assert) {
assert.expect(2);
assert.expect(4);
var initialDebugMode = config.debug;
config.debug = false;
@@ -1687,24 +1687,34 @@ QUnit.module('Views', {
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree><field name="foo"/></tree>',
arch: '<tree>' +
'<field name="foo"/>' +
'<field name="bar" widget="toggle_button"/>' +
'</tree>',
});
// this is done to force the tooltip to show immediately instead of waiting
// 1000 ms. not totally academic, but a short test suite is easier to sell :(
list.$('th:not(.o_list_record_selector)').tooltip('show', false);
list.$('th[data-name=foo]').tooltip('show', false);
list.$('th:not(.o_list_record_selector)').trigger($.Event('mouseenter'));
list.$('th[data-name=foo]').trigger($.Event('mouseenter'));
assert.strictEqual($('.tooltip .oe_tooltip_string').length, 0, "should not have rendered a tooltip");
config.debug = true;
// it is necessary to rerender the list so tooltips can be properly created
await list.reload();
list.$('th:not(.o_list_record_selector)').tooltip('show', false);
list.$('th:not(.o_list_record_selector)').trigger($.Event('mouseenter'));
list.$('th[data-name=foo]').tooltip('show', false);
list.$('th[data-name=foo]').trigger($.Event('mouseenter'));
assert.strictEqual($('.tooltip .oe_tooltip_string').length, 1, "should have rendered a tooltip");
await list.reload();
list.$('th[data-name=bar]').tooltip('show', false);
list.$('th[data-name=bar]').trigger($.Event('mouseenter'));
assert.containsOnce($, '.oe_tooltip_technical>li[data-item="widget"]',
'widget should be present for this field');
assert.strictEqual($('.oe_tooltip_technical>li[data-item="widget"]')[0].lastChild.wholeText.trim(),
'Button (toggle_button)', "widget description should be correct");
config.debug = initialDebugMode;
list.destroy();
});