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

Commit 252d03f

Browse files
test: added testcases for stream_types object
1 parent ade327e commit 252d03f

File tree

9 files changed

+267
-52
lines changed

9 files changed

+267
-52
lines changed

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

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,35 @@ const fakeItem = {
1313
},
1414
},
1515
properties: {
16-
recursive_item: {
16+
recursive_item_1: {
1717
description: 'This is a recursive item',
1818
},
19+
recursive_item_2: {
20+
description: 'This is recursive item 2',
21+
oneOf: 'This is oneOf key for recursive_item_2',
22+
},
23+
},
24+
definitions: {
25+
stream_types: {
26+
description: 'This stream_types description',
27+
type: 'string',
28+
enum: [
29+
'balance',
30+
'candles',
31+
'cashier_payments',
32+
'p2p_advert',
33+
'p2p_advertiser',
34+
'p2p_order',
35+
'proposal',
36+
'proposal_open_contract',
37+
'ticks',
38+
'transaction',
39+
'trading_platform_asset_listing',
40+
'website_status',
41+
'p2p_settings',
42+
'crypto_estimations',
43+
],
44+
},
1945
},
2046
};
2147

@@ -26,21 +52,43 @@ describe('RecursiveProperties', () => {
2652
is_open
2753
properties={fakeItem.properties || fakeItem?.items?.properties}
2854
value={fakeItem}
55+
jsonSchema={fakeItem}
2956
/>,
3057
);
3158
const recursion_1_description = await screen.findByText(/nested items/i);
3259
expect(recursion_1_description).toBeVisible();
3360

34-
const recursion_2_name = await screen.findByText(/recursive_item/i);
61+
const recursion_2_name = await screen.findByText(/recursive_item_1/i);
3562
expect(recursion_2_name).toBeVisible();
3663

3764
const recursion_2_description = await screen.findByText(/This is a recursive item/i);
3865
expect(recursion_2_description).toBeVisible();
66+
67+
const recursion_3_name = await screen.findByText(/recursive_item_2/i);
68+
expect(recursion_3_name).toBeVisible();
69+
70+
const recursion_3_description = await screen.findByText(/This is recursive item 2/i);
71+
expect(recursion_3_description).toBeVisible();
3972
});
4073

4174
it('renders only the description (last item) if there are no nested items anymore', async () => {
42-
render(<RecursiveProperties is_open properties={null} value={fakeItem} />);
75+
render(
76+
<RecursiveProperties is_open properties={null} value={fakeItem} jsonSchema={fakeItem} />,
77+
);
4378
const item = await screen.findByText(/This is the main item description/i);
4479
expect(item).toBeVisible();
4580
});
81+
82+
it('renders StreamTypesObject if value contains oneOf meaning its forgetAll api call', async () => {
83+
render(
84+
<RecursiveProperties
85+
is_open
86+
properties={null}
87+
value={fakeItem.properties.recursive_item_2}
88+
jsonSchema={fakeItem}
89+
/>,
90+
);
91+
const streamTypesObject = await screen.getByTestId('dt_stream_types_object');
92+
expect(streamTypesObject).toBeVisible();
93+
});
4694
});

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@ type TRecursiveProperties = {
77
is_open: boolean;
88
properties: any;
99
value: any;
10-
jsonSchema?: any;
10+
jsonSchema: any;
1111
};
1212

