|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Makes sure Table Charts have the right internal structure. |
|
6 */ |
|
7 |
|
8 function test() { |
|
9 initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { |
|
10 info("Starting test... "); |
|
11 |
|
12 let { document, L10N, Chart } = aMonitor.panelWin; |
|
13 let container = document.createElement("box"); |
|
14 |
|
15 let table = Chart.Table(document, { |
|
16 title: "Table title", |
|
17 data: [{ |
|
18 label1: 1, |
|
19 label2: 11.1 |
|
20 }, { |
|
21 label1: 2, |
|
22 label2: 12.2 |
|
23 }, { |
|
24 label1: 3, |
|
25 label2: 13.3 |
|
26 }], |
|
27 strings: { |
|
28 label2: (value, index) => value + ["foo", "bar", "baz"][index] |
|
29 }, |
|
30 totals: { |
|
31 label1: value => "Hello " + L10N.numberWithDecimals(value, 2), |
|
32 label2: value => "World " + L10N.numberWithDecimals(value, 2) |
|
33 } |
|
34 }); |
|
35 |
|
36 let node = table.node; |
|
37 let title = node.querySelector(".table-chart-title"); |
|
38 let grid = node.querySelector(".table-chart-grid"); |
|
39 let totals = node.querySelector(".table-chart-totals"); |
|
40 let rows = grid.querySelectorAll(".table-chart-row"); |
|
41 let sums = node.querySelectorAll(".table-chart-summary-label"); |
|
42 |
|
43 ok(node.classList.contains("table-chart-container") && |
|
44 node.classList.contains("generic-chart-container"), |
|
45 "A table chart container was created successfully."); |
|
46 |
|
47 ok(title, |
|
48 "A title node was created successfully."); |
|
49 is(title.getAttribute("value"), "Table title", |
|
50 "The title node displays the correct text."); |
|
51 |
|
52 is(rows.length, 3, |
|
53 "There should be 3 table chart rows created."); |
|
54 |
|
55 ok(rows[0].querySelector(".table-chart-row-box.chart-colored-blob"), |
|
56 "A colored blob exists for the firt row."); |
|
57 is(rows[0].querySelectorAll("label")[0].getAttribute("name"), "label1", |
|
58 "The first column of the first row exists."); |
|
59 is(rows[0].querySelectorAll("label")[1].getAttribute("name"), "label2", |
|
60 "The second column of the first row exists."); |
|
61 is(rows[0].querySelectorAll("label")[0].getAttribute("value"), "1", |
|
62 "The first column of the first row displays the correct text."); |
|
63 is(rows[0].querySelectorAll("label")[1].getAttribute("value"), "11.1foo", |
|
64 "The second column of the first row displays the correct text."); |
|
65 |
|
66 ok(rows[1].querySelector(".table-chart-row-box.chart-colored-blob"), |
|
67 "A colored blob exists for the second row."); |
|
68 is(rows[1].querySelectorAll("label")[0].getAttribute("name"), "label1", |
|
69 "The first column of the second row exists."); |
|
70 is(rows[1].querySelectorAll("label")[1].getAttribute("name"), "label2", |
|
71 "The second column of the second row exists."); |
|
72 is(rows[1].querySelectorAll("label")[0].getAttribute("value"), "2", |
|
73 "The first column of the second row displays the correct text."); |
|
74 is(rows[1].querySelectorAll("label")[1].getAttribute("value"), "12.2bar", |
|
75 "The second column of the first row displays the correct text."); |
|
76 |
|
77 ok(rows[2].querySelector(".table-chart-row-box.chart-colored-blob"), |
|
78 "A colored blob exists for the third row."); |
|
79 is(rows[2].querySelectorAll("label")[0].getAttribute("name"), "label1", |
|
80 "The first column of the third row exists."); |
|
81 is(rows[2].querySelectorAll("label")[1].getAttribute("name"), "label2", |
|
82 "The second column of the third row exists."); |
|
83 is(rows[2].querySelectorAll("label")[0].getAttribute("value"), "3", |
|
84 "The first column of the third row displays the correct text."); |
|
85 is(rows[2].querySelectorAll("label")[1].getAttribute("value"), "13.3baz", |
|
86 "The second column of the third row displays the correct text."); |
|
87 |
|
88 is(sums.length, 2, |
|
89 "There should be 2 total summaries created."); |
|
90 |
|
91 is(totals.querySelectorAll(".table-chart-summary-label")[0].getAttribute("name"), "label1", |
|
92 "The first sum's type is correct."); |
|
93 is(totals.querySelectorAll(".table-chart-summary-label")[0].getAttribute("value"), "Hello 6", |
|
94 "The first sum's value is correct."); |
|
95 |
|
96 is(totals.querySelectorAll(".table-chart-summary-label")[1].getAttribute("name"), "label2", |
|
97 "The second sum's type is correct."); |
|
98 is(totals.querySelectorAll(".table-chart-summary-label")[1].getAttribute("value"), "World 36.60", |
|
99 "The second sum's value is correct."); |
|
100 |
|
101 teardown(aMonitor).then(finish); |
|
102 }); |
|
103 } |