Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes footers and captions disappearing on empty tables #352

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/datatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,9 @@ export class DataTable {
]
}

this._tableFooters.forEach(footer => newVirtualDOM.childNodes.push(footer))
this._tableCaptions.forEach(caption => newVirtualDOM.childNodes.push(caption))

newVirtualDOM.attributes.class = newVirtualDOM.attributes.class ? `${newVirtualDOM.attributes.class} ${this.options.classes.table}` : this.options.classes.table

if (this.options.tableRender) {
Expand Down
33 changes: 33 additions & 0 deletions test/cases/empty-table-with-footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="../dist/css/style.css">
<title>empty-table-with-footer</title>
</head>
<body>
<table>
<caption>This is a table caption.</caption>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<!-- No data! -->
</tbody>
<tfoot>
<tr>
<td colspan="2">
This is a table footer.
</td>
</tr>
</tfoot>
</table>

<script src="../dist/umd.js"></script>
<script>
window.dt = new window.simpleDatatables.DataTable("table")
</script>
</body>
</html>
1 change: 1 addition & 0 deletions test/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import express from "express"
const app = express()

app.use(express.static("docs/demos"))
app.use("/tests", express.static("test/cases"))
app.get("/documentation", (_req, res) => res.send("It's me, the documentation page!"))
app.use("/favicon.ico", express.static("docs/favicon.ico"))
app.use("/favicon.svg", express.static("docs/favicon.svg"))
Expand Down
51 changes: 50 additions & 1 deletion test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ if (process.env.CI) { // eslint-disable-line no-process-env
const driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).setChromeOptions(options).build()
const manage = driver.manage()
manage.window().maximize()
const baseUrl = `http://localhost:${port}/`
let demoUrls
server.listen(port)
await driver.get(`http://localhost:${port}`).then(
await driver.get(baseUrl).then(
() => driver.findElements(webdriver.By.css("a"))
).then(
nodes => Promise.all(nodes.map(node => node.getAttribute("href")))
Expand Down Expand Up @@ -73,6 +74,54 @@ describe("Demos work", function() {
))
})

describe("Integration tests pass", function() {
this.timeout(5000)

it("initializes the datatable", async () => {
await driver.get(`${baseUrl}1-simple/`)
const wrapper = await driver.findElement(webdriver.By.className("datatable-wrapper"))
const container = await wrapper.findElement(webdriver.By.className("datatable-container"))
const table = await container.findElement(webdriver.By.tagName("table"))
const tableClass = await table.getAttribute("class")
assert.equal(tableClass, "datatable-table", "table is missing class 'datatable-table'")

await wrapper.findElement(webdriver.By.className("datatable-top"))
await wrapper.findElement(webdriver.By.className("datatable-bottom"))
})

it("shows table footer", async () => {
await driver.get(`${baseUrl}24-footer`)
const table = await driver.findElement(webdriver.By.tagName("table"))
const tfoot = table.findElement(webdriver.By.tagName("tfoot"))
const tfootText = await tfoot.getText()
assert.equal(tfootText, "This is a table footer.")
})

it("shows table caption", async () => {
await driver.get(`${baseUrl}24-footer`)
const table = await driver.findElement(webdriver.By.tagName("table"))
const caption = table.findElement(webdriver.By.tagName("caption"))
const captionText = await caption.getText()
assert.equal(captionText, "This is a table caption.")
})

it("shows table footer when empty", async () => {
await driver.get(`${baseUrl}tests/empty-table-with-footer.html`)
const table = await driver.findElement(webdriver.By.tagName("table"))
const tfoot = table.findElement(webdriver.By.tagName("tfoot"))
const tfootText = await tfoot.getText()
assert.equal(tfootText, "This is a table footer.")
})

it("shows table caption when empty", async () => {
await driver.get(`${baseUrl}tests/empty-table-with-footer.html`)
const table = await driver.findElement(webdriver.By.tagName("table"))
const caption = table.findElement(webdriver.By.tagName("caption"))
const captionText = await caption.getText()
assert.equal(captionText, "This is a table caption.")
})
})

after(() => {
driver.quit()
server.close()
Expand Down