1313
const RecursiveProperties = ({ is_open, properties, value, jsonSchema }: TRecursiveProperties) => {
1414
const keys = properties && Object.keys(properties);
15+
1516
if (!is_open) {
16-
//if object is not open then ret null
1717
return null;
1818
}
19-
20-
if ('oneOf' in value) {
21-
return <StreamTypesObject definitions={jsonSchema.definitions} />;
19+
if (value && 'oneOf' in value) {
20+
return (
21+
<React.Fragment>
22+
<StreamTypesObject definitions={jsonSchema.definitions} />
23+
</React.Fragment>
24+
);
2225
}
23-
// this will be true when we are not inside properties obj? !!!!!!
2426
if (!keys) {
2527
return (
2628
<React.Fragment>
@@ -36,7 +38,6 @@ const RecursiveProperties = ({ is_open, properties, value, jsonSchema }: TRecurs
3638
{index === 0 && value?.items?.description && (
3739
<SchemaDescription description={value.items.description} />
3840
)}
39-
{/* check if its forgetAll Request not response */}
4041
{key === 'forget_all' && 'oneOf' in value[key] ? (
4142
<SchemaObjectContent
4243
key={key}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('SchemaBodyHeader', () => {
1616
title='test title'
1717
is_open_object
1818
setIsOpenObject={() => jest.fn()}
19+
is_stream_types={false}
1920
/>,
2021
);
2122
const type = await screen.findByText('number');
@@ -34,6 +35,7 @@ describe('SchemaBodyHeader', () => {
3435
title='test title'
3536
is_open_object
3637
setIsOpenObject={() => jest.fn()}
38+
is_stream_types={false}
3739
/>,
3840
);
3941
const type = await screen.findByText('array');
@@ -52,6 +54,7 @@ describe('SchemaBodyHeader', () => {
5254
title='test title'
5355
is_open_object
5456
setIsOpenObject={() => jest.fn()}
57+
is_stream_types={false}
5558
/>,
5659
);
5760
const type = await screen.findByText('integer');
@@ -70,6 +73,7 @@ describe('SchemaBodyHeader', () => {
7073
title='test title'
7174
is_open_object
7275
setIsOpenObject={() => jest.fn()}
76+
is_stream_types={false}
7377
/>,
7478
);
7579
const type = await screen.findByText('string');
@@ -88,6 +92,7 @@ describe('SchemaBodyHeader', () => {
8892
title='test title'
8993
is_open_object
9094
setIsOpenObject={() => jest.fn()}
95+
is_stream_types={false}
9196
/>,
9297
);
9398
const type = await screen.findByText(/number/i);
@@ -106,6 +111,7 @@ describe('SchemaBodyHeader', () => {
106111
title='test title'
107112
is_open_object
108113
setIsOpenObject={() => jest.fn()}
114+
is_stream_types={false}
109115
/>,
110116
);
111117
const type = await screen.findByText(/string/i);
@@ -124,6 +130,7 @@ describe('SchemaBodyHeader', () => {
124130
title='test title'
125131
is_open_object
126132
setIsOpenObject={() => jest.fn()}
133+
is_stream_types={false}
127134
/>,
128135
);
129136
const type = await screen.findByText(/array/i);
@@ -142,9 +149,33 @@ describe('SchemaBodyHeader', () => {
142149
title='test title'
143150
is_open_object
144151
setIsOpenObject={() => jest.fn()}
152+
is_stream_types={false}
145153
/>,
146154
);
147155
const type = await screen.findByText(/integer/i);
148156
expect(type).toBeVisible();
149157
});
158+
159+
it('should render the SchemaBodyHeader with oneOf stream_types array if is_stream_types is true', async () => {
160+
render(
161+
<SchemaBodyHeader
162+
key_value={null}
163+
type={null}
164+
defaultValue='default_test'
165+
pattern=''
166+
examples={null}
167+
enum={null}
168+
title=''
169+
is_open_object
170+
setIsOpenObject={() => jest.fn()}
171+
is_stream_types={true}
172+
/>,
173+
);
174+
const oneOfType = await screen.findByText(/one of/i);
175+
const stream_types = await screen.findByText(/stream_types/i);
176+
const array_type = await screen.findByText(/array/i);
177+
expect(oneOfType).toBeVisible();
178+
expect(stream_types).toBeVisible();
179+
expect(array_type).toBeVisible();
180+
});
150181
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type TSchemaBodyHeader = {
1212
setIsOpenObject: (boolean) => void;
1313
examples: string[];
1414
enum;
15-
is_stream_types?: boolean;
15+
is_stream_types: boolean;
1616
};
1717

1818
const SchemaBodyHeader = ({

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,37 @@ const fake_properties = {
2121
},
2222
};
2323

24+
const stream_types_schema = {
25+
properties: {
26+
test_property: {
27+
description: 'property description',
28+
oneOf: 'this is oneOf key',
29+
},
30+
},
31+
definitions: {
32+
stream_types: {
33+
description: 'This stream_types description',
34+
type: 'string',
35+
enum: [
36+
'balance',
37+
'candles',
38+
'cashier_payments',
39+
'p2p_advert',
40+
'p2p_advertiser',
41+
'p2p_order',
42+
'proposal',
43+
'proposal_open_contract',
44+
'ticks',
45+
'transaction',
46+
'trading_platform_asset_listing',
47+
'website_status',
48+
'p2p_settings',
49+
'crypto_estimations',
50+
],
51+
},
52+
},
53+
};
54+
2455
describe('SchemaObjectContent', () => {
2556
it('should be able to open a nested object item', async () => {
2657
render(<SchemaObjectContent key_value='test_item' properties={fake_properties} />);
@@ -96,4 +127,24 @@ describe('SchemaObjectContent', () => {
96127
const schema = await screen.findByTitle('JSON');
97128
expect(schema).toBeVisible();
98129
});
130+
131+
it('should open StreamTypesObject upon clicking stream_types button', async () => {
132+
render(
133+
<SchemaObjectContent
134+
key='test_property'
135+
key_value='test_property'
136+
properties={stream_types_schema.properties}
137+
jsonSchema={stream_types_schema}
138+
is_stream_types={true}
139+
/>,
140+
);
141+
142+
const button = await screen.findByRole('button', { name: /stream_types/i });
143+
expect(button).toBeVisible();
144+
145+
await userEvent.click(button);
146+
147+
const streamTypesObject = await screen.getByTestId('dt_stream_types_object');
148+
expect(streamTypesObject).toBeVisible();
149+
});
99150
});

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ type TSchemaObjectContent = {
1414
is_stream_types?: boolean;
1515
};
1616

17-
//json schema also here full obj
1817
export default function SchemaObjectContent({
1918
key_value,
2019
properties,
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from 'react';
2+
import userEvent from '@testing-library/user-event';
3+
import { screen, render } from '@testing-library/react';
4+
import StreamTypesObject from '..';
5+
6+
describe('StreamTypesObject', () => {
7+
const json_schema = {
8+
stream_types: {
9+
description: 'This stream_types description',
10+
type: 'string',
11+
enum: [
12+
'balance',
13+
'candles',
14+
'cashier_payments',
15+
'p2p_advert',
16+
'p2p_advertiser',
17+
'p2p_order',
18+
'proposal',
19+
'proposal_open_contract',
20+
'ticks',
21+
'transaction',
22+
'trading_platform_asset_listing',
23+
'website_status',
24+
'p2p_settings',
25+
'crypto_estimations',
26+
],
27+
},
28+
};
29+
30+
it('should render button that opens jsonschema', async () => {
31+
render(<StreamTypesObject definitions={json_schema} />);
32+
33+
const schema_button = await screen.findByText('{}');
34+
35+
expect(schema_button).toBeVisible();
36+
37+
await userEvent.click(schema_button);
38+
39+
const schema = await screen.findByTitle('JSON');
40+
expect(schema).toBeVisible();
41+
});
42+
43+
it('should render the header of the object', () => {
44+
render(<StreamTypesObject definitions={json_schema} />);
45+
46+
const header_title = screen.getAllByText(/stream_types/)[0];
47+
expect(header_title).toBeInTheDocument();
48+
49+
const header_description = screen.getByText(/This stream_types description/i);
50+
expect(header_description).toBeInTheDocument();
51+
});
52+
53+
it('should render the body of StreamTypesObject', () => {
54+
render(<StreamTypesObject definitions={json_schema} />);
55+
56+
const type = screen.getByText(/enum/i);
57+
expect(type).toBeInTheDocument();
58+
59+
const enum_type = screen.getByText(/string/i);
60+
expect(enum_type).toBeInTheDocument();
61+
62+
json_schema.stream_types.enum.map((item) => {
63+
const enum_name = screen.getByText(item);
64+
expect(enum_name).toBeInTheDocument();
65+
});
66+
});
67+
});

0 commit comments

Comments
 (0)