Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions packages/components/test/__fixtures__/asyncapi-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ info:
title: Account Service
version: 1.0.0
description: This service is in charge of processing user signups
servers:
production:
host: api.example.com
protocol: ws
description: Production WebSocket server
channels:
userSignedup:
address: user/signedup
Expand Down
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, '../__fixtures__/asyncapi-v3.yml');

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(), 'production');
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,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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

This service is in charge of processing user signups

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

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

This service is in charge of processing user signups

- **Version:** 1.0.0
- **Server URL:** ws://api.example.com"
`;

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

This service is in charge of processing user signups

- **Version:** 1.0.0
- **Server URL:** ws://api.example.com"
`;