Skip to content

Commit cab1ed3

Browse files
committed
Add some json form tests and handle css in ui tests
1 parent 61e229a commit cab1ed3

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

client/jest.config.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module.exports = {
22
preset: "ts-jest",
33
testEnvironment: "jsdom",
44
moduleNameMapper: {
5-
"^@/(.*)$": "<rootDir>/src/$1"
5+
"^@/(.*)$": "<rootDir>/src/$1",
6+
"\\.css$": "<rootDir>/src/__mocks__/styleMock.js"
67
},
78
transform: {
89
"^.+\\.tsx?$": [

client/src/__mocks__/styleMock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
6+
describe('DynamicJsonForm Integer Fields', () => {
7+
const renderForm = (props = {}) => {
8+
const defaultProps = {
9+
schema: {
10+
type: "integer" as const,
11+
description: "Test integer field"
12+
} satisfies JsonSchemaType,
13+
value: undefined,
14+
onChange: jest.fn()
15+
};
16+
return render(<DynamicJsonForm {...defaultProps} {...props} />);
17+
};
18+
19+
describe('Basic Operations', () => {
20+
it('should render number input with step=1', () => {
21+
renderForm();
22+
const input = screen.getByRole('spinbutton');
23+
expect(input).toHaveProperty('type', 'number');
24+
expect(input).toHaveProperty('step', '1');
25+
});
26+
27+
it('should pass integer values to onChange', () => {
28+
const onChange = jest.fn();
29+
renderForm({ onChange });
30+
31+
const input = screen.getByRole('spinbutton');
32+
fireEvent.change(input, { target: { value: '42' } });
33+
34+
expect(onChange).toHaveBeenCalledWith(42);
35+
// Verify the value is a number, not a string
36+
expect(typeof onChange.mock.calls[0][0]).toBe('number');
37+
});
38+
39+
it('should not pass string values to onChange', () => {
40+
const onChange = jest.fn();
41+
renderForm({ onChange });
42+
43+
const input = screen.getByRole('spinbutton');
44+
fireEvent.change(input, { target: { value: 'abc' } });
45+
46+
expect(onChange).not.toHaveBeenCalled();
47+
});
48+
});
49+
50+
describe('Edge Cases', () => {
51+
it('should handle non-numeric input by not calling onChange', () => {
52+
const onChange = jest.fn();
53+
renderForm({ onChange });
54+
55+
const input = screen.getByRole('spinbutton');
56+
fireEvent.change(input, { target: { value: 'abc' } });
57+
58+
expect(onChange).not.toHaveBeenCalled();
59+
});
60+
});
61+
});

0 commit comments

Comments
 (0)