Skip to content

Commit 6e8f60e

Browse files
batchu5Adi-204
andauthored
test: add tests for Readme component (#1953)
Co-authored-by: Varshitha Besthavemula <varshithabesthavemula@gmail.com> Co-authored-by: Adi Boghawala <adiboghawala@gmail.com>
1 parent 19b03f9 commit 6e8f60e

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import path from 'path';
2+
import { render } from '@asyncapi/generator-react-sdk';
3+
import { Parser, fromFile } from '@asyncapi/parser';
4+
import { Readme } from '../../src/components/readme/Readme';
5+
6+
const parser = new Parser();
7+
const asyncapi_websocket_query = path.resolve(__dirname, '../__fixtures__/asyncapi-v3.yml');
8+
9+
describe('Testing of Readme component', () => {
10+
let parsedAsyncAPIDocument;
11+
12+
const languageConfigs = [
13+
{ language: 'javascript', clientFileName: 'myClient.js' },
14+
{ language: 'python', clientFileName: 'myClient.py' },
15+
];
16+
17+
beforeAll(async () => {
18+
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
19+
parsedAsyncAPIDocument = parseResult.document;
20+
});
21+
22+
languageConfigs.forEach(({ language, clientFileName }) => {
23+
test(`render Readme with language = ${language}`, () => {
24+
const params = {
25+
server: 'production',
26+
appendClientSuffix: true,
27+
customClientName: 'AccountServiceClient',
28+
clientFileName
29+
};
30+
const result = render(
31+
<Readme
32+
asyncapi={parsedAsyncAPIDocument}
33+
params={params}
34+
language={language}
35+
/>
36+
);
37+
38+
const actual = result.trim();
39+
expect(actual).toMatchSnapshot();
40+
});
41+
});
42+
});
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Testing of Readme component render Readme with language = javascript 1`] = `
4+
"# Account Service
5+
6+
## Overview
7+
8+
This service is in charge of processing user signups
9+
10+
- **Version:** 1.0.0
11+
- **Server URL:** ws://api.example.com
12+
13+
14+
## Installation
15+
16+
Install dependencies:
17+
18+
\`\`\`bash
19+
npm install
20+
\`\`\`
21+
22+
23+
## Usage
24+
25+
\`\`\`javascript
26+
const AccountServiceClient = require('./myClient');
27+
const wsClient = new AccountServiceClient();
28+
29+
async function main() {
30+
try {
31+
await wsClient.connect();
32+
// use wsClient to send/receive messages
33+
await wsClient.close();
34+
} catch (error) {
35+
console.error('Failed to connect:', error);
36+
}
37+
}
38+
39+
main();
40+
\`\`\`
41+
42+
43+
## API
44+
45+
### \`connect()\`
46+
Establishes a WebSocket connection.
47+
48+
### \`registerMessageHandler(handlerFunction)\`
49+
Registers a callback for incoming messages.
50+
51+
### \`registerErrorHandler(handlerFunction)\`
52+
Registers a callback for connection errors.
53+
54+
### \`close()\`
55+
Closes the WebSocket connection.
56+
57+
58+
### Available Operations
59+
60+
#### \`sendUserSignedup(payload)\`"
61+
`;
62+
63+
exports[`Testing of Readme component render Readme with language = python 1`] = `
64+
"# Account Service
65+
66+
## Overview
67+
68+
This service is in charge of processing user signups
69+
70+
- **Version:** 1.0.0
71+
- **Server URL:** ws://api.example.com
72+
73+
74+
## Installation
75+
76+
Install dependencies:
77+
78+
\`\`\`bash
79+
pip install -r requirements.txt
80+
\`\`\`
81+
82+
83+
## Usage
84+
85+
\`\`\`python
86+
from myClient import AccountServiceClient
87+
88+
ws_client = AccountServiceClient()
89+
90+
async def main():
91+
await ws_client.connect()
92+
# use ws_client to send/receive messages
93+
await ws_client.close()
94+
\`\`\`
95+
96+
97+
## API
98+
99+
### \`connect()\`
100+
Establishes a WebSocket connection.
101+
102+
### \`register_message_handler(handler_function)\`
103+
Registers a callback for incoming messages.
104+
105+
### \`register_error_handler(handler_function)\`
106+
Registers a callback for connection errors.
107+
108+
### \`close()\`
109+
Closes the WebSocket connection.
110+
111+
112+
### Available Operations
113+
114+
#### \`sendUserSignedup(payload)\`"
115+
`;

0 commit comments

Comments
 (0)