diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-11-10 10:24:15 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-11-13 11:18:56 +0100 |
| commit | 995610c065bf0242cb5023cfad2940234395739e (patch) | |
| tree | 6615b650e25bd78f7470f633ee78fc11df5669f9 /addons/web/static/tests/fields/basic_fields_tests.js | |
| parent | f80d043af28988279a04d6b150eb617b374b3de2 (diff) | |
[FIX] web: JournalDashboardGraph widget crash
The JournalDashboardGraph requires nv, which is lazyloaded. Before
this rev., a crash occurred when this widget was instantiated and
destroyed before the loading of the lib was complete (because a
function of the lib was called in destroy()).
For instance, press F5 (to ensure that nv isn't already loaded),
activate some throttling in the network tab, go to Accounting and
as soon as the dashboard shows up, click on another menu.
opw 781628
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 103 |
1 files changed, 70 insertions, 33 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 99cc72144b6..35431904cec 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1502,43 +1502,45 @@ QUnit.module('basic_fields', { }); - QUnit.module('JournalDashboardGraph'); + QUnit.module('JournalDashboardGraph', { + beforeEach: function () { + _.extend(this.data.partner.fields, { + graph_data: { string: "Graph Data", type: "text" }, + graph_type: { + string: "Graph Type", + type: "selection", + selection: [['line', 'Line'], ['bar', 'Bar']] + }, + }); + this.data.partner.records[0].graph_type = "bar"; + this.data.partner.records[1].graph_type = "line"; + var graph_values = [ + {'value': 300, 'label': '5-11 Dec'}, + {'value': 500, 'label': '12-18 Dec'}, + {'value': 100, 'label': '19-25 Dec'}, + ]; + this.data.partner.records[0].graph_data = JSON.stringify([{ + color: 'red', + title: 'Partner 0', + values: graph_values, + key: 'A key', + area: true, + }]); + this.data.partner.records[1].graph_data = JSON.stringify([{ + color: 'blue', + title: 'Partner 1', + values: graph_values, + key: 'A key', + area: true, + }]); + }, + }); QUnit.test('graph dashboard widget is rendered correctly', function (assert) { var done = assert.async(); assert.expect(4); - var graph_key = ""; - _.extend(this.data.partner.fields, { - graph_data: { string: "Graph Data", type: "text" }, - graph_type: { - string: "Graph Type", - type: "selection", - selection: [['line', 'Line'], ['bar', 'Bar']] - }, - }); - this.data.partner.records[0].graph_type = "bar"; - this.data.partner.records[1].graph_type = "line"; - var graph_values = [ - {'value': 300, 'label': '5-11 Dec'}, - {'value': 500, 'label': '12-18 Dec'}, - {'value': 100, 'label': '19-25 Dec'}, - ]; - this.data.partner.records[0].graph_data = JSON.stringify([{ - color: 'red', - title: 'Partner 0', - values: graph_values, - key: 'A key', - area: true, - }]); - graph_key = JSON.parse(this.data.partner.records[0].graph_data)[0].key - this.data.partner.records[1].graph_data = JSON.stringify([{ - color: 'blue', - title: 'Partner 1', - values: graph_values, - key: 'A key', - area: true, - }]); + var graph_key = JSON.parse(this.data.partner.records[0].graph_data)[0].key; var kanban = createView({ View: KanbanView, model: 'partner', @@ -1571,7 +1573,7 @@ QUnit.module('basic_fields', { evt.initMouseEvent("mouseover", true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null); $('.discreteBar')[0].dispatchEvent(evt); var tooltip = $('.nvtooltip').find('table').find('.key')[0].innerText; - assert.equal(tooltip,graph_key, "graph tooltip should be generated "); + assert.equal(tooltip, graph_key, "graph tooltip should be generated "); $('.nvtooltip').remove(); // force a re-rendering of the first record (to check if the @@ -1590,6 +1592,41 @@ QUnit.module('basic_fields', { }); + QUnit.test('graph dashboard widget does not need nv to be destroyed', function (assert) { + // this test ensures that the JournalDashboardGraph widget doesn't crash + // when being destroyed before nv has been loaded + assert.expect(2); + + var destroy = basicFields.JournalDashboardGraph.prototype.destroy; + basicFields.JournalDashboardGraph.prototype.destroy = function () { + assert.step('destroy'); + var nv = window.nv; + delete window.nv; + destroy.apply(this, arguments); + window.nv = nv; + }; + + var kanban = createView({ + View: KanbanView, + model: 'partner', + data: this.data, + arch: '<kanban class="o_kanban_test">' + + '<field name="graph_type"/>' + + '<templates><t t-name="kanban-box">' + + '<div>' + + '<field name="graph_data" t-att-graph_type="record.graph_type.raw_value" widget="dashboard_graph"/>' + + '</div>' + + '</t>' + + '</templates></kanban>', + domain: [['id', 'in', [1]]], + }); + + kanban.destroy(); + basicFields.JournalDashboardGraph.prototype.destroy = destroy; + + assert.verifySteps(['destroy']); + }); + QUnit.module('AceEditor'); QUnit.test('ace widget on text fields works', function (assert) { |
