Skip to content

Commit 43ee7c3

Browse files
Harsh16guptaAdi-204
andcommitted
test: add test coverage for Constructor (asyncapi#1949)
Co-authored-by: Harsh Gupta <harsh16official@gmail.com> Co-authored-by: Adi Boghawala <adiboghawala@gmail.com>
1 parent 9496baa commit 43ee7c3

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 { Constructor } from '../../components/Constructor';
6+
7+
const parser = new Parser();
8+
const asyncapiFilePath = path.resolve(__dirname, '../../../../test/__fixtures__/asyncapi-websocket-components.yml');
9+
10+
describe('Constructor 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 nothing when query is null', () => {
23+
const result = render(<Constructor clientName="WebSocketClient" query={null} />);
24+
expect(result.trim()).toMatchSnapshot();
25+
});
26+
27+
test('renders nothing when query has no entries', () => {
28+
const emptyQuery = new Map();
29+
const result = render(<Constructor clientName="WebSocketClient" query={emptyQuery} />);
30+
expect(result.trim()).toMatchSnapshot();
31+
});
32+
33+
test('renders constructor when query parameters are present', () => {
34+
const result = render(<Constructor clientName="WebSocketClient" query={queryParams} />);
35+
expect(result.trim()).toMatchSnapshot();
36+
});
37+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Constructor component (integration with AsyncAPI document) renders constructor when query parameters are present 1`] = `
4+
"public WebSocketClient(){
5+
this(\\"false\\", \\"true\\", null);
6+
}
7+
8+
public WebSocketClient(String heartbeat, String bids, String sessionId){
9+
params = new HashMap<>();
10+
this.heartbeat = (heartbeat != null && !heartbeat.isEmpty()) ? heartbeat : System.getenv(\\"HEARTBEAT\\");
11+
if (this.heartbeat != null){
12+
params.put(\\"heartbeat\\", this.heartbeat);
13+
}
14+
this.bids = (bids != null && !bids.isEmpty()) ? bids : System.getenv(\\"BIDS\\");
15+
if (this.bids != null){
16+
params.put(\\"bids\\", this.bids);
17+
}
18+
this.sessionId = (sessionId != null && !sessionId.isEmpty()) ? sessionId : System.getenv(\\"SESSIONID\\");
19+
if (this.sessionId != null){
20+
params.put(\\"sessionId\\", this.sessionId);
21+
}
22+
}"
23+
`;
24+
25+
exports[`Constructor component (integration with AsyncAPI document) renders nothing when query has no entries 1`] = `""`;
26+
27+
exports[`Constructor component (integration with AsyncAPI document) renders nothing when query is null 1`] = `""`;

0 commit comments

Comments
 (0)