|
1 |
| -import { render, screen, fireEvent } from '@testing-library/react'; |
2 |
| -import { describe, it, expect, jest } from '@jest/globals'; |
3 |
| -import DynamicJsonForm from '../DynamicJsonForm'; |
4 |
| -import type { JsonSchemaType } from '../DynamicJsonForm'; |
| 1 | +import { render, screen, fireEvent } from "@testing-library/react"; |
| 2 | +import { describe, it, expect, jest } from "@jest/globals"; |
| 3 | +import DynamicJsonForm from "../DynamicJsonForm"; |
| 4 | +import type { JsonSchemaType } from "../DynamicJsonForm"; |
5 | 5 |
|
6 |
| -describe('DynamicJsonForm String Fields', () => { |
| 6 | +describe("DynamicJsonForm String Fields", () => { |
7 | 7 | const renderForm = (props = {}) => {
|
8 | 8 | const defaultProps = {
|
9 | 9 | schema: {
|
10 | 10 | type: "string" as const,
|
11 |
| - description: "Test string field" |
| 11 | + description: "Test string field", |
12 | 12 | } satisfies JsonSchemaType,
|
13 | 13 | value: undefined,
|
14 |
| - onChange: jest.fn() |
| 14 | + onChange: jest.fn(), |
15 | 15 | };
|
16 | 16 | return render(<DynamicJsonForm {...defaultProps} {...props} />);
|
17 | 17 | };
|
18 | 18 |
|
19 |
| - describe('Type Validation', () => { |
20 |
| - it('should handle numeric input as string type', () => { |
| 19 | + describe("Type Validation", () => { |
| 20 | + it("should handle numeric input as string type", () => { |
21 | 21 | const onChange = jest.fn();
|
22 | 22 | renderForm({ onChange });
|
23 |
| - |
24 |
| - const input = screen.getByRole('textbox'); |
25 |
| - fireEvent.change(input, { target: { value: '123321' } }); |
26 |
| - |
27 |
| - expect(onChange).toHaveBeenCalledWith('123321'); |
| 23 | + |
| 24 | + const input = screen.getByRole("textbox"); |
| 25 | + fireEvent.change(input, { target: { value: "123321" } }); |
| 26 | + |
| 27 | + expect(onChange).toHaveBeenCalledWith("123321"); |
28 | 28 | // Verify the value is a string, not a number
|
29 |
| - expect(typeof onChange.mock.calls[0][0]).toBe('string'); |
| 29 | + expect(typeof onChange.mock.calls[0][0]).toBe("string"); |
30 | 30 | });
|
31 | 31 |
|
32 |
| - it('should render as text input, not number input', () => { |
| 32 | + it("should render as text input, not number input", () => { |
33 | 33 | renderForm();
|
34 |
| - const input = screen.getByRole('textbox'); |
35 |
| - expect(input).toHaveProperty('type', 'text'); |
| 34 | + const input = screen.getByRole("textbox"); |
| 35 | + expect(input).toHaveProperty("type", "text"); |
36 | 36 | });
|
37 | 37 | });
|
38 | 38 | });
|
39 | 39 |
|
40 |
| -describe('DynamicJsonForm Integer Fields', () => { |
| 40 | +describe("DynamicJsonForm Integer Fields", () => { |
41 | 41 | const renderForm = (props = {}) => {
|
42 | 42 | const defaultProps = {
|
43 | 43 | schema: {
|
44 | 44 | type: "integer" as const,
|
45 |
| - description: "Test integer field" |
| 45 | + description: "Test integer field", |
46 | 46 | } satisfies JsonSchemaType,
|
47 | 47 | value: undefined,
|
48 |
| - onChange: jest.fn() |
| 48 | + onChange: jest.fn(), |
49 | 49 | };
|
50 | 50 | return render(<DynamicJsonForm {...defaultProps} {...props} />);
|
51 | 51 | };
|
52 | 52 |
|
53 |
| - describe('Basic Operations', () => { |
54 |
| - it('should render number input with step=1', () => { |
| 53 | + describe("Basic Operations", () => { |
| 54 | + it("should render number input with step=1", () => { |
55 | 55 | renderForm();
|
56 |
| - const input = screen.getByRole('spinbutton'); |
57 |
| - expect(input).toHaveProperty('type', 'number'); |
58 |
| - expect(input).toHaveProperty('step', '1'); |
| 56 | + const input = screen.getByRole("spinbutton"); |
| 57 | + expect(input).toHaveProperty("type", "number"); |
| 58 | + expect(input).toHaveProperty("step", "1"); |
59 | 59 | });
|
60 | 60 |
|
61 |
| - it('should pass integer values to onChange', () => { |
| 61 | + it("should pass integer values to onChange", () => { |
62 | 62 | const onChange = jest.fn();
|
63 | 63 | renderForm({ onChange });
|
64 |
| - |
65 |
| - const input = screen.getByRole('spinbutton'); |
66 |
| - fireEvent.change(input, { target: { value: '42' } }); |
67 |
| - |
| 64 | + |
| 65 | + const input = screen.getByRole("spinbutton"); |
| 66 | + fireEvent.change(input, { target: { value: "42" } }); |
| 67 | + |
68 | 68 | expect(onChange).toHaveBeenCalledWith(42);
|
69 | 69 | // Verify the value is a number, not a string
|
70 |
| - expect(typeof onChange.mock.calls[0][0]).toBe('number'); |
| 70 | + expect(typeof onChange.mock.calls[0][0]).toBe("number"); |
71 | 71 | });
|
72 | 72 |
|
73 |
| - it('should not pass string values to onChange', () => { |
| 73 | + it("should not pass string values to onChange", () => { |
74 | 74 | const onChange = jest.fn();
|
75 | 75 | renderForm({ onChange });
|
76 |
| - |
77 |
| - const input = screen.getByRole('spinbutton'); |
78 |
| - fireEvent.change(input, { target: { value: 'abc' } }); |
79 |
| - |
| 76 | + |
| 77 | + const input = screen.getByRole("spinbutton"); |
| 78 | + fireEvent.change(input, { target: { value: "abc" } }); |
| 79 | + |
80 | 80 | expect(onChange).not.toHaveBeenCalled();
|
81 | 81 | });
|
82 | 82 | });
|
83 | 83 |
|
84 |
| - describe('Edge Cases', () => { |
85 |
| - it('should handle non-numeric input by not calling onChange', () => { |
| 84 | + describe("Edge Cases", () => { |
| 85 | + it("should handle non-numeric input by not calling onChange", () => { |
86 | 86 | const onChange = jest.fn();
|
87 | 87 | renderForm({ onChange });
|
88 |
| - |
89 |
| - const input = screen.getByRole('spinbutton'); |
90 |
| - fireEvent.change(input, { target: { value: 'abc' } }); |
91 |
| - |
| 88 | + |
| 89 | + const input = screen.getByRole("spinbutton"); |
| 90 | + fireEvent.change(input, { target: { value: "abc" } }); |
| 91 | + |
92 | 92 | expect(onChange).not.toHaveBeenCalled();
|
93 | 93 | });
|
94 | 94 | });
|
|
0 commit comments