@aiready/components 0.14.4 → 0.14.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charts/ForceDirectedGraph.js.map +1 -1
- package/dist/hooks/useForceSimulation.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/charts/force-directed/useGraphInteractions.ts +2 -2
- package/src/charts/force-directed/useImperativeHandle.ts +1 -1
- package/src/components/__tests__/badge.test.tsx +38 -0
- package/src/components/__tests__/button.test.tsx +54 -0
- package/src/components/__tests__/card.test.tsx +56 -17
- package/src/components/__tests__/checkbox.test.tsx +28 -58
- package/src/components/__tests__/container.test.tsx +44 -51
- package/src/components/__tests__/grid.test.tsx +27 -134
- package/src/components/__tests__/input.test.tsx +35 -20
- package/src/components/__tests__/label.test.tsx +29 -35
- package/src/components/__tests__/modal.test.tsx +43 -72
- package/src/components/__tests__/select.test.tsx +51 -84
- package/src/components/__tests__/separator.test.tsx +23 -56
- package/src/components/__tests__/switch.test.tsx +28 -68
- package/src/components/__tests__/textarea.test.tsx +29 -77
- package/src/hooks/useForceSimulation.ts +2 -2
|
@@ -1,85 +1,45 @@
|
|
|
1
|
-
import { describe, it, expect
|
|
2
|
-
import { render, screen
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import { Switch } from '../switch';
|
|
4
4
|
|
|
5
5
|
describe('Switch', () => {
|
|
6
|
-
it('
|
|
7
|
-
render(<Switch />);
|
|
8
|
-
expect(screen.
|
|
6
|
+
it('renders switch', () => {
|
|
7
|
+
render(<Switch data-testid="switch" />);
|
|
8
|
+
expect(screen.getByTestId('switch')).toBeInTheDocument();
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
it('
|
|
12
|
-
render(<Switch
|
|
13
|
-
expect(screen.
|
|
11
|
+
it('applies custom className', () => {
|
|
12
|
+
render(<Switch className="custom-switch" data-testid="switch" />);
|
|
13
|
+
expect(screen.getByTestId('switch')).toHaveClass('custom-switch');
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
it('
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
it('renders as button role', () => {
|
|
17
|
+
render(<Switch data-testid="switch" />);
|
|
18
|
+
const switchEl = screen.getByTestId('switch');
|
|
19
|
+
expect(switchEl).toHaveAttribute('role', 'switch');
|
|
19
20
|
});
|
|
20
21
|
|
|
21
|
-
it('
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
it('has unchecked state by default', () => {
|
|
23
|
+
render(<Switch data-testid="switch" />);
|
|
24
|
+
const switchEl = screen.getByTestId('switch');
|
|
25
|
+
expect(switchEl).toHaveAttribute('aria-checked', 'false');
|
|
24
26
|
});
|
|
25
27
|
|
|
26
|
-
it('
|
|
27
|
-
render(<Switch checked
|
|
28
|
-
|
|
28
|
+
it('can be checked', () => {
|
|
29
|
+
render(<Switch checked data-testid="switch" />);
|
|
30
|
+
const switchEl = screen.getByTestId('switch');
|
|
31
|
+
expect(switchEl).toHaveAttribute('aria-checked', 'true');
|
|
29
32
|
});
|
|
30
33
|
|
|
31
|
-
it('
|
|
32
|
-
render(<Switch
|
|
33
|
-
|
|
34
|
+
it('is disabled when disabled prop is true', () => {
|
|
35
|
+
render(<Switch disabled data-testid="switch" />);
|
|
36
|
+
const switchEl = screen.getByTestId('switch');
|
|
37
|
+
expect(switchEl).toBeDisabled();
|
|
34
38
|
});
|
|
35
39
|
|
|
36
|
-
it('
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
expect(handleChange).toHaveBeenCalledTimes(1);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should call onCheckedChange when clicked', () => {
|
|
44
|
-
const handleCheckedChange = vi.fn();
|
|
45
|
-
render(<Switch onCheckedChange={handleCheckedChange} />);
|
|
46
|
-
fireEvent.click(screen.getByRole('checkbox'));
|
|
47
|
-
expect(handleCheckedChange).toHaveBeenCalledTimes(1);
|
|
48
|
-
expect(handleCheckedChange).toHaveBeenCalledWith(true);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should call onCheckedChange with false when unchecking', () => {
|
|
52
|
-
const handleCheckedChange = vi.fn();
|
|
53
|
-
render(<Switch checked onCheckedChange={handleCheckedChange} />);
|
|
54
|
-
fireEvent.click(screen.getByRole('checkbox'));
|
|
55
|
-
expect(handleCheckedChange).toHaveBeenCalledWith(false);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should be disabled when disabled prop is set', () => {
|
|
59
|
-
render(<Switch disabled />);
|
|
60
|
-
expect(screen.getByRole('checkbox')).toBeDisabled();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should forward ref', () => {
|
|
64
|
-
const ref = { current: null };
|
|
65
|
-
render(<Switch ref={ref} />);
|
|
66
|
-
expect(ref.current).not.toBeNull();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should use provided id', () => {
|
|
70
|
-
render(<Switch id="custom-id" label="Test" />);
|
|
71
|
-
const checkbox = screen.getByRole('checkbox');
|
|
72
|
-
expect(checkbox).toHaveAttribute('id', 'custom-id');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should generate unique id when not provided', () => {
|
|
76
|
-
render(<Switch label="Test" />);
|
|
77
|
-
const checkbox = screen.getByRole('checkbox');
|
|
78
|
-
expect(checkbox).toHaveAttribute('id');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should have sr-only class on input', () => {
|
|
82
|
-
render(<Switch />);
|
|
83
|
-
expect(screen.getByRole('checkbox')).toHaveClass('sr-only');
|
|
40
|
+
it('has default styling', () => {
|
|
41
|
+
render(<Switch data-testid="switch" />);
|
|
42
|
+
const switchEl = screen.getByTestId('switch');
|
|
43
|
+
expect(switchEl).toHaveClass('peer', 'inline-flex');
|
|
84
44
|
});
|
|
85
45
|
});
|
|
@@ -1,96 +1,48 @@
|
|
|
1
|
-
import { describe, it, expect
|
|
2
|
-
import { render, screen
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import { Textarea } from '../textarea';
|
|
4
4
|
|
|
5
5
|
describe('Textarea', () => {
|
|
6
|
-
it('
|
|
7
|
-
render(<Textarea />);
|
|
8
|
-
expect(screen.
|
|
6
|
+
it('renders textarea', () => {
|
|
7
|
+
render(<Textarea data-testid="textarea" />);
|
|
8
|
+
expect(screen.getByTestId('textarea')).toBeInTheDocument();
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
it('
|
|
12
|
-
|
|
13
|
-
expect(
|
|
11
|
+
it('applies custom className', () => {
|
|
12
|
+
render(<Textarea className="custom-textarea" data-testid="textarea" />);
|
|
13
|
+
expect(screen.getByTestId('textarea')).toHaveClass('custom-textarea');
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
it('
|
|
17
|
-
render(<Textarea
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
it('should forward ref', () => {
|
|
22
|
-
const ref = { current: null };
|
|
23
|
-
render(<Textarea ref={ref} />);
|
|
24
|
-
expect(ref.current).not.toBeNull();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should be disabled when disabled prop is set', () => {
|
|
28
|
-
render(<Textarea disabled />);
|
|
29
|
-
expect(screen.getByRole('textbox')).toBeDisabled();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should handle value prop', () => {
|
|
33
|
-
render(<Textarea value="test value" readOnly />);
|
|
34
|
-
expect(screen.getByRole('textbox')).toHaveValue('test value');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should spread additional props', () => {
|
|
38
|
-
const { container } = render(<Textarea data-testid="textarea" />);
|
|
39
|
-
expect(container.firstChild).toHaveAttribute('data-testid', 'textarea');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should call onChange when text is entered', () => {
|
|
43
|
-
const handleChange = vi.fn();
|
|
44
|
-
render(<Textarea onChange={handleChange} />);
|
|
45
|
-
fireEvent.change(screen.getByRole('textbox'), {
|
|
46
|
-
target: { value: 'new text' },
|
|
47
|
-
});
|
|
48
|
-
expect(handleChange).toHaveBeenCalledTimes(1);
|
|
16
|
+
it('renders as textarea element', () => {
|
|
17
|
+
render(<Textarea data-testid="textarea" />);
|
|
18
|
+
const textarea = screen.getByTestId('textarea');
|
|
19
|
+
expect(textarea.tagName).toBe('TEXTAREA');
|
|
49
20
|
});
|
|
50
21
|
|
|
51
|
-
it('
|
|
52
|
-
|
|
53
|
-
expect(
|
|
54
|
-
'flex',
|
|
55
|
-
'min-h-[80px]',
|
|
56
|
-
'w-full',
|
|
57
|
-
'rounded-md'
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should render as a textarea element', () => {
|
|
62
|
-
render(<Textarea />);
|
|
63
|
-
expect(screen.getByRole('textbox').tagName).toBe('TEXTAREA');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should support rows attribute', () => {
|
|
67
|
-
render(<Textarea rows={5} />);
|
|
68
|
-
expect(screen.getByRole('textbox')).toHaveAttribute('rows', '5');
|
|
22
|
+
it('accepts placeholder', () => {
|
|
23
|
+
render(<Textarea placeholder="Enter text" />);
|
|
24
|
+
expect(screen.getByPlaceholderText('Enter text')).toBeInTheDocument();
|
|
69
25
|
});
|
|
70
26
|
|
|
71
|
-
it('
|
|
72
|
-
render(<Textarea
|
|
73
|
-
expect(screen.
|
|
27
|
+
it('is disabled when disabled prop is true', () => {
|
|
28
|
+
render(<Textarea disabled data-testid="textarea" />);
|
|
29
|
+
expect(screen.getByTestId('textarea')).toBeDisabled();
|
|
74
30
|
});
|
|
75
31
|
|
|
76
|
-
it('
|
|
77
|
-
const
|
|
78
|
-
|
|
32
|
+
it('forwards ref correctly', () => {
|
|
33
|
+
const ref = { current: null };
|
|
34
|
+
render(<Textarea ref={ref} />);
|
|
35
|
+
expect(ref.current).toBeInstanceOf(HTMLTextAreaElement);
|
|
79
36
|
});
|
|
80
37
|
|
|
81
|
-
it('
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
'focus-visible:ring-ring'
|
|
86
|
-
);
|
|
38
|
+
it('has default styling', () => {
|
|
39
|
+
render(<Textarea data-testid="textarea" />);
|
|
40
|
+
const textarea = screen.getByTestId('textarea');
|
|
41
|
+
expect(textarea).toHaveClass('flex', 'min-h-[80px]', 'w-full');
|
|
87
42
|
});
|
|
88
43
|
|
|
89
|
-
it('
|
|
90
|
-
|
|
91
|
-
expect(
|
|
92
|
-
'disabled:cursor-not-allowed',
|
|
93
|
-
'disabled:opacity-50'
|
|
94
|
-
);
|
|
44
|
+
it('accepts rows prop', () => {
|
|
45
|
+
render(<Textarea rows={5} data-testid="textarea" />);
|
|
46
|
+
expect(screen.getByTestId('textarea')).toHaveAttribute('rows', '5');
|
|
95
47
|
});
|
|
96
48
|
});
|
|
@@ -89,7 +89,7 @@ export function useForceSimulation(
|
|
|
89
89
|
typeof l.target === 'string'
|
|
90
90
|
? l.target
|
|
91
91
|
: (l.target as SimulationNode)?.id;
|
|
92
|
-
const linkType = (l as
|
|
92
|
+
const linkType = (l as { type?: string }).type || '';
|
|
93
93
|
return `${sourceId}->${targetId}:${linkType}`;
|
|
94
94
|
})
|
|
95
95
|
.join('|');
|
|
@@ -156,7 +156,7 @@ export function useForceSimulation(
|
|
|
156
156
|
const linkForce = d3
|
|
157
157
|
.forceLink<SimulationNode, SimulationLink>(linksCopy)
|
|
158
158
|
.id((d) => d.id)
|
|
159
|
-
.distance((d) => (d as
|
|
159
|
+
.distance((d) => (d as { distance?: number }).distance ?? linkDistance)
|
|
160
160
|
.strength(linkStrength);
|
|
161
161
|
|
|
162
162
|
simulation
|