Skip to content

Commit 2a5e412

Browse files
committed
test: add index test case.
1 parent dea3520 commit 2a5e412

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

core/src/Container.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const Container = forwardRef(<T extends object>(props: ContainerProps<T>,
1818
const dispatch = useShowToolsDispatch();
1919
useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(ref, () => $ref.current, [$ref]);
2020
const subkeyid = useId();
21-
const defaultClassNames = `w-rjv-inner ${className}`;
21+
const defaultClassNames = [className, 'w-rjv-inner'].filter(Boolean).join(' ');
2222
const reset: React.HTMLAttributes<HTMLDivElement> = {
2323
onMouseEnter: () => dispatch({ [subkeyid]: true }),
2424
onMouseLeave: () => dispatch({ [subkeyid]: false }),

core/src/index.test.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import renderer from 'react-test-renderer';
2+
import JsonView from './';
3+
4+
const avatar = 'https://i.imgur.com/MK3eW3As.jpg';
5+
const longArray = new Array(1000).fill(1);
6+
const example = {
7+
avatar,
8+
string: 'Lorem ipsum dolor sit amet',
9+
integer: 42,
10+
float: 114.514,
11+
// @ts-ignore
12+
bigint: 10086n,
13+
null: null,
14+
undefined,
15+
timer: 0,
16+
date: new Date('Tue Sep 13 2022 14:07:44 GMT-0500 (Central Daylight Time)'),
17+
array: [19, 100.86, 'test', NaN, Infinity],
18+
nestedArray: [
19+
[1, 2],
20+
[3, 4],
21+
],
22+
object: {
23+
'first-child': true,
24+
'second-child': false,
25+
'last-child': null,
26+
},
27+
longArray,
28+
string_number: '1234',
29+
};
30+
31+
it('renders <JsonView /> test case', () => {
32+
const component = renderer.create(<JsonView value={example} />);
33+
let tree = component.toJSON();
34+
expect(tree).toHaveProperty('type');
35+
expect(tree).toHaveProperty('props');
36+
expect(tree).toHaveProperty('children');
37+
expect(tree).toHaveProperty('type', 'div');
38+
expect(tree).toHaveProperty('props.className', 'w-json-view-container w-rjv w-rjv-inner');
39+
expect(tree).toHaveProperty('props.style.backgroundColor', 'var(--w-rjv-background-color, #00000000)');
40+
expect(tree).toHaveProperty('props.style', {
41+
lineHeight: 1.4,
42+
fontSize: 13,
43+
fontFamily: 'var(--w-rjv-font-family, Menlo, monospace)',
44+
color: 'var(--w-rjv-color, #002b36)',
45+
backgroundColor: 'var(--w-rjv-background-color, #00000000)',
46+
});
47+
expect(tree).toHaveProperty('props.onMouseEnter');
48+
expect(tree).toHaveProperty('props.onMouseLeave');
49+
});

core/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const JsonView: JsonViewComponent = forwardRef<HTMLDivElement, JsonViewProps<obj
123123
fontSize: 13,
124124
...style,
125125
} as React.CSSProperties;
126-
const cls = `w-json-view-container w-rjv ${className || ''}`;
126+
const cls = ['w-json-view-container', 'w-rjv', className].filter(Boolean).join(' ');
127127
return (
128128
<Provider
129129
initialState={{

0 commit comments

Comments
 (0)