summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_filter_groups.js
blob: a5d38494342a8b347b9e5139529d09a28f817302 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests filters.

"use strict";

const TEST_URI =
  "http://example.com/browser/devtools/client/webconsole/" +
  "test/browser/test-console-filter-groups.html";

add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);

  await waitFor(
    () => findConsoleAPIMessage(hud, "[a]") && findConsoleAPIMessage(hud, "[j]")
  );

  /*
   * The output looks like the following:
   *   ▼[a]
   *   |   [b]
   *   |   [c]
   *   | ▼[d]
   *   | |   [e]
   *   |   [f]
   *   |   [g]
   *   [h]
   *   [i]
   *   ▶︎[j]
   *   ▼[group]
   *   | ▼[subgroup]
   *   | |  [subitem]
   */

  await setFilterState(hud, {
    text: "[",
  });

  checkMessages(
    hud,
    `
    ▼[a]
    |  [b]
    |  [c]
    | ▼[d]
    | |  [e]
    |  [f]
    |  [g]
    [h]
    [i]
    ▶︎[j]
    ▼[group]
    | ▼[subgroup]
    | |    [subitem]
    `,
    `Got all expected messages when filtering on common character "["`
  );

  info("Check that filtering on a group substring shows all children");
  await setFilterState(hud, {
    text: "[a]",
  });

  checkMessages(
    hud,
    `
    ▼[a]
    |  [b]
    |  [c]
    | ▼[d]
    | |  [e]
    |  [f]
    |  [g]
    `,
    `Got all children of group when filtering on "[a]"`
  );

  info(
    "Check that filtering on a group child substring shows the parent group message"
  );
  await setFilterState(hud, {
    text: "[b]",
  });

  checkMessages(
    hud,
    `
    ▼[a]
    |  [b]
    `,
    `Got matching message and parent group when filtering on "[b]"`
  );

  info(
    "Check that filtering on a sub-group substring shows subgroup children and parent group"
  );
  await setFilterState(hud, {
    text: "[d]",
  });

  checkMessages(
    hud,
    `
    ▼[a]
    | ▼[d]
    | |  [e]
    `,
    `Got matching message, subgroup children and parent group when filtering on "[d]"`
  );

  info("Check that filtering on a sub-group child shows all parent groups");
  await setFilterState(hud, {
    text: "[e]",
  });

  checkMessages(
    hud,
    `
    ▼[a]
    | ▼[d]
    | |  [e]
    `,
    `Got matching message and parent groups when filtering on "[e]"`
  );

  info(
    "Check that filtering a message in a collapsed group shows the parent group"
  );
  await setFilterState(hud, {
    text: "[k]",
  });

  checkMessages(
    hud,
    `
    [j]
    `,
    `Got collapsed group when filtering on "[k]"`
  );

  info("Check that filtering a message not in a group hides all groups");
  await setFilterState(hud, {
    text: "[h]",
  });

  checkMessages(
    hud,
    `
    [h]
    `,
    `Got only matching message when filtering on "[h]"`
  );

  await setFilterState(hud, {
    text: "",
  });

  const groupA = await findMessageVirtualizedByType({
    hud,
    text: "[a]",
    typeSelector: ".console-api",
  });
  const groupJ = await findMessageVirtualizedByType({
    hud,
    text: "[j]",
    typeSelector: ".console-api",
  });

  toggleGroup(groupA);
  toggleGroup(groupJ);

  checkMessages(
    hud,
    `▶︎[a]
    [h]
    [i]
    ▼[j]
    |  [k]
    ▼[group]
    | ▼[subgroup]
    | |    [subitem]`,
    `Got matching messages after collapsing and expanding group messages`
  );

  info(
    "Check that filtering on expanded groupCollapsed messages does not hide children"
  );
  await setFilterState(hud, {
    text: "[k]",
  });

  checkMessages(
    hud,
    `
    ▼[j]
    |  [k]
    `,
    `Got only matching message when filtering on "[k]"`
  );

  info(
    "Check that filtering on collapsed group messages shows only the group parent"
  );

  await setFilterState(hud, {
    text: "[e]",
  });

  checkMessages(
    hud,
    `
    [a]
    `,
    `Got only matching message when filtering on "[e]"`
  );

  info(
    "Check that filtering on collapsed, nested group messages shows only expaded ancestor"
  );

  // We clear the filter so subgroup is visible and can be toggled
  await setFilterState(hud, {
    text: "",
  });

  const subGroup = findConsoleAPIMessage(hud, "[subgroup]");
  toggleGroup(subGroup);

  await setFilterState(hud, {
    text: "[subitem",
  });

  checkMessages(
    hud,
    `
    ▼[group]
    |  ▶︎[subgroup]
    `,
    `Got only visible ancestors when filtering on "[subitem"`
  );
});

/**
 *
 * @param {WebConsole} hud
 * @param {String} expected
 * @param {String} assertionMessage
 */
function checkMessages(hud, expected, assertionMessage) {
  const expectedMessages = expected
    .split("\n")
    .filter(line => line.trim())
    .map(line => line.replace(/(▶︎|▼|\|)/g, "").trim());

  const messages = Array.from(
    hud.ui.outputNode.querySelectorAll(".message .message-body")
  ).map(el => el.innerText.trim());

  const formatMessages = arr => `\n${arr.join("\n")}\n`;

  is(
    formatMessages(messages),
    formatMessages(expectedMessages),
    assertionMessage
  );
}

function toggleGroup(node) {
  const toggleArrow = node.querySelector(".collapse-button");
  toggleArrow.click();
}