Skip to content

test: add test coverage for TimedConnection#2009

Open
Harsh16gupta wants to merge 1 commit intoasyncapi:masterfrom
Harsh16gupta:test/TimedConnection-1937
Open

test: add test coverage for TimedConnection#2009
Harsh16gupta wants to merge 1 commit intoasyncapi:masterfrom
Harsh16gupta:test/TimedConnection-1937

Conversation

@Harsh16gupta
Copy link
Contributor

@Harsh16gupta Harsh16gupta commented Feb 18, 2026

Description
Adds comprehensive integration tests for the TimedConnection component in the Java Quarkus WebSocket client template.

Fixes #1937

image

Summary by CodeRabbit

  • Tests
    • Added integration tests for the TimedConnection component, validating rendering behavior across multiple scenarios including null, undefined, and empty data states.

@changeset-bot
Copy link

changeset-bot bot commented Feb 18, 2026

⚠️ No Changeset found

Latest commit: c0ecb72

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@asyncapi-bot
Copy link
Contributor

What reviewer looks at during PR review

The following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.

  1. PR Title: Use a concise title that follows our Conventional Commits guidelines and clearly summarizes the change using imperative mood (it means spoken or written as if giving a command or instruction, like "add new helper for listing operations")

    Note - In Generator, prepend feat: or fix: in PR title only when PATCH/MINOR release must be triggered.

  2. PR Description: Clearly explain the issue being solved, summarize the changes made, and mention the related issue.

    Note - In Generator, we use Maintainers Work board to track progress. Ensure the PR Description includes Resolves #<issue-number> or Fixes #<issue-number> this will automatically close the linked issue when the PR is merged and helps automate the maintainers workflow.

  3. Documentation: Update the relevant Generator documentation to accurately reflect the changes introduced in the PR, ensuring users and contributors have up-to-date guidance.

  4. Comments and JSDoc: Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions, so others can easily understand and use the code.

  5. DRY Code: Ensure the code follows the Don't Repeat Yourself principle. Look out for duplicate logic that can be reused.

  6. Test Coverage: Ensure the new code is well-tested with meaningful test cases that pass consistently and cover all relevant edge cases.

  7. Commit History: Contributors should avoid force-pushing as much as possible. It makes it harder to track incremental changes and review the latest updates.

  8. Template Design Principles Alignment: While reviewing template-related changes in the packages/ directory, ensure they align with the Assumptions and Principles. If any principle feels outdated or no longer applicable, start a discussion these principles are meant to evolve with the project.

  9. Reduce Scope When Needed: If an issue or PR feels too large or complex, consider splitting it and creating follow-up issues. Smaller, focused PRs are easier to review and merge.

  10. Bot Comments: As reviewers, check that contributors have appropriately addressed comments or suggestions made by automated bots. If there are bot comments the reviewer disagrees with, react to them or mark them as resolved, so the review history remains clear and accurate.

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

📝 Walkthrough

Walkthrough

A new integration test file for the TimedConnection React component has been added with 53 lines of code. Tests use an AsyncAPI parser and fixture to verify component rendering via snapshots under various sendOperations prop configurations.

Changes

Cohort / File(s) Summary
TimedConnection Component Tests
packages/templates/clients/websocket/java/quarkus/test/components/TimedConnection.test.js
New test file with snapshot tests covering TimedConnection component rendering with null, undefined, empty array, and populated sendOperations props. Uses AsyncAPI parser fixture for test data.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'test: add test coverage for TimedConnection' uses imperative mood, follows Conventional Commits guidelines with 'test:' prefix, and clearly summarizes adding tests for the TimedConnection component.
Linked Issues check ✅ Passed The PR adds comprehensive tests for TimedConnection component covering conditional logic with multiple scenarios (null, undefined, empty array, and actual data), directly fulfilling the requirement in issue #1937 to add component-level test coverage.
Out of Scope Changes check ✅ Passed The PR contains only test file additions for TimedConnection component with no public API changes, remaining entirely within the scope defined by issue #1937.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/templates/clients/websocket/java/quarkus/test/components/TimedConnection.test.js (1)

1-53: Add JSDoc to the beforeAll callback at minimum.

