mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
parent
f258548f3c
commit
6d0d3b108b
2 changed files with 94 additions and 7 deletions
|
@ -772,4 +772,90 @@ describe("DataTable", () => {
|
|||
expect.any(Object),
|
||||
);
|
||||
});
|
||||
|
||||
it("should handle changing number of headers without crashing", async () => {
|
||||
const rows = [
|
||||
{
|
||||
id: "a",
|
||||
name: "Load Balancer 3",
|
||||
protocol: "HTTP",
|
||||
port: 3000,
|
||||
rule: "Round robin",
|
||||
},
|
||||
{
|
||||
id: "b",
|
||||
name: "Load Balancer 1",
|
||||
protocol: "HTTP",
|
||||
port: 443,
|
||||
rule: "Round robin",
|
||||
},
|
||||
];
|
||||
|
||||
const headers5 = [
|
||||
{ key: "name", value: "Name" },
|
||||
{ key: "protocol", value: "Protocol" },
|
||||
{ key: "port", value: "Port" },
|
||||
{ key: "rule", value: "Rule" },
|
||||
{ key: "actions", value: "Actions" },
|
||||
];
|
||||
|
||||
const headers3 = [
|
||||
{ key: "name", value: "Name" },
|
||||
{ key: "protocol", value: "Protocol" },
|
||||
{ key: "port", value: "Port" },
|
||||
];
|
||||
|
||||
const { component, rerender } = render(DataTable, {
|
||||
props: {
|
||||
rows,
|
||||
headers: headers5,
|
||||
},
|
||||
});
|
||||
|
||||
// First render with 5 headers
|
||||
expect(component).toBeTruthy();
|
||||
|
||||
// Change to 3 headers - this should not crash
|
||||
await rerender({
|
||||
rows,
|
||||
headers: headers3,
|
||||
});
|
||||
|
||||
expect(component).toBeTruthy();
|
||||
|
||||
// Change back to 5 headers - this should not crash
|
||||
await rerender({
|
||||
rows,
|
||||
headers: headers5,
|
||||
});
|
||||
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should handle empty headers correctly", async () => {
|
||||
const rows = [
|
||||
{
|
||||
id: "a",
|
||||
name: "Load Balancer 3",
|
||||
protocol: "HTTP",
|
||||
port: 3000,
|
||||
rule: "Round robin",
|
||||
},
|
||||
];
|
||||
|
||||
const headersWithEmpty = [
|
||||
{ key: "name", value: "Name" },
|
||||
{ key: "protocol", value: "Protocol" },
|
||||
{ key: "actions", value: "", empty: true, columnMenu: true },
|
||||
];
|
||||
|
||||
const { component } = render(DataTable, {
|
||||
props: {
|
||||
rows,
|
||||
headers: headersWithEmpty,
|
||||
},
|
||||
});
|
||||
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue