Skip to content

Commit 915249f

Browse files
test: add tests and snapshot for QueryParamsVariables component (#1622)
Co-authored-by: ANIRUDH <anirudhnarang0@gmail.com> Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
1 parent 1b21c32 commit 915249f

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 { QueryParamsVariables } from '../../components/QueryParamsVariables.js';
6+
7+
const parser = new Parser();
8+
const asyncapiFilePath = path.resolve(
9+
__dirname,
10+
'../../../../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml'
11+
);
12+
13+
describe('QueryParamsVariables component (integration with AsyncAPI document)', () => {
14+
let parsedAsyncAPIDocument;
15+
16+
beforeAll(async () => {
17+
const parseResult = await fromFile(parser, asyncapiFilePath).parse();
18+
parsedAsyncAPIDocument = parseResult.document;
19+
});
20+
21+
test('renders correctly with query parameters', () => {
22+
const channels = parsedAsyncAPIDocument.channels();
23+
const queryParamsObject = getQueryParams(channels);
24+
const queryParamsArray = queryParamsObject ? Array.from(queryParamsObject.entries()) : [];
25+
const result = render(<QueryParamsVariables queryParams={queryParamsArray} />);
26+
expect(result.trim()).toMatchSnapshot();
27+
});
28+
29+
test('renders nothing when queryParams is null', () => {
30+
const result = render(<QueryParamsVariables queryParams={null} />);
31+
expect(result.trim()).toMatchSnapshot();
32+
});
33+
34+
test('renders nothing when queryParams is undefined', () => {
35+
const result = render(<QueryParamsVariables />);
36+
expect(result.trim()).toMatchSnapshot();
37+
});
38+
39+
test('renders nothing when queryParams is an empty array', () => {
40+
const result = render(<QueryParamsVariables queryParams={[]} />);
41+
expect(result.trim()).toMatchSnapshot();
42+
});
43+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`QueryParamsVariables component (integration with AsyncAPI document) renders correctly with query parameters 1`] = `
4+
"heartbeat = heartbeat or os.getenv(\\"HEARTBEAT\\")
5+
if heartbeat is not None:
6+
params[\\"heartbeat\\"] = heartbeat
7+
top_of_book = top_of_book or os.getenv(\\"TOP_OF_BOOK\\")
8+
if top_of_book is not None:
9+
params[\\"top_of_book\\"] = top_of_book
10+
bids = bids or os.getenv(\\"BIDS\\")
11+
if bids is not None:
12+
params[\\"bids\\"] = bids
13+
offers = offers or os.getenv(\\"OFFERS\\")
14+
if offers is not None:
15+
params[\\"offers\\"] = offers"
16+
`;
17+
18+
exports[`QueryParamsVariables component (integration with AsyncAPI document) renders nothing when queryParams is an empty array 1`] = `""`;
19+
20+
exports[`QueryParamsVariables component (integration with AsyncAPI document) renders nothing when queryParams is null 1`] = `""`;
21+
22+
exports[`QueryParamsVariables component (integration with AsyncAPI document) renders nothing when queryParams is undefined 1`] = `""`;

0 commit comments

Comments
 (0)