Skip to content

Commit 5a2207c

Browse files
committed
test: add tests for overview component
1 parent 92de9ee commit 5a2207c

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
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, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.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(), 'withHostDuplicatingProtocol');
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
Market data is a public API that streams all the market data on a given symbol.
7+
8+
9+
- **Version:** 1.0.0
10+
- **Server URL:** undefined"
11+
`;
12+
13+
exports[`Testing of Overview component render overview component when title is missing 1`] = `
14+
"## Overview
15+
16+
Market data is a public API that streams all the market data on a given symbol.
17+
18+
19+
- **Version:** 1.0.0
20+
- **Server URL:** wss://api.gemini.com"
21+
`;
22+
23+
exports[`Testing of Overview component render overview component with all parameters 1`] = `
24+
"## Overview
25+
26+
Market data is a public API that streams all the market data on a given symbol.
27+
28+
29+
- **Version:** 1.0.0
30+
- **Server URL:** wss://api.gemini.com"
31+
`;

0 commit comments

Comments
 (0)