Bug 1399897 - Fix console_table mochitest; r=Honza. draft
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Mon, 08 Jan 2018 12:26:32 +0100
changeset 719104 fdf95ccb5abf8fc9ed362e03d72dae2f03245300
parent 719103 220368d50a36707f7114a4c69580614b79b955e9
child 745699 45cf28d1a250f9281399f1f34178aee5cfa64928
push id95152
push userbmo:nchevobbe@mozilla.com
push dateThu, 11 Jan 2018 13:34:30 +0000
reviewersHonza
bugs1399897
milestone59.0a1
Bug 1399897 - Fix console_table mochitest; r=Honza. Now that we are using sibling divs for all the cells of the table, we don't have the same notion of what is a row. The console table test is adapted to the new component. MozReview-Commit-ID: HcfzTaRVIcN
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_console_table.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_console_table.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_console_table.js
@@ -146,37 +146,37 @@ add_task(function* () {
     ".message .new-consoletable");
   is(consoleTableNodes.length, testCases.length,
     "console has the expected number of consoleTable items");
   testCases.forEach((testCase, index) => testItem(testCase, nodes[index]));
 });
 function testItem(testCase, node) {
   info(testCase.info);
 
-  let columns = Array.from(node.querySelectorAll("thead th"));
-  let rows = Array.from(node.querySelectorAll("tbody tr"));
+  const columns = Array.from(node.querySelectorAll("[role=columnheader]"));
+  const columnsNumber = columns.length;
+  const cells = Array.from(node.querySelectorAll("[role=gridcell]"));
 
   is(
     JSON.stringify(testCase.expected.columns),
     JSON.stringify(columns.map(column => column.textContent)),
     "table has the expected columns"
   );
 
-  is(testCase.expected.rows.length, rows.length,
+  // We don't really have rows since we are using a CSS grid in order to have a sticky
+  // header on the table. So we check the "rows" by dividing the number of cells by the
+  // number of columns.
+  is(testCase.expected.rows.length, cells.length / columnsNumber,
     "table has the expected number of rows");
 
   testCase.expected.rows.forEach((expectedRow, rowIndex) => {
-    let row = rows[rowIndex];
-    let cells = row.querySelectorAll("td");
-    is(expectedRow.length, cells.length, "row has the expected number of cells");
-
-    expectedRow.forEach((expectedCell, cellIndex) => {
-      let cell = cells[cellIndex];
-      is(expectedCell, cell.textContent, "cell has the expected content");
-    });
+    const startIndex = rowIndex * columnsNumber;
+    // Slicing the cells array so we can get the current "row".
+    const rowCells = cells.slice(startIndex, startIndex + columnsNumber);
+    is(rowCells.map(x => x.textContent).join(" | "), expectedRow.join(" | "));
   });
 }
 
 function findConsoleTable(node, index) {
   let condition = node.querySelector(
     `.message:nth-of-type(${index + 1}) .new-consoletable`);
   return condition;
 }