-
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.
🚸 #629 - style: use "fill-available-space" for datagrid heights"
- Loading branch information
1 parent
42519f7
commit 9f3a93f
Showing
6 changed files
with
335 additions
and
18 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
frontend/src/components/DestructionListToolbar/DestructionListToolbar.stories.tsx
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,71 @@ | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
import { expect, userEvent, within } from "@storybook/test"; | ||
|
||
import { | ||
ClearSessionStorageDecorator, | ||
ReactRouterDecorator, | ||
} from "../../../.storybook/decorators"; | ||
import { destructionListFactory } from "../../fixtures"; | ||
import { DestructionListToolbar } from "./DestructionListToolbar"; | ||
|
||
const meta: Meta<typeof DestructionListToolbar> = { | ||
title: "Components/DestructionListToolbar", | ||
component: DestructionListToolbar, | ||
decorators: [ClearSessionStorageDecorator, ReactRouterDecorator], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Tabable: Story = { | ||
args: { | ||
destructionList: destructionListFactory(), | ||
}, | ||
play: async (context) => { | ||
const canvas = within(context.canvasElement); | ||
// Initial tab | ||
await expect(canvas.getByText("Auteur")).toBeVisible(); | ||
|
||
// Click on history tab | ||
await userEvent.click( | ||
await canvas.findByRole("tab", { name: "Geschiedenis" }), | ||
); | ||
await expect(await canvas.findByText("Datum")).toBeVisible(); | ||
|
||
// Click on details tab | ||
await userEvent.click(await canvas.findByRole("tab", { name: "Details" })); | ||
await expect(canvas.getByText("Min/max archiefactiedatum")).toBeVisible(); | ||
}, | ||
}; | ||
|
||
export const Collapsible: Story = { | ||
args: { | ||
destructionList: destructionListFactory(), | ||
}, | ||
play: async (context) => { | ||
const canvas = within(context.canvasElement); | ||
// Click on history tab | ||
await userEvent.click( | ||
await canvas.findByRole("tab", { name: "Geschiedenis" }), | ||
); | ||
|
||
// Assert content rendered | ||
expect((await canvas.findByRole("tabpanel")).children).toHaveLength(1); | ||
|
||
// Click on history tab again (collapse) | ||
await userEvent.click( | ||
await canvas.findByRole("tab", { name: "Geschiedenis" }), | ||
); | ||
|
||
// Assert content not rendered | ||
expect((await canvas.findByRole("tabpanel")).children).toHaveLength(0); | ||
|
||
// Click on history tab again (expand) | ||
await userEvent.click( | ||
await canvas.findByRole("tab", { name: "Geschiedenis" }), | ||
); | ||
|
||
// Assert content rendered | ||
expect((await canvas.findByRole("tabpanel")).children).toHaveLength(1); | ||
}, | ||
}; |
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
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,124 @@ | ||
import { clearPreference, getPreference, setPreference } from "./preferences"; | ||
|
||
describe("getPreference", () => { | ||
beforeEach(() => { | ||
sessionStorage.clear(); | ||
}); | ||
|
||
it("should retrieve a stored string preference", async () => { | ||
sessionStorage.setItem( | ||
"oab.lib.preference.testKey", | ||
JSON.stringify({ type: "string", value: "testValue" }), | ||
); | ||
const result = await getPreference<string>("testKey"); | ||
expect(result).toBe("testValue"); | ||
}); | ||
|
||
it("should retrieve a stored number preference", async () => { | ||
sessionStorage.setItem( | ||
"oab.lib.preference.testKey", | ||
JSON.stringify({ type: "number", value: "1" }), | ||
); | ||
const result = await getPreference<number>("testKey"); | ||
expect(result).toBe(1); | ||
}); | ||
|
||
it("should retrieve a stored boolean preference", async () => { | ||
sessionStorage.setItem( | ||
"oab.lib.preference.testKey", | ||
JSON.stringify({ type: "boolean", value: "true" }), | ||
); | ||
const result = await getPreference<boolean>("testKey"); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it("should retrieve a stored null preference", async () => { | ||
sessionStorage.setItem( | ||
"oab.lib.preference.testKey", | ||
JSON.stringify({ type: "null", value: "null" }), | ||
); | ||
const result = await getPreference<null>("testKey"); | ||
expect(result).toBe(null); | ||
}); | ||
|
||
it("should retrieve a stored object preference", async () => { | ||
const obj = { a: 1, b: "test" }; | ||
sessionStorage.setItem( | ||
"oab.lib.preference.testKey", | ||
JSON.stringify({ type: "json", value: JSON.stringify(obj) }), | ||
); | ||
const result = await getPreference<object>("testKey"); | ||
expect(result).toEqual(obj); | ||
}); | ||
|
||
it("should return undefined for a non-existent key", async () => { | ||
const result = await getPreference<string>("nonExistentKey"); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe("setPreference", () => { | ||
beforeEach(() => { | ||
sessionStorage.clear(); | ||
}); | ||
|
||
it("should store a string preference", async () => { | ||
await setPreference<string>("testKey", "testValue"); | ||
const stored = JSON.parse( | ||
sessionStorage.getItem("oab.lib.preference.testKey")!, | ||
); | ||
expect(stored).toEqual({ type: "string", value: "testValue" }); | ||
}); | ||
|
||
it("should store a number preference", async () => { | ||
await setPreference<number>("testKey", 1); | ||
const stored = JSON.parse( | ||
sessionStorage.getItem("oab.lib.preference.testKey")!, | ||
); | ||
expect(stored).toEqual({ type: "number", value: 1 }); | ||
}); | ||
|
||
it("should store a boolean preference", async () => { | ||
await setPreference<boolean>("testKey", true); | ||
const stored = JSON.parse( | ||
sessionStorage.getItem("oab.lib.preference.testKey")!, | ||
); | ||
expect(stored).toEqual({ type: "boolean", value: true }); | ||
}); | ||
|
||
it("should store a null preference", async () => { | ||
await setPreference<null>("testKey", null); | ||
const stored = JSON.parse( | ||
sessionStorage.getItem("oab.lib.preference.testKey")!, | ||
); | ||
expect(stored).toEqual({ type: "null", value: null }); | ||
}); | ||
|
||
it("should store an object preference", async () => { | ||
const obj = { a: 1, b: "test" }; | ||
await setPreference<Record<string, number | string>>("testKey", obj); | ||
const stored = JSON.parse( | ||
sessionStorage.getItem("oab.lib.preference.testKey")!, | ||
); | ||
expect(stored).toEqual({ type: "json", value: JSON.stringify(obj) }); | ||
}); | ||
|
||
it("should throw an error for unsupported types like function", async () => { | ||
const unsupportedValue = () => {}; | ||
await expect(setPreference("testKey", unsupportedValue)).rejects.toThrow( | ||
"Function values are not supported as preference.", | ||
); | ||
}); | ||
}); | ||
|
||
describe.only("clearPreference", () => { | ||
beforeEach(() => { | ||
sessionStorage.clear(); | ||
}); | ||
|
||
it("should clear a stored preference", async () => { | ||
await setPreference("testKey", "testValue"); | ||
await clearPreference("testKey"); | ||
expect(await getPreference("testKey")).toBeUndefined(); | ||
}); | ||
}); |
Oops, something went wrong.