Skip to content

Commit 14c197a

Browse files
KunalNasaderberg
andauthored
test: add test for AvailableOperations component (#1569)
Co-authored-by: KunalNasa <kunalnasa.dev@gmail.com> Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
1 parent d1f8b4b commit 14c197a

File tree

4 files changed

+118
-1
lines changed

4 files changed

+118
-1
lines changed

packages/templates/clients/websocket/javascript/components/AvailableOperations.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import OperationHeader from './OperationHeader';
33
import MessageExamples from './MessageExamples';
44

55
export function AvailableOperations({ operations }) {
6+
if (!operations || operations.length === 0) {
7+
return null;
8+
}
69
return (
710
<>
811
<Text newLines={2}>### Available Operations</Text>

packages/templates/clients/websocket/javascript/template/README.md.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Registers a callback to handle WebSocket errors.
4646
#### \`close()\`
4747
Closes the WebSocket connection.`}
4848
</Text>
49-
{operations.length > 0 && <AvailableOperations operations={operations} />}
49+
<AvailableOperations operations={operations} />
5050
<Text newLines={2}>
5151
{`## Testing the client
5252
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import path from 'path';
2+
import { render } from '@asyncapi/generator-react-sdk';
3+
import { Parser, fromFile } from '@asyncapi/parser';
4+
import { AvailableOperations } from '../../components/AvailableOperations';
5+
6+
const parser = new Parser();
7+
const asyncapi_websocket_query = path.resolve(__dirname, '../../../../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
8+
9+
describe('Testing AvailableOperations component', () => {
10+
let parsedAsyncAPIDocument;
11+
beforeAll(async () => {
12+
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
13+
parsedAsyncAPIDocument = parseResult.document;
14+
});
15+
16+
test('Must render all available operations', () => {
17+
const operations = parsedAsyncAPIDocument.operations().all();
18+
const result = render(<AvailableOperations operations={operations} />);
19+
const actual = result.trim();
20+
expect(actual).toMatchSnapshot();
21+
});
22+
23+
test('Must not render anything if operations are passed as empty array.', () => {
24+
const result = render(<AvailableOperations operations={[]} />);
25+
const actual = result.trim();
26+
expect(actual).toBe('');
27+
});
28+
test('Must not render anything if operations are passed as null', () => {
29+
const result = render(<AvailableOperations operations={null} />);
30+
const actual = result.trim();
31+
expect(actual).toBe('');
32+
});
33+
});
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Testing AvailableOperations component Must render all available operations 1`] = `
4+
"### Available Operations
5+
6+
#### \`noMessage(payload)\`
7+
Operation with no messages
8+
9+
10+
11+
12+
#### \`noMessageExamples(payload)\`
13+
Message without any examples
14+
15+
16+
17+
18+
#### \`oneMessageExample(payload)\`
19+
One message with one example
20+
21+
22+
23+
**Example:**
24+
\`\`\`javascript
25+
client.oneMessageExample(\\"test\\");
26+
\`\`\`
27+
28+
29+
30+
#### \`multipleExamples(payload)\`
31+
Multiple messages with examples
32+
33+
34+
35+
**Example:**
36+
\`\`\`javascript
37+
client.multipleExamples(\\"test\\");
38+
\`\`\`
39+
40+
41+
**Example:**
42+
\`\`\`javascript
43+
client.multipleExamples(false);
44+
\`\`\`
45+
46+
47+
**Example:**
48+
\`\`\`javascript
49+
client.multipleExamples(123);
50+
\`\`\`
51+
52+
53+
54+
#### \`mixedMessageExamples(payload)\`
55+
Mixed message example coverage
56+
57+
58+
59+
**Example:**
60+
\`\`\`javascript
61+
client.mixedMessageExamples(\\"test\\");
62+
\`\`\`
63+
64+
65+
**Example:**
66+
\`\`\`javascript
67+
client.mixedMessageExamples(\\"test\\");
68+
\`\`\`
69+
70+
71+
**Example:**
72+
\`\`\`javascript
73+
client.mixedMessageExamples(false);
74+
\`\`\`
75+
76+
77+
**Example:**
78+
\`\`\`javascript
79+
client.mixedMessageExamples(123);
80+
\`\`\`"
81+
`;

0 commit comments

Comments
 (0)