|
1 | 1 | import renderer from 'react-test-renderer';
|
2 |
| -import userEvent from '@testing-library/user-event'; |
3 |
| -import { screen, render, waitFor } from '@testing-library/react'; |
4 | 2 | import JsonView from './';
|
5 | 3 |
|
6 |
| -const mySet = new Set(); |
7 |
| -mySet.add(1); // Set(1) { 1 } |
8 |
| -mySet.add(5); // Set(2) { 1, 5 } |
9 |
| -mySet.add(5); // Set(2) { 1, 5 } |
10 |
| -mySet.add('some text'); // Set(3) { 1, 5, 'some text' } |
11 |
| - |
12 |
| -const myMap = new Map(); |
13 |
| -myMap.set('www', 'foo'); |
14 |
| -myMap.set(1, 'bar'); |
15 |
| - |
16 | 4 | const avatar = 'https://i.imgur.com/MK3eW3As.jpg';
|
17 | 5 | const longArray = new Array(1000).fill(1);
|
18 | 6 | const example = {
|
@@ -59,140 +47,3 @@ it('renders <JsonView /> test case', () => {
|
59 | 47 | expect(tree).toHaveProperty('props.onMouseEnter');
|
60 | 48 | expect(tree).toHaveProperty('props.onMouseLeave');
|
61 | 49 | });
|
62 |
| - |
63 |
| -it('renders <JsonView.String /> test case', async () => { |
64 |
| - const demo = { |
65 |
| - string: 'Lorem ipsum dolor sit amet', |
66 |
| - }; |
67 |
| - const { container } = render( |
68 |
| - <JsonView value={demo}> |
69 |
| - <JsonView.String |
70 |
| - render={(props, { type }) => { |
71 |
| - if (type === 'type') { |
72 |
| - expect(props.style).toHaveProperty('color', 'var(--w-rjv-type-string-color, #cb4b16)'); |
73 |
| - return <em {...props} data-testid="str-type" />; |
74 |
| - } |
75 |
| - return <span {...props} data-testid="str-value" />; |
76 |
| - }} |
77 |
| - /> |
78 |
| - </JsonView>, |
79 |
| - ); |
80 |
| - expect(container.firstElementChild).toBeInstanceOf(Element); |
81 |
| - await waitFor(() => { |
82 |
| - const type = screen.getByTestId('str-type'); |
83 |
| - expect(type.className).toBe('w-rjv-type'); |
84 |
| - expect(type.tagName).toBe('EM'); |
85 |
| - expect(type.innerHTML).toBe('string'); |
86 |
| - const value = screen.getByTestId('str-value'); |
87 |
| - expect(value.className).toBe('w-rjv-value'); |
88 |
| - expect(value.tagName).toBe('SPAN'); |
89 |
| - expect(value).toHaveProperty('style.cursor', 'pointer'); |
90 |
| - }); |
91 |
| -}); |
92 |
| - |
93 |
| -[ |
94 |
| - { |
95 |
| - name: 'Bigint', |
96 |
| - Comp: JsonView.Bigint, |
97 |
| - value: BigInt(10086), |
98 |
| - field: 'bigint', |
99 |
| - color: 'var(--w-rjv-type-bigint-color, #268bd2)', |
100 |
| - }, |
101 |
| - { |
102 |
| - name: 'False', |
103 |
| - Comp: JsonView.False, |
104 |
| - value: false, |
105 |
| - field: 'bool', |
106 |
| - color: 'var(--w-rjv-type-boolean-color, #2aa198)', |
107 |
| - }, |
108 |
| - { |
109 |
| - name: 'Float', |
110 |
| - Comp: JsonView.Float, |
111 |
| - value: 0.3, |
112 |
| - field: 'float', |
113 |
| - color: 'var(--w-rjv-type-float-color, #859900)', |
114 |
| - }, |
115 |
| - { |
116 |
| - name: 'Int', |
117 |
| - Comp: JsonView.Int, |
118 |
| - value: 123, |
119 |
| - field: 'int', |
120 |
| - color: 'var(--w-rjv-type-int-color, #268bd2)', |
121 |
| - }, |
122 |
| - { |
123 |
| - name: 'True', |
124 |
| - Comp: JsonView.True, |
125 |
| - value: true, |
126 |
| - field: 'bool', |
127 |
| - color: 'var(--w-rjv-type-boolean-color, #2aa198)', |
128 |
| - }, |
129 |
| - { |
130 |
| - name: 'Null', |
131 |
| - Comp: JsonView.Null, |
132 |
| - value: null, |
133 |
| - field: 'null', |
134 |
| - color: 'var(--w-rjv-type-null-color, #d33682)', |
135 |
| - }, |
136 |
| - { |
137 |
| - name: 'Undefined', |
138 |
| - Comp: JsonView.Undefined, |
139 |
| - value: undefined, |
140 |
| - field: 'undefined', |
141 |
| - color: 'var(--w-rjv-type-undefined-color, #586e75)', |
142 |
| - }, |
143 |
| - // { |
144 |
| - // name: 'Nan', |
145 |
| - // Comp: JsonView.Nan, |
146 |
| - // value: NaN, |
147 |
| - // field: 'NaN', |
148 |
| - // color: 'var(--w-rjv-type-nan-color, #859900)', |
149 |
| - // }, |
150 |
| - // { |
151 |
| - // name: 'Date', |
152 |
| - // Comp: JsonView.Date, |
153 |
| - // value: new Date('2023/02/12'), |
154 |
| - // field: 'date', |
155 |
| - // color: 'var(--w-rjv-type-date-color, #268bd2)', |
156 |
| - // }, |
157 |
| - // { |
158 |
| - // name: 'Url', |
159 |
| - // Comp: JsonView.Url, |
160 |
| - // value: new URL('https://www.google.com'), |
161 |
| - // field: 'url', |
162 |
| - // color: 'var(--w-rjv-type-url-color, #0969da)', |
163 |
| - // }, |
164 |
| - // { |
165 |
| - // name: 'Map', |
166 |
| - // Comp: JsonView.Map, |
167 |
| - // value: myMap, |
168 |
| - // field: 'map', |
169 |
| - // color: 'var(--w-rjv-type-map-color, #268bd2)', |
170 |
| - // }, |
171 |
| -].forEach(({ name, value: val, field, color, Comp }) => { |
172 |
| - it(`renders <JsonView.${name} /> test case`, async () => { |
173 |
| - const demo = { |
174 |
| - value: val, |
175 |
| - }; |
176 |
| - const { container } = render( |
177 |
| - <JsonView value={demo}> |
178 |
| - <Comp |
179 |
| - render={(props, { type, value }) => { |
180 |
| - expect(value).toBe(val); |
181 |
| - expect(props.style).toHaveProperty('color', color); |
182 |
| - return <span {...props} data-testid={`${name}-${type}`} />; |
183 |
| - }} |
184 |
| - /> |
185 |
| - </JsonView>, |
186 |
| - ); |
187 |
| - expect(container.firstElementChild).toBeInstanceOf(Element); |
188 |
| - await waitFor(() => { |
189 |
| - const type = screen.getByTestId(`${name}-type`); |
190 |
| - expect(type.className).toBe('w-rjv-type'); |
191 |
| - expect(type.tagName).toBe('SPAN'); |
192 |
| - expect(type.innerHTML).toBe(field); |
193 |
| - const value = screen.getByTestId(`${name}-value`); |
194 |
| - expect(value.className).toBe('w-rjv-value'); |
195 |
| - expect(value.tagName).toBe('SPAN'); |
196 |
| - }); |
197 |
| - }); |
198 |
| -}); |
0 commit comments