Skip to content

Commit 8a7a126

Browse files
test: add snapshot tests for Send.js component (#1606)
Co-authored-by: Pradyumn Chauhan <140681043+PradyumnChauhan@users.noreply.github.com>
1 parent 003a0a2 commit 8a7a126

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import path from 'path';
2+
import { render } from '@asyncapi/generator-react-sdk';
3+
import { Parser, fromFile } from '@asyncapi/parser';
4+
import { Send } from '../../components/Send';
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 of Send component', () => {
10+
let parsedAsyncAPIDocument;
11+
12+
beforeAll(async () => {
13+
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
14+
parsedAsyncAPIDocument = parseResult.document;
15+
});
16+
17+
test('render Send component with send operations', () => {
18+
const sendOperations = parsedAsyncAPIDocument.operations().filterBySend();
19+
const result = render(<Send sendOperations={sendOperations} />);
20+
const actual = result.trim();
21+
expect(actual).toMatchSnapshot();
22+
});
23+
24+
test('renders nothing when send operations is empty', () => {
25+
const result = render(<Send sendOperations={[]} />);
26+
const actual = result.trim();
27+
expect(actual).toMatchSnapshot();
28+
});
29+
test('render nothing when send operations is null', () => {
30+
const result = render(<Send sendOperations={null} />);
31+
const actual = result.trim();
32+
expect(actual).toMatchSnapshot();
33+
});
34+
test('renders nothing without send operations', () => {
35+
const result = render(<Send />);
36+
const actual = result.trim();
37+
expect(actual).toMatchSnapshot();
38+
});
39+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Testing of Send component render Send component with send operations 1`] = `
4+
"@staticmethod
5+
async def _send(message, socket):
6+
\\"\\"\\"
7+
Internal helper to handle the actual sending logic.
8+
9+
Args:
10+
message (dict or str): The message to send.
11+
socket (websockets.WebSocketCommonProtocol): The WebSocket to send through.
12+
13+
Notes:
14+
If message is a dictionary, it will be automatically converted to JSON.
15+
\\"\\"\\"
16+
try:
17+
if isinstance(message, dict):
18+
message = json.dumps(message)
19+
await socket.send(message)
20+
except Exception as e:
21+
print(\\"Error sending:\\", e)"
22+
`;
23+
24+
exports[`Testing of Send component render nothing when send operations is null 1`] = `""`;
25+
26+
exports[`Testing of Send component renders nothing when send operations is empty 1`] = `""`;
27+
28+
exports[`Testing of Send component renders nothing without send operations 1`] = `""`;

0 commit comments

Comments
 (0)