browser_net_charts-05.js (2262B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Makes sure Pie+Table Charts have the right internal structure. 8 */ 9 10 add_task(async function () { 11 const { 12 L10N, 13 } = require("resource://devtools/client/netmonitor/src/utils/l10n.js"); 14 15 const { monitor } = await initNetMonitor(HTTPS_SIMPLE_URL, { 16 requestCount: 1, 17 }); 18 info("Starting test... "); 19 20 const { document, windowRequire } = monitor.panelWin; 21 const { Chart } = windowRequire("devtools/client/shared/widgets/Chart"); 22 23 const wait = waitForNetworkEvents(monitor, 1); 24 await navigateTo(HTTPS_SIMPLE_URL); 25 await wait; 26 27 const chart = Chart.PieTable(document, { 28 title: "Table title", 29 data: [ 30 { 31 size: 1, 32 label: 11.1, 33 }, 34 { 35 size: 2, 36 label: 12.2, 37 }, 38 { 39 size: 3, 40 label: 13.3, 41 }, 42 ], 43 strings: { 44 label2: (value, index) => value + ["foo", "bar", "baz"][index], 45 }, 46 totals: { 47 size: value => "Hello " + L10N.numberWithDecimals(value, 2), 48 label: value => "World " + L10N.numberWithDecimals(value, 2), 49 }, 50 header: { 51 label1: "", 52 label2: "", 53 }, 54 }); 55 56 ok(chart.pie, "The pie chart proxy is accessible."); 57 ok(chart.table, "The table chart proxy is accessible."); 58 59 const { node } = chart; 60 const rows = node.querySelectorAll(".table-chart-row"); 61 const sums = node.querySelectorAll(".table-chart-summary-label"); 62 63 ok( 64 node.classList.contains("pie-table-chart-container"), 65 "A pie+table chart container was created successfully." 66 ); 67 68 ok( 69 node.querySelector(".table-chart-title"), 70 "A title node was created successfully." 71 ); 72 ok( 73 node.querySelector(".pie-chart-container"), 74 "A pie chart was created successfully." 75 ); 76 ok( 77 node.querySelector(".table-chart-container"), 78 "A table chart was created successfully." 79 ); 80 81 is( 82 rows.length, 83 4, 84 "There should be 3 pie chart slices and 1 header created." 85 ); 86 is( 87 rows.length, 88 4, 89 "There should be 3 table chart rows and 1 header created." 90 ); 91 is(sums.length, 2, "There should be 2 total summaries and 1 header created."); 92 93 await teardown(monitor); 94 });