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
56 changes: 56 additions & 0 deletions packages/components/test/components/Readme.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import path from 'path';
import { render } from '@asyncapi/generator-react-sdk';
import { Parser, fromFile } from '@asyncapi/parser';
import { buildParams } from '@asyncapi/generator-helpers';
import { Readme } from '../../src/components/readme/Readme';

const parser = new Parser();
const asyncapi_websocket_query = path.resolve(__dirname, '../__fixtures__/asyncapi-v3.yml');

describe('Testing of Readme component', () => {
let parsedAsyncAPIDocument;
let params;

const languageConfigs = [
{ language: 'javascript', clientFileName: 'myClient.js' },
{ language: 'python', clientFileName: 'myClient.py' },
];

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

languageConfigs.forEach(({ language, clientFileName }) => {
test(`render Readme with language = ${language}`, () => {
const params = buildParams(
language,
{ clientFileName },
'production'
);
Copy link
Member

Choose a reason for hiding this comment

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

I would not recommend using this helper buildParams. As in actual code of Readme we don't use this helper. Additionally if the helper changes all other test will start failing and this helper has nothing to do with Readme component. Just use directly object.

const result = render(
<Readme
asyncapi={parsedAsyncAPIDocument}
params={params}
language={language}
/>
);

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

test.each([
['asyncapi is missing', { params, language: 'javascript' }],
['params are missing', { asyncapi: parsedAsyncAPIDocument, language: 'javascript' }],
['language is missing', { asyncapi: parsedAsyncAPIDocument, params }],
['asyncapi is null', { asyncapi: null, params, language: 'javascript' }],
['params is null', { asyncapi: parsedAsyncAPIDocument, params: null, language: 'javascript' }],
['language is null', { asyncapi: parsedAsyncAPIDocument, params, language: null }],
['language is empty', { asyncapi: parsedAsyncAPIDocument, params, language: '' }],
['language is unsupported',{ asyncapi: parsedAsyncAPIDocument, params, language: 'dart' }],
])('throws TypeError when %s', (_label, props) => {
expect(() => render(<Readme {...props} />)).toThrow(TypeError);
});
Copy link
Member

Choose a reason for hiding this comment

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

remove this testcase for now no need!

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing of Readme component render Readme with language = javascript 1`] = `
"# Account Service

## Overview

This service is in charge of processing user signups

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


## Installation

Install dependencies:

\`\`\`bash
npm install
\`\`\`


## Usage

\`\`\`javascript
const AccountService = require('./myClient');
const wsClient = new AccountService();

async function main() {
try {
await wsClient.connect();
// use wsClient to send/receive messages
await wsClient.close();
} catch (error) {
console.error('Failed to connect:', error);
}
}

main();
\`\`\`


## API

### \`connect()\`
Establishes a WebSocket connection.

### \`registerMessageHandler(handlerFunction)\`
Registers a callback for incoming messages.

### \`registerErrorHandler(handlerFunction)\`
Registers a callback for connection errors.

### \`close()\`
Closes the WebSocket connection.


### Available Operations

#### \`sendUserSignedup(payload)\`"
`;

exports[`Testing of Readme component render Readme with language = python 1`] = `
"# Account Service

## Overview

This service is in charge of processing user signups

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


## Installation

Install dependencies:

\`\`\`bash
pip install -r requirements.txt
\`\`\`


## Usage

\`\`\`python
from myClient import AccountService

ws_client = AccountService()

async def main():
await ws_client.connect()
# use ws_client to send/receive messages
await ws_client.close()
\`\`\`


## API

### \`connect()\`
Establishes a WebSocket connection.

### \`register_message_handler(handler_function)\`
Registers a callback for incoming messages.

### \`register_error_handler(handler_function)\`
Registers a callback for connection errors.

### \`close()\`
Closes the WebSocket connection.


### Available Operations

#### \`sendUserSignedup(payload)\`"
`;