-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsel-editor.spec.tsx
More file actions
83 lines (73 loc) · 1.99 KB
/
sel-editor.spec.tsx
File metadata and controls
83 lines (73 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { render } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { SELEditor } from "./sel-editor";
import type { SELSchema } from "@seljs/schema";
const testSchema = {
version: "1.0.0",
contracts: [
{
name: "erc20",
methods: [
{
name: "balanceOf",
params: [{ name: "owner", type: "address" }],
returns: "uint256",
},
],
},
],
variables: [{ name: "user", type: "address" }],
types: [],
functions: [],
macros: [],
} as unknown as SELSchema;
describe("src/sel-editor.tsx", () => {
it("renders without crashing", () => {
const { container } = render(<SELEditor schema={testSchema} />);
expect(container.firstChild).toBeTruthy();
});
it("applies className prop", () => {
const { container } = render(
<SELEditor schema={testSchema} className="my-editor" />,
);
expect(
(container.firstChild as HTMLElement).classList.contains("my-editor"),
).toBe(true);
});
it("renders with initial value", () => {
const { container } = render(
<SELEditor schema={testSchema} value="erc20.balanceOf(user)" />,
);
// CodeMirror creates its DOM inside the container div
expect(container.querySelector(".cm-editor")).toBeTruthy();
});
it("accepts onChange callback", () => {
const onChange = vi.fn();
const { container } = render(
<SELEditor schema={testSchema} onChange={onChange} />,
);
expect(container.querySelector(".cm-editor")).toBeTruthy();
});
it("accepts checkerOptions prop", () => {
const { container } = render(
<SELEditor
schema={testSchema}
value="test"
checkerOptions={{ rules: [] }}
/>,
);
expect(container.querySelector(".cm-editor")).toBeTruthy();
});
it("renders with empty schema", () => {
const emptySchema: SELSchema = {
version: "1.0.0",
contracts: [],
variables: [],
types: [],
functions: [],
macros: [],
};
const { container } = render(<SELEditor schema={emptySchema} />);
expect(container.querySelector(".cm-editor")).toBeTruthy();
});
});