Skip to content

Commit f6eeb4e

Browse files
test: add test coverage for ClientFields (#1984)
Co-authored-by: Harsh Gupta <harsh16official@gmail.com> Co-authored-by: Adi Boghawala <adiboghawala@gmail.com>
1 parent b85c04e commit f6eeb4e

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 { ClientFields } from '../../components/ClientFields.js';
6+
7+
const parser = new Parser();
8+
const asyncapiFilePath = path.resolve(__dirname, '../../../../test/__fixtures__/asyncapi-websocket-components.yml');
9+
10+
describe('ClientFields component (integration with AsyncAPI document)', () => {
11+
let parsedAsyncAPIDocument;
12+
let channels;
13+
let queryParams;
14+
15+
beforeAll(async () => {
16+
const parseResult = await fromFile(parser, asyncapiFilePath).parse();
17+
parsedAsyncAPIDocument = parseResult.document;
18+
channels = parsedAsyncAPIDocument.channels();
19+
queryParams = getQueryParams(channels);
20+
});
21+
22+
test('renders base fields without query param fields when queryParams is null', () => {
23+
const result = render(
24+
<ClientFields
25+
queryParams={null}
26+
clientName="WebSocketClient"
27+
/>
28+
);
29+
expect(result.trim()).toMatchSnapshot();
30+
});
31+
32+
test('renders base fields without query param fields when queryParams is undefined', () => {
33+
const result = render(
34+
<ClientFields
35+
clientName="WebSocketClient"
36+
/>
37+
);
38+
expect(result.trim()).toMatchSnapshot();
39+
});
40+
41+
test('renders base fields without query param fields when queryParams is empty Map', () => {
42+
const emptyMap = new Map();
43+
const result = render(
44+
<ClientFields
45+
queryParams={emptyMap}
46+
clientName="WebSocketClient"
47+
/>
48+
);
49+
expect(result.trim()).toMatchSnapshot();
50+
});
51+
52+
test('renders base fields with query param fields when queryParams has data from fixture', () => {
53+
const result = render(
54+
<ClientFields
55+
queryParams={queryParams}
56+
clientName="WebSocketClient"
57+
/>
58+
);
59+
expect(result.trim()).toMatchSnapshot();
60+
});
61+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ClientFields component (integration with AsyncAPI document) renders base fields with query param fields when queryParams has data from fixture 1`] = `
4+
"@Inject
5+
public WebSocketClientConnection connection;
6+
7+
private static final Logger LOG = Logger.getLogger(WebSocketClient.class);
8+
9+
10+
private HashMap<String, String> params;
11+
private String heartbeat;
12+
private String bids;
13+
private String sessionId;"
14+
`;
15+
16+
exports[`ClientFields component (integration with AsyncAPI document) renders base fields without query param fields when queryParams is empty Map 1`] = `
17+
"@Inject
18+
public WebSocketClientConnection connection;
19+
20+
private static final Logger LOG = Logger.getLogger(WebSocketClient.class);"
21+
`;
22+
23+
exports[`ClientFields component (integration with AsyncAPI document) renders base fields without query param fields when queryParams is null 1`] = `
24+
"@Inject
25+
public WebSocketClientConnection connection;
26+
27+
private static final Logger LOG = Logger.getLogger(WebSocketClient.class);"
28+
`;
29+
30+
exports[`ClientFields component (integration with AsyncAPI document) renders base fields without query param fields when queryParams is undefined 1`] = `
31+
"@Inject
32+
public WebSocketClientConnection connection;
33+
34+
private static final Logger LOG = Logger.getLogger(WebSocketClient.class);"
35+
`;

0 commit comments

Comments
 (0)