From b83db271354ee8ecabf4a39c96f3a187dd5535d5 Mon Sep 17 00:00:00 2001 From: MOENS Alexandre Date: Tue, 21 Aug 2018 12:00:49 +0200 Subject: [FIX] web: JournalDashboardGraph widget crash Mk.II Hardening of commit:995610c065bf0242cb5023cfad2940234395739e The JournalDashboardGraph requires nv, which is lazyloaded. However it requires nvd3.js which is loaded after nv.d3.js. A function called in destroy is defined by nv.d3.js, which can make the crashhappen with the right (wrong) timing. opw 1873749 --- .../web/static/tests/fields/basic_fields_tests.js | 39 ++++++++++++++++++++++ 1 file changed, 39 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 fade0282f69..1133bed08b5 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1902,6 +1902,45 @@ QUnit.module('basic_fields', { assert.verifySteps(['destroy']); }); + QUnit.test('graph dashboard widget can be destroyed when nv is partially loaded', function (assert) { + // this test ensures that the JournalDashboardGraph widget doesn't crash + // when being destroyed before nv has been completely loaded + assert.expect(2); + + testUtils.patch(basicFields.JournalDashboardGraph, { + destroy: function () { + assert.step('destroy'); + // nv is fully loaded only when nvd3.js has been loaded + // which happens sequentially after nv.d3.js + // we simulate this race condition with: + var offWindowResize = window.nv.utils.offWindowResize; + window.nv.utils.offWindowResize = undefined; + this._super.apply(this, arguments); + window.nv.utils.offWindowResize = offWindowResize; + }, + }); + + var kanban = createView({ + View: KanbanView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '' + + '
' + + '' + + '
' + + '
' + + '
', + domain: [['id', 'in', [1]]], + }); + + kanban.destroy(); + testUtils.unpatch(basicFields.JournalDashboardGraph); + + assert.verifySteps(['destroy']); + }); + QUnit.module('AceEditor'); QUnit.test('ace widget on text fields works', function (assert) { -- cgit v1.2.3