Skip to content

Commit 19b03f9

Browse files
test: add test coverage for ConstructorSignature (#1968)
Co-authored-by: Harsh Gupta <harsh16official@gmail.com> Co-authored-by: Adi Boghawala <adiboghawala@gmail.com>
1 parent e43f7e9 commit 19b03f9

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import path from 'path';
2+
import { render } from '@asyncapi/generator-react-sdk';
3+
import { Parser, fromFile } from '@asyncapi/parser';
4+
import { getQueryParams } from '@asyncapi/generator-helpers';
5+
import { ConstructorSignature } from '../../components/ConstructorSignature.js';
6+
7+
const parser = new Parser();
8+
const asyncapiFilePath = path.resolve(__dirname, '../../../../test/__fixtures__/asyncapi-websocket-components.yml');
9+
10+
describe('ConstructorSignature component (integration with AsyncAPI document)', () => {
11+
let parsedAsyncAPIDocument;
12+
let channels;
13+
let queryParamsArray;
14+
15+
beforeAll(async () => {
16+
const parseResult = await fromFile(parser, asyncapiFilePath).parse();
17+
parsedAsyncAPIDocument = parseResult.document;
18+
channels = parsedAsyncAPIDocument.channels();
19+
20+
const queryParams = getQueryParams(channels);
21+
queryParamsArray = queryParams ? Array.from(queryParams.entries()) : null;
22+
});
23+
24+
test('renders nothing when queryParams is null', () => {
25+
const result = render(
26+
<ConstructorSignature
27+
clientName="WebSocketClient"
28+
queryParams={null}
29+
/>
30+
);
31+
expect(result.trim()).toMatchSnapshot();
32+
});
33+
34+
test('renders nothing when queryParams is undefined', () => {
35+
const result = render(
36+
<ConstructorSignature
37+
clientName="WebSocketClient"
38+
/>
39+
);
40+
expect(result.trim()).toMatchSnapshot();
41+
});
42+
43+
test('renders constructor signature with empty parameters when queryParams is empty array', () => {
44+
const result = render(
45+
<ConstructorSignature
46+
clientName="WebSocketClient"
47+
queryParams={[]}
48+
/>
49+
);
50+
expect(result.trim()).toMatchSnapshot();
51+
});
52+
53+
test('renders constructor signature with query parameters from fixture', () => {
54+
const result = render(
55+
<ConstructorSignature
56+
clientName="WebSocketClient"
57+
queryParams={queryParamsArray}
58+
/>
59+
);
60+
expect(result.trim()).toMatchSnapshot();
61+
});
62+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ConstructorSignature component (integration with AsyncAPI document) renders constructor signature with empty parameters when queryParams is empty array 1`] = `"public WebSocketClient(){"`;
4+
5+
exports[`ConstructorSignature component (integration with AsyncAPI document) renders constructor signature with query parameters from fixture 1`] = `"public WebSocketClient(String heartbeat, String bids, String sessionId){"`;
6+
7+
exports[`ConstructorSignature component (integration with AsyncAPI document) renders nothing when queryParams is null 1`] = `""`;
8+
9+
exports[`ConstructorSignature component (integration with AsyncAPI document) renders nothing when queryParams is undefined 1`] = `""`;

0 commit comments

Comments
 (0)