Skip to content

Commit bd1eae1

Browse files
committed
test: add editor test case.
1 parent 824ce05 commit bd1eae1

File tree

3 files changed

+127
-5
lines changed

3 files changed

+127
-5
lines changed

core/src/copied.test.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import renderer from 'react-test-renderer';
2-
import {cleanup, screen, fireEvent, render} from '@testing-library/react';
3-
import { act } from 'react-dom/test-utils';
4-
import ReactDOM from 'react-dom/client';
5-
import userEvent from '@testing-library/user-event'
2+
import { cleanup, screen, fireEvent, render } from '@testing-library/react';
3+
import userEvent from '@testing-library/user-event';
64
import { Copied } from './copied';
75

86
it('renders <Copied /> test case', () => {
@@ -31,6 +29,21 @@ it('renders <Copied /> `show` test case', () => {
3129
expect(tree).toHaveProperty('props.onClick');
3230
});
3331

32+
it('renders <Copied /> `click` test case', async () => {
33+
const user = userEvent.setup();
34+
render(<Copied text={{ a: 1 }} show data-testid="demo2" />);
35+
const elm = screen.getByTestId('demo2');
36+
await user.click(elm);
37+
expect(elm).toBeInstanceOf(SVGSVGElement);
38+
const elme = screen.getByTestId('demo2');
39+
expect(typeof elme).toEqual('object');
40+
expect(elm.style).toHaveProperty('cursor', 'pointer');
41+
expect(elm.style).toHaveProperty('vertical-align', 'middle');
42+
expect(elm.style).toHaveProperty('margin-left', '5px');
43+
expect(elm.getAttribute('fill')).toEqual('var(--w-rjv-copied-success-color, #28a745)');
44+
// screen.debug();
45+
});
46+
3447
it('renders <Copied /> `show` test case', () => {
3548
function TriangleArrow(props: any) {
3649
const { style, ...reset } = props;

core/src/editor/countInfoExtra.test.tsx

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import renderer from 'react-test-renderer';
2+
import { cleanup, screen, fireEvent, render } from '@testing-library/react';
3+
import userEvent from '@testing-library/user-event';
24
import { CountInfoExtra } from './countInfoExtra';
35

46

@@ -31,4 +33,85 @@ it('renders <CountInfoExtra /> onAdd test case', () => {
3133
height: '1em',
3234
width: '1em',
3335
});
34-
});
36+
});
37+
38+
it('renders <CountInfoExtra /> onDelete/parentValue test case', () => {
39+
const component = renderer.create(
40+
<CountInfoExtra editable parentValue={{ ab: 1 }} visible showTools value={{ a: 123 }} onDelete={() => true} onAdd={() => true} />
41+
);
42+
let tree = component.toJSON();
43+
expect(Array.isArray(tree)).toBe(true);
44+
if (Array.isArray(tree)) {
45+
const child1 = tree[1];
46+
expect(child1).toHaveProperty('type');
47+
expect(child1).toHaveProperty('props');
48+
expect(child1).toHaveProperty('children');
49+
expect(child1).toHaveProperty('type', 'svg');
50+
expect(child1).toHaveProperty('props.fill', 'var(--w-rjv-delete-color, #dc3545)')
51+
expect(child1).toHaveProperty('props.viewBox', '0 0 40 40')
52+
expect(child1).toHaveProperty('props.style', {
53+
verticalAlign: 'middle',
54+
display: 'inline-block',
55+
cursor: 'pointer',
56+
marginLeft: 5,
57+
height: '1em',
58+
width: '1em',
59+
});
60+
}
61+
});
62+
63+
it('renders <CountInfoExtra /> `onDelete/onAdd` test case', async () => {
64+
const user = userEvent.setup();
65+
const { container } = render(
66+
<CountInfoExtra
67+
editable
68+
visible
69+
showTools
70+
keyName="ab"
71+
parentValue={{ ab: { a: 123 } }}
72+
value={{ a: 123 }}
73+
onDelete={(keyName, value, parentValue) => {
74+
expect(keyName).toEqual('ab');
75+
return true;
76+
}}
77+
setValue={() => { }}
78+
setParentValue={() => { }}
79+
onAdd={(keyOrValue) => {
80+
expect(keyOrValue).toEqual('AddKeyOrValue');
81+
return true
82+
}}
83+
/>
84+
);
85+
expect(container.firstElementChild).toBeInstanceOf(SVGSVGElement);
86+
await user.click(container.firstElementChild!);
87+
expect(container.lastElementChild).toBeInstanceOf(SVGSVGElement);
88+
await user.click(container.lastElementChild!);
89+
});
90+
91+
it('renders <CountInfoExtra /> `onDelete/onAdd` test case', async () => {
92+
const user = userEvent.setup();
93+
const { container } = render(
94+
<CountInfoExtra
95+
editable
96+
visible
97+
showTools
98+
keyName={0}
99+
parentValue={['ab', 1, 3]}
100+
value={['ab', 1, 3]}
101+
onDelete={(keyName, value, parentValue) => {
102+
expect(keyName).toEqual(0);
103+
return true;
104+
}}
105+
setValue={() => { }}
106+
setParentValue={() => { }}
107+
onAdd={(keyOrValue) => {
108+
expect(keyOrValue).toEqual('AddKeyOrValue');
109+
return true
110+
}}
111+
/>
112+
);
113+
expect(container.firstElementChild).toBeInstanceOf(SVGSVGElement);
114+
await user.click(container.firstElementChild!);
115+
expect(container.lastElementChild).toBeInstanceOf(SVGSVGElement);
116+
await user.click(container.lastElementChild!);
117+
});

core/src/editor/value.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,30 @@ it('renders <ReValue /> quotes test case', () => {
118118
expect(tree[2]).toHaveProperty('props.style', { color: 'var(--w-rjv-type-string-color, #cb4b16)' });
119119
expect(tree[2]).toHaveProperty('props.data-value', '"test"');
120120
}
121+
});
122+
123+
124+
it('renders <ReValue /> onDelete test case', () => {
125+
const component = renderer.create(
126+
<ReValue type="string" displayDataTypes quotes="'" value="test" visible={true} editableValue={true} onDelete={() => true} />,
127+
);
128+
const tree = component.toJSON();
129+
expect(Array.isArray(tree)).toBe(true);
130+
if (Array.isArray(tree)) {
131+
expect(tree).toHaveLength(5);
132+
const child1 = tree[4];
133+
expect(child1).toHaveProperty('props');
134+
expect(child1).toHaveProperty('type', 'svg');
135+
expect(child1).toHaveProperty('props.style', {
136+
verticalAlign: 'middle',
137+
display: 'inline-block',
138+
cursor: 'pointer',
139+
marginLeft: 5,
140+
height: '1em',
141+
width: '1em'
142+
});
143+
expect(child1).toHaveProperty('props.onClick');
144+
expect(child1).toHaveProperty('props.fill', 'var(--w-rjv-delete-color, #dc3545)');
145+
expect(child1).toHaveProperty('props.viewBox', '0 0 40 40');
146+
}
121147
});

0 commit comments

Comments
 (0)