Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions packages/components/test/components/Overview.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import path from 'path';
import { render } from '@asyncapi/generator-react-sdk';
import { Parser, fromFile } from '@asyncapi/parser';
import { getServer, getServerUrl } from '@asyncapi/generator-helpers';
import { Overview } from '../../src/components/readme/Overview';

const parser = new Parser();
const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah some other components incorrectly uses this fixture but this should be actually one inside components https://github.com/asyncapi/generator/blob/master/packages/components/test/__fixtures__/asyncapi-v3.yml
please use this one. you can make changes in fixtures only if testing requires.


describe('Testing of Overview component', () => {
let parsedAsyncAPIDocument;
let info;
let title;
let serverUrl;

beforeAll(async () => {
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
parsedAsyncAPIDocument = parseResult.document;

info = parsedAsyncAPIDocument.info();
title = info.title();

const server = getServer(parsedAsyncAPIDocument.servers(), 'withHostDuplicatingProtocol');
serverUrl = getServerUrl(server);
});

test('render overview component with all parameters', () => {
const result = render(
<Overview
info={info}
title={title}
serverUrl={serverUrl}
/>
);

const actual = result.trim();
expect(actual).toMatchSnapshot();
});

test('throws error when info is missing', () => {
expect(() => {
render(<Overview title={title} serverUrl={serverUrl}/>);
}).toThrow(TypeError);
});

test('render overview component when title is missing', () => {
const result = render(
<Overview
info={info}
serverUrl={serverUrl}
/>
);

const actual = result.trim();
expect(actual).toMatchSnapshot();
});

test('render overview component when serverUrl is missing', () => {
const result = render(
<Overview
info={info}
title={title}
/>
);

const actual = result.trim();
expect(actual).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing of Overview component render overview component when serverUrl is missing 1`] = `
"## Overview

Market data is a public API that streams all the market data on a given symbol.


- **Version:** 1.0.0
- **Server URL:** undefined"
`;

exports[`Testing of Overview component render overview component when title is missing 1`] = `
"## Overview

Market data is a public API that streams all the market data on a given symbol.


- **Version:** 1.0.0
- **Server URL:** wss://api.gemini.com"
`;

exports[`Testing of Overview component render overview component with all parameters 1`] = `
"## Overview

Market data is a public API that streams all the market data on a given symbol.


- **Version:** 1.0.0
- **Server URL:** wss://api.gemini.com"
`;