-
-
Notifications
You must be signed in to change notification settings - Fork 382
test: add test coverage for Constructor #1949
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
Merged
asyncapi-bot
merged 3 commits into
asyncapi:master
from
Harsh16gupta:test/Constructor-1887
Feb 8, 2026
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/templates/clients/websocket/java/quarkus/test/components/Constructor.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import path from 'path'; | ||
| import { render } from '@asyncapi/generator-react-sdk'; | ||
| import { Parser, fromFile } from '@asyncapi/parser'; | ||
| import { getQueryParams } from '@asyncapi/generator-helpers'; | ||
| import { Constructor } from '../../components/Constructor'; | ||
|
|
||
|
|
||
| const parser = new Parser(); | ||
| const asyncapiFilePath = path.resolve(__dirname, '../../../../test/__fixtures__/asyncapi-websocket-components.yml'); | ||
|
|
||
|
|
||
| describe('Constructor component (integration with AsyncAPI document)', () => { | ||
| let parsedAsyncAPIDocument; | ||
| let channels; | ||
| let queryParams; | ||
|
|
||
| beforeAll(async () => { | ||
| const parseResult = await fromFile(parser, asyncapiFilePath).parse(); | ||
| parsedAsyncAPIDocument = parseResult.document; | ||
| channels = parsedAsyncAPIDocument.channels(); | ||
| queryParams = getQueryParams(channels); | ||
| }); | ||
|
|
||
| test('renders nothing when query is null', () => { | ||
| const result = render(<Constructor clientName="WebSocketClient" query={null} />); | ||
| expect(result.trim()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('renders nothing when query has no entries', () => { | ||
| const emptyQuery = new Map(); | ||
| const result = render(<Constructor clientName="WebSocketClient" query={emptyQuery} />); | ||
| expect(result.trim()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('renders constructor when query parameters are present', () => { | ||
| const result = render(<Constructor clientName="WebSocketClient" query={queryParams} />); | ||
| expect(result.trim()).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
27 changes: 27 additions & 0 deletions
27
...tes/clients/websocket/java/quarkus/test/components/__snapshots__/Constructor.test.js.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Constructor component (integration with AsyncAPI document) renders constructor when query parameters are present 1`] = ` | ||
| "public WebSocketClient(){ | ||
| this(\\"false\\", \\"true\\", null); | ||
| } | ||
|
|
||
| public WebSocketClient(String heartbeat, String bids, String sessionId){ | ||
| params = new HashMap<>(); | ||
| this.heartbeat = (heartbeat != null && !heartbeat.isEmpty()) ? heartbeat : System.getenv(\\"HEARTBEAT\\"); | ||
| if (this.heartbeat != null){ | ||
| params.put(\\"heartbeat\\", this.heartbeat); | ||
| } | ||
| this.bids = (bids != null && !bids.isEmpty()) ? bids : System.getenv(\\"BIDS\\"); | ||
| if (this.bids != null){ | ||
| params.put(\\"bids\\", this.bids); | ||
| } | ||
| this.sessionId = (sessionId != null && !sessionId.isEmpty()) ? sessionId : System.getenv(\\"SESSIONID\\"); | ||
| if (this.sessionId != null){ | ||
| params.put(\\"sessionId\\", this.sessionId); | ||
| } | ||
| }" | ||
| `; | ||
|
|
||
| exports[`Constructor component (integration with AsyncAPI document) renders nothing when query has no entries 1`] = `""`; | ||
|
|
||
| exports[`Constructor component (integration with AsyncAPI document) renders nothing when query is null 1`] = `""`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.