summaryrefslogtreecommitdiffstats
path: root/comm/mail/base/test/browser/files/tree-element-test-common.js
blob: 6f22962acad1690224684738bf15b9757dfa120f (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, you can obtain one at http://mozilla.org/MPL/2.0/. */

// FIXME: Wrap the whole method around the document load listener to prevent the
// undefined state of the "tree-view-table-row" element. This is due to the .mjs
// nature of the class file.
window.addEventListener("load", () => {
  class AlternativeCardRow extends customElements.get("tree-view-table-row") {
    static ROW_HEIGHT = 80;

    connectedCallback() {
      if (this.hasConnected) {
        return;
      }

      super.connectedCallback();

      this.cell = this.appendChild(document.createElement("td"));
    }

    get index() {
      return super.index;
    }

    set index(index) {
      super.index = index;
      this.cell.textContent = this.view.getCellText(index, {
        id: "GeneratedName",
      });
    }
  }
  customElements.define("alternative-row", AlternativeCardRow, {
    extends: "tr",
  });

  class TestView {
    values = [];

    constructor(start, count) {
      for (let i = start; i < start + count; i++) {
        this.values.push(i);
      }
    }

    get rowCount() {
      return this.values.length;
    }

    getCellText(index, column) {
      return `${column.id} ${this.values[index]}`;
    }

    isContainer() {
      return false;
    }

    isContainerOpen() {
      return false;
    }

    selectionChanged() {}

    setTree() {}
  }

  const tree = document.getElementById("testTree");
  tree.table.setBodyID("testBody");
  tree.addEventListener("select", () => {
    console.log("select event, selected indices:", tree.selectedIndices);
  });
  tree.view = new TestView(0, 150);
});