blob: 89c2eaf8df0f7ac7303534d250f1dec842ff454e (
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
|
describe("HTMLTableElement", () => {
loadLocalPage("Table.html");
afterInitialPageLoad(page => {
test("empty table attributes", () => {
let table = page.document.getElementById("empty-table");
expect(table).not.toBeNull();
expect(table.caption).toBe(null);
expect(table.tHead).toBe(null);
expect(table.tFoot).toBe(null);
expect(table.tBodies).toHaveLength(0);
expect(table.rows).toHaveLength(0);
});
test("full table attributes", () => {
let table = page.document.getElementById("full-table");
expect(table).not.toBeNull();
expect(table.caption.nodeName).toBe("CAPTION");
expect(table.tHead.nodeName).toBe("THEAD");
expect(table.tFoot.nodeName).toBe("TFOOT");
expect(table.tBodies.length).toBe(1);
expect(table.rows.length).toBe(3);
});
test("create/delete caption", () => {
let table = page.document.createElement("table");
expect(table).not.toBeNull();
expect(table.caption).toBeNull();
table.createCaption();
expect(table.caption).not.toBeNull();
table.deleteCaption();
expect(table.caption).toBeNull();
});
test("create/delete thead", () => {
let table = page.document.createElement("table");
expect(table).not.toBeNull();
expect(table.tHead).toBeNull();
table.createTHead();
expect(table.tHead).not.toBeNull();
table.deleteTHead();
expect(table.tHead).toBeNull();
});
test("create/delete tfoot", () => {
let table = page.document.createElement("table");
expect(table).not.toBeNull();
expect(table.tFoot).toBeNull();
table.createTFoot();
expect(table.tFoot).not.toBeNull();
table.deleteTFoot();
expect(table.tFoot).toBeNull();
});
test("insert rows", () => {
let table = page.document.createElement("table");
expect(table).not.toBeNull();
// We hardcode the default value in a few places, due to the WrapperGenerator's bug with default values
const defaultValue = -1;
expect(table.rows.length).toBe(0);
// insertRow with an index > number of rows will throw
expect(() => {
table.insertRow(1);
}).toThrow();
// Inserting a row into an empty table will create a <tbody> and <tr>
let rowFirst = table.insertRow(defaultValue);
rowFirst.innerText = "row_first";
expect(table.firstElementChild.nodeName).toBe("TBODY");
expect(table.firstElementChild.firstElementChild.nodeName).toBe("TR");
expect(table.firstElementChild.firstElementChild.innerText).toBe("row_first");
for (let i = 0; i < 10; i++) {
let row = table.insertRow(defaultValue);
row.innerText = "row" + i;
}
expect(table.rows.length).toBe(11);
// insertRow with the default value
let rowDefault = table.insertRow(defaultValue);
rowDefault.innerText = "row_default";
expect(table.rows[table.rows.length - 1].innerText).toBe("row_default");
});
test("delete rows", () => {
let table = page.document.createElement("table");
expect(table).not.toBeNull();
// We hardcode the default value in a few places, due to the WrapperGenerator's bug with default values
const defaultValue = -1;
// deleteRow with an index > number of rows will throw
expect(table.deleteRow).toThrow();
for (let i = 0; i < 10; i++) {
let row = table.insertRow(defaultValue);
row.innerText = "row" + i;
}
// deleteRow with with no argument will delete the last row
expect(table.rows[table.rows.length - 1].innerText).toBe("row9");
table.deleteRow(defaultValue);
expect(table.rows[table.rows.length - 1].innerText).toBe("row8");
// We can delete a row with a specific index
expect(table.rows[5].innerText).toBe("row5");
table.deleteRow(5);
expect(table.rows[5].innerText).toBe("row6");
});
});
waitForPageToLoad();
});
|