Skip to content

Commit f2c8819

Browse files
batchu5Adi-204
andauthored
test: add tests for overview component (#1947)
Co-authored-by: Varshitha Besthavemula <varshithabesthavemula@gmail.com> Co-authored-by: Adi Boghawala <adiboghawala@gmail.com>
1 parent da5384d commit f2c8819

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

packages/components/test/__fixtures__/asyncapi-v3.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ info:
33
title: Account Service
44
version: 1.0.0
55
description: This service is in charge of processing user signups
6+
servers:
7+
production:
8+
host: api.example.com
9+
protocol: ws
10+
description: Production WebSocket server
611
channels:
712
userSignedup:
813
address: user/signedup
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import path from 'path';
2+
import { render } from '@asyncapi/generator-react-sdk';
3+
import { Parser, fromFile } from '@asyncapi/parser';
4+
import { getServer, getServerUrl } from '@asyncapi/generator-helpers';
5+
import { Overview } from '../../src/components/readme/Overview';
6+
7+
const parser = new Parser();
8+
const asyncapi_websocket_query = path.resolve(__dirname, '../__fixtures__/asyncapi-v3.yml');
9+
10+
describe('Testing of Overview component', () => {
11+
let parsedAsyncAPIDocument;
12+
let info;
13+
let title;
14+
let serverUrl;
15+
16+
beforeAll(async () => {
17+
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
18+
parsedAsyncAPIDocument = parseResult.document;
19+
20+
info = parsedAsyncAPIDocument.info();
21+
title = info.title();
22+
23+
const server = getServer(parsedAsyncAPIDocument.servers(), 'production');
24+
serverUrl = getServerUrl(server);
25+
});
26+
27+
test('render overview component with all parameters', () => {
28+
const result = render(
29+
<Overview
30+
info={info}
31+
title={title}
32+
serverUrl={serverUrl}
33+
/>
34+
);
35+
36+
const actual = result.trim();
37+
expect(actual).toMatchSnapshot();
38+
});
39+
40+
test('throws error when info is missing', () => {
41+
expect(() => {
42+
render(<Overview title={title} serverUrl={serverUrl}/>);
43+
}).toThrow(TypeError);
44+
});
45+
46+
test('render overview component when title is missing', () => {
47+
const result = render(
48+
<Overview
49+
info={info}
50+
serverUrl={serverUrl}
51+
/>
52+
);
53+
54+
const actual = result.trim();
55+
expect(actual).toMatchSnapshot();
56+
});
57+
58+
test('render overview component when serverUrl is missing', () => {
59+
const result = render(
60+
<Overview
61+
info={info}
62+
title={title}
63+
/>
64+
);
65+
66+
const actual = result.trim();
67+
expect(actual).toMatchSnapshot();
68+
});
69+
});
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 Overview component render overview component when serverUrl is missing 1`] = `
4+
"## Overview
5+
6+
This service is in charge of processing user signups
7+
8+
- **Version:** 1.0.0
9+
- **Server URL:** undefined"
10+
`;
11+
12+
exports[`Testing of Overview component render overview component when title is missing 1`] = `
13+
"## Overview
14+
15+
This service is in charge of processing user signups
16+
17+
- **Version:** 1.0.0
18+
- **Server URL:** ws://api.example.com"
19+
`;
20+
21+
exports[`Testing of Overview component render overview component with all parameters 1`] = `
22+
"## Overview
23+
24+
This service is in charge of processing user signups
25+
26+
- **Version:** 1.0.0
27+
- **Server URL:** ws://api.example.com"
28+
`;

0 commit comments

Comments
 (0)