Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 5a3a61d

Browse files
test: testcases for new components and added crypto_config to playground_requests
1 parent 7ec69b4 commit 5a3a61d

File tree

8 files changed

+354
-28
lines changed

8 files changed

+354
-28
lines changed

src/features/Apiexplorer/Schema/RecursiveContent/RecursiveProperties/__tests__/RecursiveProperties.test.tsx

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,36 @@ const fakeItem = {
2020
description: 'This is recursive item 2',
2121
oneOf: 'This is oneOf key for recursive_item_2',
2222
},
23+
recursive_item_3: {
24+
description: 'This is recursive item 3',
25+
oneOf: [
26+
{
27+
description: 'This is object 1',
28+
type: 'string',
29+
},
30+
{
31+
description: 'This is object 2',
32+
type: 'object',
33+
properties: {
34+
property_1: {
35+
description: 'item 1',
36+
type: 'string',
37+
enum: ['deposit', 'withdraw'],
38+
},
39+
property_2: {
40+
description: 'item 2',
41+
type: 'object',
42+
properties: {
43+
property_2_1: {
44+
description: 'item 3',
45+
type: 'string',
46+
},
47+
},
48+
},
49+
},
50+
},
51+
],
52+
},
2353
},
2454
definitions: {
2555
stream_types: {
@@ -59,16 +89,19 @@ describe('RecursiveProperties', () => {
5989
expect(recursion_1_description).toBeVisible();
6090

6191
const recursion_2_name = await screen.findByText(/recursive_item_1/i);
62-
expect(recursion_2_name).toBeVisible();
63-
6492
const recursion_2_description = await screen.findByText(/This is a recursive item/i);
93+
expect(recursion_2_name).toBeVisible();
6594
expect(recursion_2_description).toBeVisible();
6695

6796
const recursion_3_name = await screen.findByText(/recursive_item_2/i);
68-
expect(recursion_3_name).toBeVisible();
69-
7097
const recursion_3_description = await screen.findByText(/This is recursive item 2/i);
98+
expect(recursion_3_name).toBeVisible();
7199
expect(recursion_3_description).toBeVisible();
100+
101+
const recursion_4_name = await screen.findByText(/recursive_item_3/i);
102+
const recursion_4_description = await screen.findByText(/This is recursive item 3/i);
103+
expect(recursion_4_name).toBeVisible();
104+
expect(recursion_4_description).toBeVisible();
72105
});
73106

74107
it('renders only the description (last item) if there are no nested items anymore', async () => {
@@ -79,7 +112,7 @@ describe('RecursiveProperties', () => {
79112
expect(item).toBeVisible();
80113
});
81114

82-
it('renders StreamTypesObject if value contains oneOf meaning its forgetAll api call', async () => {
115+
it('renders StreamTypesObject for forgetAll api call', async () => {
83116
render(
84117
<RecursiveProperties
85118
is_open
@@ -91,4 +124,19 @@ describe('RecursiveProperties', () => {
91124
const streamTypesObject = await screen.getByTestId('dt_stream_types_object');
92125
expect(streamTypesObject).toBeVisible();
93126
});
127+
128+
it('renders SchemaOneOfObjectContent if the value of key inside property schema contains oneOf', async () => {
129+
render(
130+
<RecursiveProperties
131+
is_open
132+
properties={fakeItem.properties}
133+
value={fakeItem.properties}
134+
jsonSchema={fakeItem}
135+
/>,
136+
);
137+
const schemaOneOfObjectContent = await screen.getAllByTestId(
138+
'dt_schema_oneof_object_content',
139+
)[0];
140+
expect(schemaOneOfObjectContent).toBeVisible();
141+
});
94142
});

src/features/Apiexplorer/Schema/RecursiveContent/SchemaBodyHeader/__tests__/SchemaBodyHeader.test.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('SchemaBodyHeader', () => {
1717
is_open_object
1818
setIsOpenObject={() => jest.fn()}
1919
is_stream_types={false}
20+
items_type={undefined}
2021
/>,
2122
);
2223
const type = await screen.findByText('number');
@@ -36,6 +37,7 @@ describe('SchemaBodyHeader', () => {
3637
is_open_object
3738
setIsOpenObject={() => jest.fn()}
3839
is_stream_types={false}
40+
items_type={undefined}
3941
/>,
4042
);
4143
const type = await screen.findByText('array');
@@ -55,6 +57,7 @@ describe('SchemaBodyHeader', () => {
5557
is_open_object
5658
setIsOpenObject={() => jest.fn()}
5759
is_stream_types={false}
60+
items_type={undefined}
5861
/>,
5962
);
6063
const type = await screen.findByText('integer');
@@ -74,6 +77,7 @@ describe('SchemaBodyHeader', () => {
7477
is_open_object
7578
setIsOpenObject={() => jest.fn()}
7679
is_stream_types={false}
80+
items_type={undefined}
7781
/>,
7882
);
7983
const type = await screen.findByText('string');
@@ -93,6 +97,7 @@ describe('SchemaBodyHeader', () => {
9397
is_open_object
9498
setIsOpenObject={() => jest.fn()}
9599
is_stream_types={false}
100+
items_type={undefined}
96101
/>,
97102
);
98103
const type = await screen.findByText(/number/i);
@@ -112,6 +117,7 @@ describe('SchemaBodyHeader', () => {
112117
is_open_object
113118
setIsOpenObject={() => jest.fn()}
114119
is_stream_types={false}
120+
items_type={undefined}
115121
/>,
116122
);
117123
const type = await screen.findByText(/string/i);
@@ -131,6 +137,7 @@ describe('SchemaBodyHeader', () => {
131137
is_open_object
132138
setIsOpenObject={() => jest.fn()}
133139
is_stream_types={false}
140+
items_type={undefined}
134141
/>,
135142
);
136143
const type = await screen.findByText(/array/i);
@@ -150,6 +157,7 @@ describe('SchemaBodyHeader', () => {
150157
is_open_object
151158
setIsOpenObject={() => jest.fn()}
152159
is_stream_types={false}
160+
items_type={undefined}
153161
/>,
154162
);
155163
const type = await screen.findByText(/integer/i);
@@ -169,6 +177,7 @@ describe('SchemaBodyHeader', () => {
169177
is_open_object
170178
setIsOpenObject={() => jest.fn()}
171179
is_stream_types={true}
180+
items_type={undefined}
172181
/>,
173182
);
174183
const oneOfType = await screen.findByText(/one of/i);
@@ -178,4 +187,24 @@ describe('SchemaBodyHeader', () => {
178187
expect(stream_types).toBeVisible();
179188
expect(array_type).toBeVisible();
180189
});
190+
191+
it('should render the SchemaBodyHeader for array with items type', async () => {
192+
render(
193+
<SchemaBodyHeader
194+
key_value='test_key_value'
195+
type={'array'}
196+
defaultValue='default_test'
197+
pattern='some_test_pattern'
198+
examples={['example1', 'example2']}
199+
enum={['test1', 'test2']}
200+
title={undefined}
201+
is_open_object
202+
setIsOpenObject={() => jest.fn()}
203+
is_stream_types={false}
204+
items_type={'string'}
205+
/>,
206+
);
207+
const type = await screen.findByText(/string/i);
208+
expect(type).toBeVisible();
209+
});
181210
});
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import React from 'react';
2+
import SchemaOneOfBodyHeader from '..';
3+
import { screen, render } from '@testing-library/react';
4+
5+
describe('SchemaOneOfBodyHeader', () => {
6+
it('should render SchemaOneOfBodyHeader with button having object type as display name', () => {
7+
render(
8+
<SchemaOneOfBodyHeader
9+
key_title={'cashier'}
10+
oneOf={[
11+
{
12+
description: 'description 1',
13+
type: 'string',
14+
},
15+
{
16+
description: 'description 1',
17+
type: 'number',
18+
},
19+
{
20+
description: 'description 2',
21+
type: 'object',
22+
},
23+
]}
24+
updateIndexArray={() => jest.fn()}
25+
/>,
26+
);
27+
const one_of = screen.getByText(/one of/i);
28+
const button_1 = screen.getByRole('button', {
29+
name: /string/i,
30+
});
31+
const button_2 = screen.getByRole('button', {
32+
name: /object/i,
33+
});
34+
const button_3 = screen.getByRole('button', {
35+
name: /number/i,
36+
});
37+
expect(one_of).toBeInTheDocument();
38+
expect(button_1).toBeInTheDocument();
39+
expect(button_2).toBeInTheDocument();
40+
expect(button_3).toBeInTheDocument();
41+
});
42+
43+
it('should render SchemaOneOfBodyHeader with button having object type as display name', () => {
44+
render(
45+
<SchemaOneOfBodyHeader
46+
key_title={'cashier'}
47+
oneOf={[
48+
{
49+
description: 'description 1',
50+
type: 'string',
51+
title: 'some title',
52+
},
53+
{
54+
description: 'description 2',
55+
type: 'null',
56+
},
57+
]}
58+
updateIndexArray={() => jest.fn()}
59+
/>,
60+
);
61+
const one_of = screen.getByText(/one of/i);
62+
const button_1 = screen.getByRole('button', {
63+
name: /some title/i,
64+
});
65+
const button_2 = screen.getByRole('button', {
66+
name: /null/i,
67+
});
68+
expect(one_of).toBeInTheDocument();
69+
expect(button_1).toBeInTheDocument();
70+
expect(button_2).toBeInTheDocument();
71+
});
72+
73+
it('should render SchemaOneOfBodyHeader with pattern', () => {
74+
render(
75+
<SchemaOneOfBodyHeader
76+
key_title={'cashier'}
77+
oneOf={[
78+
{
79+
type: 'integer',
80+
pattern: 'some regex pattern',
81+
},
82+
{
83+
type: 'array',
84+
items: {
85+
type: 'string',
86+
pattern: 'some regex pattern',
87+
},
88+
},
89+
]}
90+
updateIndexArray={() => jest.fn()}
91+
/>,
92+
);
93+
const one_of = screen.getByText(/one of/i);
94+
const type_1 = screen.getByText(/integer/i);
95+
const pattern = screen.getByText(/some regex pattern/i);
96+
const type_2 = screen.getByText(/array/i);
97+
98+
expect(one_of).toBeInTheDocument();
99+
expect(type_1).toBeInTheDocument();
100+
expect(pattern).toBeInTheDocument();
101+
expect(type_2).toBeInTheDocument();
102+
});
103+
});

src/features/Apiexplorer/Schema/RecursiveContent/SchemaOneOfBodyHeader/index.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import styles from '../../Schema.module.scss';
44
type TSchemaOneOfBodyHeader = {
55
key_title: string;
66
oneOf: Record<string, any>[];
7-
updateIndexArray;
7+
updateIndexArray: (index: number) => void;
88
};
99

1010
const SchemaOneOfBodyHeader = ({ key_title, oneOf, updateIndexArray }: TSchemaOneOfBodyHeader) => {
11-
let previous_pattern = '';
1211
const generateClassName = (type) => {
1312
let typeClass;
1413
switch (type) {
@@ -44,12 +43,6 @@ const SchemaOneOfBodyHeader = ({ key_title, oneOf, updateIndexArray }: TSchemaOn
4443
oneOf.map((object, index) => {
4544
const show_btn = object?.description || object?.properties;
4645
const typeClassName = generateClassName(object?.type);
47-
if (
48-
index !== 0 &&
49-
(object?.pattern || object?.item?.pattern) !== previous_pattern
50-
) {
51-
previous_pattern = object.pattern;
52-
}
5346

5447
return (
5548
<React.Fragment key={index}>
@@ -67,9 +60,7 @@ const SchemaOneOfBodyHeader = ({ key_title, oneOf, updateIndexArray }: TSchemaOn
6760
)}
6861
{'pattern' in object && (
6962
<div className={styles.schemaRegexContainer}>
70-
{previous_pattern !== object.pattern && (
71-
<span className={styles.schemaBodyPattern}>{object.pattern}</span>
72-
)}
63+
<span className={styles.schemaBodyPattern}>{object.pattern}</span>
7364
</div>
7465
)}
7566
</div>

0 commit comments

Comments
 (0)