Skip to content

Commit 797b4b1

Browse files
committed
added first component tests
1 parent 2023dc5 commit 797b4b1

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, it, expect } from "vitest";
2+
import { render, screen } from "@testing-library/react";
3+
import { Box } from "./Box";
4+
import type { ComponentChangeHandler } from "@/types/state/event";
5+
6+
describe("Box", () => {
7+
it("should render the Box component", () => {
8+
const onChange: ComponentChangeHandler = () => {};
9+
render(
10+
<Box id="bx" type={"Box"} children={["Hallo!"]} onChange={onChange} />,
11+
);
12+
expect(screen.getByText("Hallo!")).not.toBeUndefined();
13+
});
14+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { describe, it, expect } from "vitest";
2+
import { render, screen, fireEvent } from "@testing-library/react";
3+
import type {
4+
ComponentChangeEvent,
5+
ComponentChangeHandler,
6+
} from "@/types/state/event";
7+
import { Button } from "./Button";
8+
9+
describe("Button", () => {
10+
it("should render the Button component", () => {
11+
const onChange: ComponentChangeHandler = () => {};
12+
render(
13+
<Button id="bt" type={"Button"} text={"Click!"} onChange={onChange} />,
14+
);
15+
expect(screen.getByText("Click!")).not.toBeUndefined();
16+
});
17+
18+
it("should fire the 'clicked'", () => {
19+
let recordedEvent: ComponentChangeEvent | undefined = undefined;
20+
const onChange: ComponentChangeHandler = (event) => {
21+
recordedEvent = event;
22+
};
23+
render(
24+
<Button
25+
data-testid="bt"
26+
id="bt"
27+
type={"Button"}
28+
text={"Click!"}
29+
onChange={onChange}
30+
/>,
31+
);
32+
fireEvent.click(screen.getByText("Click!"));
33+
expect(recordedEvent).not.toBeUndefined();
34+
});
35+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, it, expect } from "vitest";
2+
import { render } from "@testing-library/react";
3+
import { VegaChart } from "./VegaChart";
4+
import type { ComponentChangeHandler } from "@/types/state/event";
5+
6+
describe("VegaChart", () => {
7+
it("should render the VegaChart component if chart is not given", () => {
8+
const onChange: ComponentChangeHandler = () => {};
9+
render(
10+
<VegaChart id="vc" type={"VegaChart"} chart={null} onChange={onChange} />,
11+
);
12+
expect(document.querySelector("#vc")).not.toBeUndefined();
13+
});
14+
});

0 commit comments

Comments
 (0)