Skip to content

Commit 630c937

Browse files
ItshMohderberg
andauthored
test: add the snapshot test for the InitSignature.js (#1575)
Co-authored-by: ItshMoh <mohan.kumar.min22@itbhu.ac.in> Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
1 parent 14c197a commit 630c937

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import path from 'path';
2+
import { render } from '@asyncapi/generator-react-sdk';
3+
import { Parser, fromFile } from '@asyncapi/parser';
4+
import { getServer, getServerUrl, getQueryParams } from '@asyncapi/generator-helpers';
5+
import { InitSignature } from '../../components/InitSignature.js';
6+
7+
const parser = new Parser();
8+
const asyncapiFilePath = path.resolve(__dirname, '../../../../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
9+
10+
describe('InitSignature component (integration with AsyncAPI document)', () => {
11+
let servers;
12+
let parsedAsyncAPIDocument;
13+
14+
beforeAll(async () => {
15+
const parseResult = await fromFile(parser, asyncapiFilePath).parse();
16+
parsedAsyncAPIDocument = parseResult.document;
17+
servers = parsedAsyncAPIDocument.servers();
18+
});
19+
20+
test('renders with only serverUrl (no query parameters)', () => {
21+
const server = getServer(servers, 'withHostDuplicatingProtocol');
22+
const serverUrl = getServerUrl(server);
23+
const result = render(<InitSignature queryParams={null} serverUrl={serverUrl} />);
24+
expect(result.trim()).toMatchSnapshot();
25+
});
26+
27+
test('renders with empty query parameters array', () => {
28+
const server = getServer(servers, 'withVariables');
29+
const serverUrl = getServerUrl(server);
30+
const result = render(<InitSignature queryParams={[]} serverUrl={serverUrl} />);
31+
expect(result.trim()).toMatchSnapshot();
32+
});
33+
34+
test('renders with single query parameter with default value false', () => {
35+
const server = getServer(servers, 'withPathname');
36+
const serverUrl = getServerUrl(server);
37+
const queryParamsWithFalseDefault = [['heartbeat', 'false']];
38+
const result = render(<InitSignature queryParams={queryParamsWithFalseDefault} serverUrl={serverUrl} />);
39+
expect(result.trim()).toMatchSnapshot();
40+
});
41+
42+
test('renders with single query parameter with default value true', () => {
43+
const server = getServer(servers, 'withoutPathName');
44+
const serverUrl = getServerUrl(server);
45+
const queryParamsWithTrueDefault = [['bids', 'true']];
46+
const result = render(<InitSignature queryParams={queryParamsWithTrueDefault} serverUrl={serverUrl} />);
47+
expect(result.trim()).toMatchSnapshot();
48+
});
49+
50+
test('renders with multiple query parameters with mixed default values', () => {
51+
const server = getServer(servers, 'withVariables');
52+
const serverUrl = getServerUrl(server);
53+
const channels = parsedAsyncAPIDocument.channels();
54+
const queryParams = getQueryParams(channels);
55+
const queryParamsArray = queryParams && Array.from(queryParams.entries());
56+
const result = render(<InitSignature queryParams={queryParamsArray} serverUrl={serverUrl} />);
57+
expect(result.trim()).toMatchSnapshot();
58+
});
59+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`InitSignature component (integration with AsyncAPI document) renders with empty query parameters array 1`] = `"def __init__(self, url: str = \\"wss://api.gemini.com/v1/marketdata/{symbol}\\", ):"`;
4+
5+
exports[`InitSignature component (integration with AsyncAPI document) renders with multiple query parameters with mixed default values 1`] = `"def __init__(self, url: str = \\"wss://api.gemini.com/v1/marketdata/{symbol}\\", heartbeat: str = \\"false\\", top_of_book: str = \\"false\\", bids: str = \\"true\\", offers: str = None):"`;
6+
7+
exports[`InitSignature component (integration with AsyncAPI document) renders with only serverUrl (no query parameters) 1`] = `"def __init__(self, url: str = \\"wss://api.gemini.com\\"):"`;
8+
9+
exports[`InitSignature component (integration with AsyncAPI document) renders with single query parameter with default value false 1`] = `"def __init__(self, url: str = \\"wss://api.gemini.com/v1/marketdata\\", heartbeat: str = \\"false\\"):"`;
10+
11+
exports[`InitSignature component (integration with AsyncAPI document) renders with single query parameter with default value true 1`] = `"def __init__(self, url: str = \\"wss://api.gemini.com\\", bids: str = \\"true\\"):"`;

0 commit comments

Comments
 (0)