forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWeb: Add tests for HTMLTableElement attributes
These tests aim to exercise all attributes on <html> elements, including all edge cases.
- Loading branch information
1 parent
737f6e9
commit dc9995a
Showing
2 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
Userland/Libraries/LibWeb/Tests/HTML/HTMLTableElement.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
loadPage("file:https:///home/anon/web-tests/Pages/Table.html"); | ||
|
||
afterInitialPageLoad(() => { | ||
test("empty table attributes", () => { | ||
let table = 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 = 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 = 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 = 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 = 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 = 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 = 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"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<table id="empty-table"></table> | ||
<table id="full-table"> | ||
<caption>A Caption</caption> | ||
<thead> | ||
<th>Head Cell</th> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
Body Cell | ||
</td> | ||
</tr> | ||
</tbody> | ||
<tfoot> | ||
<tr> | ||
<td> | ||
Footer Cell | ||
</td> | ||
</tr> | ||
</tfoot> | ||
</table> | ||
</body> | ||
</html> |