summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/test/browser_net_charts-07.js
blob: 9744c33e6da575722563e862b30689dba71a9c33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Makes sure Table Charts correctly handle empty source data.
 */

add_task(async function () {
  const {
    L10N,
  } = require("resource://devtools/client/netmonitor/src/utils/l10n.js");

  const { monitor } = await initNetMonitor(HTTPS_SIMPLE_URL, {
    requestCount: 1,
  });
  info("Starting test... ");

  const { document, windowRequire } = monitor.panelWin;
  const { Chart } = windowRequire("devtools/client/shared/widgets/Chart");

  const wait = waitForNetworkEvents(monitor, 1);
  await navigateTo(HTTPS_SIMPLE_URL);
  await wait;

  const table = Chart.Table(document, {
    data: [],
    totals: {
      label1: value => "Hello " + L10N.numberWithDecimals(value, 2),
      label2: value => "World " + L10N.numberWithDecimals(value, 2),
    },
    header: {
      label1: "",
      label2: "",
    },
  });

  const { node } = table;
  const grid = node.querySelector(".table-chart-grid");
  const totals = node.querySelector(".table-chart-totals");
  const rows = grid.querySelectorAll(".table-chart-row");
  const sums = node.querySelectorAll(".table-chart-summary-label");

  is(rows.length, 2, "There should be 1 table chart row and 1 header created.");

  is(
    rows[1].querySelectorAll(".table-chart-row-label")[0].getAttribute("name"),
    "size",
    "The first column of the first row exists."
  );
  is(
    rows[1].querySelectorAll(".table-chart-row-label")[1].getAttribute("name"),
    "label",
    "The second column of the first row exists."
  );
  is(
    rows[1].querySelectorAll(".table-chart-row-label")[0].textContent,
    "",
    "The first column of the first row displays the correct text."
  );
  is(
    rows[1].querySelectorAll(".table-chart-row-label")[1].textContent,
    L10N.getStr("tableChart.unavailable"),
    "The second column of the first row displays the correct text."
  );

  is(sums.length, 2, "There should be 2 total summaries created.");

  is(
    totals
      .querySelectorAll(".table-chart-summary-label")[0]
      .getAttribute("name"),
    "label1",
    "The first sum's type is correct."
  );
  is(
    totals.querySelectorAll(".table-chart-summary-label")[0].textContent,
    "Hello 0",
    "The first sum's value is correct."
  );

  is(
    totals
      .querySelectorAll(".table-chart-summary-label")[1]
      .getAttribute("name"),
    "label2",
    "The second sum's type is correct."
  );
  is(
    totals.querySelectorAll(".table-chart-summary-label")[1].textContent,
    "World 0",
    "The second sum's value is correct."
  );

  await teardown(monitor);
});