From 10f43955d81ff3e7b5ab050656b312ec19f927c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Thu, 16 Aug 2018 12:39:26 +0200 Subject: [FIX] web: render JournalDashboardGraph when in DOM The lib 'nvd3' renders graph when they are attached to the DOM. However, widgets are rendered in fragments and appended to the DOM when ready (to prevent flickering). Before this commit, we used a `setTimeout(0)` and cross fingers that the widget was attached to the DOM when the `render` method was called. With this commit, the render method is called when it is attached to the DOM. Task-ID 1868252 Closes #26410 --- .../web/static/tests/fields/basic_fields_tests.js | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 63e677f367d..68643f7b48d 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -14,6 +14,7 @@ var testUtils = require('web.test_utils'); var createView = testUtils.createView; var createAsyncView = testUtils.createAsyncView; var DebouncedField = basicFields.DebouncedField; +var JournalDashboardGraph = basicFields.JournalDashboardGraph; var _t = core._t; QUnit.module('fields', {}, function () { @@ -2009,6 +2010,57 @@ QUnit.module('basic_fields', { }, }); + QUnit.test('graph dashboard widget attach/detach callbacks', function (assert) { + // This widget is rendered with nvd3, and nvd3 renders the graphs when + // the svg is in the DOM. The intent of this test is to determine when + // the field widgets are in the DOM, so that we can tell nvd3 to render + // them. + var done = assert.async(); + assert.expect(6); + + testUtils.patch(JournalDashboardGraph, { + on_attach_callback: function () { + assert.step('on_attach_callback'); + }, + on_detach_callback: function () { + assert.step('on_detach_callback'); + }, + }); + + createAsyncView({ + View: KanbanView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '' + + '
' + + '' + + '
' + + '
' + + '
', + domain: [['id', 'in', [1, 2]]], + }).then(function (kanban) { + assert.verifySteps([ + 'on_attach_callback', + 'on_attach_callback' + ]); + + kanban.on_detach_callback(); + + assert.verifySteps([ + 'on_attach_callback', + 'on_attach_callback', + 'on_detach_callback', + 'on_detach_callback' + ]); + + kanban.destroy(); + testUtils.unpatch(JournalDashboardGraph); + done(); + }); + }); + QUnit.test('graph dashboard widget is rendered correctly', function (assert) { var done = assert.async(); assert.expect(4); -- cgit v1.2.3