-
-
Notifications
You must be signed in to change notification settings - Fork 382
test: add test coverage for TimedConnection #2009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import path from 'path'; | ||
| import { render } from '@asyncapi/generator-react-sdk'; | ||
| import { Parser, fromFile } from '@asyncapi/parser'; | ||
| import TimedConnection from '../../components/TimedConnection.js'; | ||
|
|
||
| const parser = new Parser(); | ||
| const asyncapiFilePath = path.resolve(__dirname, '../../../../test/__fixtures__/asyncapi-websocket-components.yml'); | ||
|
|
||
| describe('TimedConnection component (integration with AsyncAPI document)', () => { | ||
| let parsedAsyncAPIDocument; | ||
| let sendOperations; | ||
|
|
||
| beforeAll(async () => { | ||
| const parseResult = await fromFile(parser, asyncapiFilePath).parse(); | ||
| parsedAsyncAPIDocument = parseResult.document; | ||
| const operations = parsedAsyncAPIDocument.operations(); | ||
| sendOperations = operations.filterBySend(); | ||
| }); | ||
|
Comment on lines
+13
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Two issues in this block:
♻️ Proposed restructuring-describe('TimedConnection component (integration with AsyncAPI document)', () => {
- let parsedAsyncAPIDocument;
- let sendOperations;
-
- beforeAll(async () => {
- const parseResult = await fromFile(parser, asyncapiFilePath).parse();
- parsedAsyncAPIDocument = parseResult.document;
- const operations = parsedAsyncAPIDocument.operations();
- sendOperations = operations.filterBySend();
- });
-
- test('renders generic message when sendOperations is null', () => { ... });
- test('renders generic message when sendOperations is undefined', () => { ... });
- test('renders generic message when sendOperations is empty array', () => { ... });
- test('renders specific message with operationId when sendOperations has data from fixture', () => { ... });
-});
+describe('TimedConnection component', () => {
+ describe('without fixture — edge cases', () => {
+ test('renders generic message when sendOperations is null', () => { ... });
+ test('renders generic message when sendOperations is undefined', () => { ... });
+ test('renders generic message when sendOperations is empty array', () => { ... });
+ });
+
+ describe('integration with AsyncAPI document', () => {
+ let parsedAsyncAPIDocument;
+ let sendOperations;
+
+ beforeAll(async () => {
+ const parseResult = await fromFile(parser, asyncapiFilePath).parse();
+ parsedAsyncAPIDocument = parseResult.document;
+ expect(parsedAsyncAPIDocument).toBeDefined();
+ sendOperations = parsedAsyncAPIDocument.operations().filterBySend();
+ });
+
+ test('renders specific message with operationId when sendOperations has data from fixture', () => { ... });
+ });
+});🤖 Prompt for AI Agents |
||
|
|
||
| test('renders generic message when sendOperations is null', () => { | ||
| const result = render( | ||
| <TimedConnection | ||
| sendOperations={null} | ||
| /> | ||
| ); | ||
| expect(result.trim()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('renders generic message when sendOperations is undefined', () => { | ||
| const result = render( | ||
| <TimedConnection /> | ||
| ); | ||
| expect(result.trim()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('renders generic message when sendOperations is empty array', () => { | ||
| const result = render( | ||
| <TimedConnection | ||
| sendOperations={[]} | ||
| /> | ||
| ); | ||
| expect(result.trim()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('renders specific message with operationId when sendOperations has data from fixture', () => { | ||
| const result = render( | ||
| <TimedConnection | ||
| sendOperations={sendOperations} | ||
| /> | ||
| ); | ||
| expect(result.trim()).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`TimedConnection component (integration with AsyncAPI document) renders generic message when sendOperations is empty array 1`] = ` | ||
| "WebSocketClientConnection connection = connector.connectAndAwait(); | ||
| // Wait 2 seconds before first message | ||
| Thread.sleep(2000); | ||
| // Send 5 messages | ||
| for (int i = 1; i <= 5; i++) { | ||
| // Send a message to any available operation by including its operation ID (i.e. \\"null\\") | ||
| String msg = \\"Message #\\" + i + \\" from Quarkus\\"; | ||
| connection.sendTextAndAwait(msg); | ||
| Log.info(\\"Sent: \\" + msg); | ||
| Thread.sleep(5000); // Wait 5 seconds between messages | ||
| } | ||
| // Wait 10 seconds after final message | ||
| Log.info(\\"All messages sent. Waiting 10 seconds before closing...\\"); | ||
| Thread.sleep(10000);" | ||
| `; | ||
|
|
||
| exports[`TimedConnection component (integration with AsyncAPI document) renders generic message when sendOperations is null 1`] = ` | ||
| "WebSocketClientConnection connection = connector.connectAndAwait(); | ||
| // Wait 2 seconds before first message | ||
| Thread.sleep(2000); | ||
| // Send 5 messages | ||
| for (int i = 1; i <= 5; i++) { | ||
| // Send a message to any available operation by including its operation ID (i.e. \\"null\\") | ||
| String msg = \\"Message #\\" + i + \\" from Quarkus\\"; | ||
| connection.sendTextAndAwait(msg); | ||
| Log.info(\\"Sent: \\" + msg); | ||
| Thread.sleep(5000); // Wait 5 seconds between messages | ||
| } | ||
| // Wait 10 seconds after final message | ||
| Log.info(\\"All messages sent. Waiting 10 seconds before closing...\\"); | ||
| Thread.sleep(10000);" | ||
| `; | ||
|
|
||
| exports[`TimedConnection component (integration with AsyncAPI document) renders generic message when sendOperations is undefined 1`] = ` | ||
| "WebSocketClientConnection connection = connector.connectAndAwait(); | ||
| // Wait 2 seconds before first message | ||
| Thread.sleep(2000); | ||
| // Send 5 messages | ||
| for (int i = 1; i <= 5; i++) { | ||
| // Send a message to any available operation by including its operation ID (i.e. \\"null\\") | ||
| String msg = \\"Message #\\" + i + \\" from Quarkus\\"; | ||
| connection.sendTextAndAwait(msg); | ||
| Log.info(\\"Sent: \\" + msg); | ||
| Thread.sleep(5000); // Wait 5 seconds between messages | ||
| } | ||
| // Wait 10 seconds after final message | ||
| Log.info(\\"All messages sent. Waiting 10 seconds before closing...\\"); | ||
| Thread.sleep(10000);" | ||
| `; | ||
|
|
||
| exports[`TimedConnection component (integration with AsyncAPI document) renders specific message with operationId when sendOperations has data from fixture 1`] = ` | ||
| "WebSocketClientConnection connection = connector.connectAndAwait(); | ||
| // Wait 2 seconds before first message | ||
| Thread.sleep(2000); | ||
| // Send 5 messages | ||
| for (int i = 1; i <= 5; i++) { | ||
| // Send a message to any available operation by including its operation ID (i.e. \\"sendMessage\\") | ||
| String msg = \\"Message #\\" + i + \\" from Quarkus for sendMessage\\"; | ||
| connection.sendTextAndAwait(msg); | ||
| Log.info(\\"Sent: \\" + msg); | ||
| Thread.sleep(5000); // Wait 5 seconds between messages | ||
| } | ||
| // Wait 10 seconds after final message | ||
| Log.info(\\"All messages sent. Waiting 10 seconds before closing...\\"); | ||
| Thread.sleep(10000);" | ||
| `; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: asyncapi/generator
Length of output: 2895
🏁 Script executed:
Repository: asyncapi/generator
Length of output: 4085
Add JSDoc comments for test functions and beforeAll callback to comply with coding guidelines.
The fixture path is correct—the file exists at
packages/templates/clients/websocket/test/__fixtures__/asyncapi-websocket-components.ymland the path resolution fromtest/components/is accurate.__dirnameis also available: this project uses Babel transformation viababel-jest(configured injest.config.js), which converts ES modules to CommonJS at runtime, making__dirnameaccessible. Other test files in the same directory (ClientConnector.test.js, EchoWebSocket.test.js) already use this identical pattern successfully.However, the file lacks JSDoc comments for functions as required by the coding guidelines. Add JSDoc to:
beforeAllcallback (lines 13–18): describe what it does, that it's async, return typetest()callback (lines 20–51): describe what each test verifies🤖 Prompt for AI Agents