Skip to content

Commit 34586ef

Browse files
Adi-204derberg
andauthored
test: add test for python QueryParamsArgumentsDocs (#1588)
Co-authored-by: Adi-204 <adiboghawala@gmail.com> Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
1 parent 0f775e5 commit 34586ef

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 { QueryParamsArgumentsDocs } from '../../components/QueryParamsArgumentsDocs';
6+
7+
const parser = new Parser();
8+
const asyncapiFilePath = path.resolve(__dirname, '../../../../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
9+
10+
describe('QueryParamsArgumentsDocs component (integration with AsyncAPI document)', () => {
11+
let parsedAsyncAPIDocument;
12+
13+
beforeAll(async () => {
14+
const parseResult = await fromFile(parser, asyncapiFilePath).parse();
15+
parsedAsyncAPIDocument = parseResult.document;
16+
});
17+
18+
test('render documentation for WebSocket query parameters when they exist in the AsyncAPI document', () => {
19+
const channels = parsedAsyncAPIDocument.channels();
20+
const queryParams = getQueryParams(channels);
21+
const queryParamsArray = queryParams && Array.from(queryParams.entries());
22+
const result = render(<QueryParamsArgumentsDocs queryParams={queryParamsArray} />);
23+
expect(result.trim()).toMatchSnapshot();
24+
});
25+
26+
test('render nothing when empty query parameters array is provided', () => {
27+
const result = render(<QueryParamsArgumentsDocs queryParams={[]} />);
28+
expect(result.trim()).toMatchSnapshot();
29+
});
30+
31+
test('render nothing when no query parameters are provided (null input)', () => {
32+
const result = render(<QueryParamsArgumentsDocs queryParams={null} />);
33+
expect(result.trim()).toMatchSnapshot();
34+
});
35+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`QueryParamsArgumentsDocs component (integration with AsyncAPI document) render documentation for WebSocket query parameters when they exist in the AsyncAPI document 1`] = `
4+
"heartbeat (str, optional):If provided (or if HEARTBEAT environment variable is set), added as ?heartbeat=… to URL
5+
top_of_book (str, optional):If provided (or if TOP_OF_BOOK environment variable is set), added as ?top_of_book=… to URL
6+
bids (str, optional):If provided (or if BIDS environment variable is set), added as ?bids=… to URL
7+
offers (str, optional):If provided (or if OFFERS environment variable is set), added as ?offers=… to URL"
8+
`;
9+
10+
exports[`QueryParamsArgumentsDocs component (integration with AsyncAPI document) render nothing when empty query parameters array is provided 1`] = `""`;
11+
12+
exports[`QueryParamsArgumentsDocs component (integration with AsyncAPI document) render nothing when no query parameters are provided (null input) 1`] = `""`;

0 commit comments

Comments
 (0)