Skip to content

Commit 1ccf455

Browse files
committed
test(data-table): add more unit tests
1 parent 90f25df commit 1ccf455

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

tests/DataTable/DataTable.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { render, screen } from "@testing-library/svelte";
22
import { tick } from "svelte";
33
import { user } from "../setup-tests";
44
import DataTable from "./DataTable.test.svelte";
5+
import DataTableCustomSlots from "./DataTableCustomSlots.test.svelte";
6+
import DataTableCustomDescription from "./DataTableCustomDescription.test.svelte";
7+
import DataTableCustomBoth from "./DataTableCustomBoth.test.svelte";
58

69
describe("DataTable", () => {
710
beforeEach(() => {
@@ -857,4 +860,39 @@ describe("DataTable", () => {
857860

858861
expect(component).toBeTruthy();
859862
});
863+
864+
// Regression test for https://github.com/carbon-design-system/carbon-components-svelte/issues/1594
865+
it("renders custom title element with props", () => {
866+
render(DataTableCustomSlots);
867+
868+
const customTitle = screen.getByRole("heading", { level: 2 });
869+
expect(customTitle).toBeInTheDocument();
870+
expect(customTitle).toHaveTextContent("Custom Title");
871+
expect(customTitle).toHaveClass("bx--data-table-header__title");
872+
});
873+
874+
it("renders custom description element with props", () => {
875+
const { container } = render(DataTableCustomDescription);
876+
877+
const customDescription = container.querySelector(
878+
"div.bx--data-table-header__description",
879+
);
880+
expect(customDescription).toBeInTheDocument();
881+
expect(customDescription).toHaveTextContent("Custom Description");
882+
expect(customDescription).toHaveClass("bx--data-table-header__description");
883+
});
884+
885+
it("renders both custom title and description elements", () => {
886+
const { container } = render(DataTableCustomBoth);
887+
888+
const customTitle = screen.getByRole("heading", { level: 2 });
889+
expect(customTitle).toBeInTheDocument();
890+
expect(customTitle).toHaveClass("bx--data-table-header__title");
891+
892+
const customDescription = container.querySelector(
893+
"div.bx--data-table-header__description",
894+
);
895+
expect(customDescription).toBeInTheDocument();
896+
expect(customDescription).toHaveClass("bx--data-table-header__description");
897+
});
860898
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script lang="ts">
2+
import { DataTable } from "carbon-components-svelte";
3+
4+
const headers = [
5+
{ key: "name", value: "Name" },
6+
{ key: "protocol", value: "Protocol" },
7+
] as const;
8+
9+
const rows = [
10+
{
11+
id: "a",
12+
name: "Load Balancer 1",
13+
protocol: "HTTP",
14+
},
15+
];
16+
</script>
17+
18+
<DataTable {headers} {rows}>
19+
<h2 slot="title" let:props {...props}>Custom Title</h2>
20+
<div slot="description" let:props {...props}>Custom Description</div>
21+
</DataTable>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script lang="ts">
2+
import { DataTable } from "carbon-components-svelte";
3+
4+
const headers = [
5+
{ key: "name", value: "Name" },
6+
{ key: "protocol", value: "Protocol" },
7+
] as const;
8+
9+
const rows = [
10+
{
11+
id: "a",
12+
name: "Load Balancer 1",
13+
protocol: "HTTP",
14+
},
15+
];
16+
</script>
17+
18+
<DataTable {headers} {rows}>
19+
<div slot="description" let:props {...props}>Custom Description</div>
20+
</DataTable>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script lang="ts">
2+
import { DataTable } from "carbon-components-svelte";
3+
4+
const headers = [
5+
{ key: "name", value: "Name" },
6+
{ key: "protocol", value: "Protocol" },
7+
] as const;
8+
9+
const rows = [
10+
{
11+
id: "a",
12+
name: "Load Balancer 1",
13+
protocol: "HTTP",
14+
},
15+
];
16+
</script>
17+
18+
<DataTable {headers} {rows}>
19+
<h2 slot="title" let:props {...props}>Custom Title</h2>
20+
</DataTable>

0 commit comments

Comments
 (0)