As per coding guidelines, functions in .js files should have JSDoc. The test(...) names are self-documenting, but the beforeAll async callback — which sets up shared state and has failure modes — benefits from a brief @description noting what it loads and what parsedAsyncAPIDocument / sendOperations represent.

♻️ Suggested JSDoc for `beforeAll`
+  /**
+   * Parses the shared AsyncAPI fixture and extracts send operations
+   * used by the fixture-driven test.
+   * `@async`
+   */
   beforeAll(async () => {

As per coding guidelines: "Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/templates/clients/websocket/java/quarkus/test/components/TimedConnection.test.js`
around lines 1 - 53, Add a JSDoc block above the beforeAll async callback
describing its purpose and what it initializes (parsedAsyncAPIDocument and
sendOperations), including a brief `@description`, any relevant return/throws note
(it’s async and may reject), and types for the variables (e.g.,
parsedAsyncAPIDocument: AsyncAPIDocument, sendOperations: Array). Locate the
beforeAll function in the TimedConnection.test.js file and insert a short JSDoc
that documents the setup behavior and the meanings of parsedAsyncAPIDocument and
sendOperations so linters and readers understand the shared test state.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@packages/templates/clients/websocket/java/quarkus/test/components/TimedConnection.test.js`:
- Around line 13-18: Add a validity guard after parsing in the beforeAll so
parsedAsyncAPIDocument is asserted before calling
parsedAsyncAPIDocument.operations() (e.g., add
expect(parsedAsyncAPIDocument).toBeDefined()); and remove the coupling of the
three fixture-independent tests from this describe that uses beforeAll by
relocating those tests (the ones that call with null/undefined/[]) into a
sibling describe or a nested describe without the beforeAll so failures parsing
in beforeAll do not cascade to tests that don’t use sendOperations (references:
beforeAll, parsedAsyncAPIDocument, sendOperations).
- Line 7: Add JSDoc comments above the beforeAll callback and each test callback
in TimedConnection.test.js: for the beforeAll callback (the async setup
function) add a JSDoc block describing that it initializes test fixtures and is
asynchronous, include `@async` and `@returns` {Promise<void>}; for each test()
callback add a JSDoc block that succinctly states what the test verifies (e.g.,
verifies connection establishment, message timing, or teardown behavior),
include `@async` if the test callback is async and `@returns` {Promise<void>} for
consistency; place the comments immediately above the beforeAll and each
test(...) so linters and coding guidelines recognize them.

---

Nitpick comments:
In
`@packages/templates/clients/websocket/java/quarkus/test/components/TimedConnection.test.js`:
- Around line 1-53: Add a JSDoc block above the beforeAll async callback
describing its purpose and what it initializes (parsedAsyncAPIDocument and
sendOperations), including a brief `@description`, any relevant return/throws note
(it’s async and may reject), and types for the variables (e.g.,
parsedAsyncAPIDocument: AsyncAPIDocument, sendOperations: Array). Locate the
beforeAll function in the TimedConnection.test.js file and insert a short JSDoc
that documents the setup behavior and the meanings of parsedAsyncAPIDocument and
sendOperations so linters and readers understand the shared test state.

import TimedConnection from '../../components/TimedConnection.js';

const parser = new Parser();
const asyncapiFilePath = path.resolve(__dirname, '../../../../test/__fixtures__/asyncapi-websocket-components.yml');
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# 1. Search for the fixture file
echo "=== Searching for asyncapi-websocket-components.yml ==="
fd "asyncapi-websocket-components.yml" --type f 2>/dev/null || echo "File not found with fd"

# 2. Look for package.json in the quarkus directory and check it
echo -e "\n=== Checking package.json in quarkus package ==="
if [ -f packages/templates/clients/websocket/java/quarkus/package.json ]; then
  cat packages/templates/clients/websocket/java/quarkus/package.json
else
  echo "Not found at expected location"
fi

# 3. Check parent package.json files for module configuration
echo -e "\n=== Checking parent package.json files ==="
for pkgjson in packages/package.json packages/templates/package.json packages/templates/clients/package.json packages/templates/clients/websocket/package.json; do
  if [ -f "$pkgjson" ]; then
    echo "--- $pkgjson ---"
    cat "$pkgjson" | head -20
  fi
done

# 4. Check how other test files in the package handle __dirname
echo -e "\n=== Other test files in the quarkus package ==="
fd "\.test\.js$" packages/templates/clients/websocket/java/quarkus/ --type f

Repository: asyncapi/generator

Length of output: 2895


🏁 Script executed:

#!/bin/bash

# Check a couple of other test files to see if they use __dirname in the same way
echo "=== Checking ClientConnector.test.js ==="
head -20 packages/templates/clients/websocket/java/quarkus/test/components/ClientConnector.test.js

echo -e "\n=== Checking EchoWebSocket.test.js ==="
head -20 packages/templates/clients/websocket/java/quarkus/test/components/EchoWebSocket.test.js

# Also check the full TimedConnection.test.js to see the JSDoc situation
echo -e "\n=== Full TimedConnection.test.js ==="
cat -n packages/templates/clients/websocket/java/quarkus/test/components/TimedConnection.test.js

# Check if there's a jest.config.js or similar
echo -e "\n=== Jest configuration ==="
fd "jest.config" packages/templates/clients/websocket/java/quarkus/ --type f
if [ -f packages/templates/clients/websocket/java/quarkus/jest.config.js ]; then
  cat packages/templates/clients/websocket/java/quarkus/jest.config.js
fi

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.yml and the path resolution from test/components/ is accurate. __dirname is also available: this project uses Babel transformation via babel-jest (configured in jest.config.js), which converts ES modules to CommonJS at runtime, making __dirname accessible. 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:

  • The beforeAll callback (lines 13–18): describe what it does, that it's async, return type
  • Each test() callback (lines 20–51): describe what each test verifies
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/templates/clients/websocket/java/quarkus/test/components/TimedConnection.test.js`
at line 7, Add JSDoc comments above the beforeAll callback and each test
callback in TimedConnection.test.js: for the beforeAll callback (the async setup
function) add a JSDoc block describing that it initializes test fixtures and is
asynchronous, include `@async` and `@returns` {Promise<void>}; for each test()
callback add a JSDoc block that succinctly states what the test verifies (e.g.,
verifies connection establishment, message timing, or teardown behavior),
include `@async` if the test callback is async and `@returns` {Promise<void>} for
consistency; place the comments immediately above the beforeAll and each
test(...) so linters and coding guidelines recognize them.

Comment on lines +13 to +18
beforeAll(async () => {
const parseResult = await fromFile(parser, asyncapiFilePath).parse();
parsedAsyncAPIDocument = parseResult.document;
const operations = parsedAsyncAPIDocument.operations();
sendOperations = operations.filterBySend();
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

beforeAll failure cascades to fixture-independent tests; add a document guard.

Two issues in this block:

  1. Missing validity guard: parseResult.document is undefined when the AsyncAPI document is invalid. Calling .operations() on it will throw a TypeError, making the error misleading. Add a guard:

    expect(parsedAsyncAPIDocument).toBeDefined();
  2. Unnecessary coupling: Tests 1–3 pass null, undefined, and [] directly and never read sendOperations. Because they share this describe/beforeAll, a fixture-load failure will fail them too, masking what actually broke. Consider moving them into a sibling describe block without a beforeAll, or into a nested describe that skips setup.

♻️ 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
Verify each finding against the current code and only fix it if needed.

In
`@packages/templates/clients/websocket/java/quarkus/test/components/TimedConnection.test.js`
around lines 13 - 18, Add a validity guard after parsing in the beforeAll so
parsedAsyncAPIDocument is asserted before calling
parsedAsyncAPIDocument.operations() (e.g., add
expect(parsedAsyncAPIDocument).toBeDefined()); and remove the coupling of the
three fixture-independent tests from this describe that uses beforeAll by
relocating those tests (the ones that call with null/undefined/[]) into a
sibling describe or a nested describe without the beforeAll so failures parsing
in beforeAll do not cascade to tests that don’t use sendOperations (references:
beforeAll, parsedAsyncAPIDocument, sendOperations).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TEST] Add component tests for TimedConnection.js (Java WebSocket Template)

2 participants