Skip to content

test: add tests for usage component#1900

Merged
asyncapi-bot merged 4 commits intoasyncapi:masterfrom
batchu5:test/add-tests-usage-component
Feb 4, 2026
Merged

test: add tests for usage component#1900
asyncapi-bot merged 4 commits intoasyncapi:masterfrom
batchu5:test/add-tests-usage-component

Conversation

@batchu5
Copy link
Contributor

@batchu5 batchu5 commented Feb 1, 2026

Summary

Improve validation and test coverage for the Usage component.

What changed

  • Added a new test file to verify Usage component behavior for edge cases such as null, undefined, empty values, and incorrect casing of the language parameter.
  • Updated the Usage component to handle these edge cases consistently.

Related issue(s)
Fixes #1868

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suite for the Usage component to validate rendering with supported languages and error handling for invalid parameters.

@changeset-bot
Copy link

changeset-bot bot commented Feb 1, 2026

⚠️ No Changeset found

Latest commit: f80a735

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.

@dosubot
Copy link

dosubot bot commented Feb 1, 2026

Related Documentation

No published documentation to review for changes on this repository.

Write your first living document

How did I do? Any feedback?  Join Discord

@coderabbitai
Copy link

coderabbitai bot commented Feb 1, 2026

📝 Walkthrough

Walkthrough

Adds a new test suite for the Usage component with 99 lines of test coverage, including snapshot tests for two supported languages (python, javascript) and comprehensive error validation for invalid language parameter inputs.

Changes

Cohort / File(s) Summary
Usage Component Tests
packages/components/test/components/Usage.test.js
Introduces snapshot tests for rendering with supported languages and error handling tests covering unsupported languages, empty strings, incorrect casing, null, and undefined language values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title follows Conventional Commits format with 'test:' prefix and clearly summarizes the change in imperative mood.
Linked Issues check ✅ Passed The PR successfully adds tests for the Usage component as required by issue #1868, addressing a key coding objective of the linked issue.
Out of Scope Changes check ✅ Passed All changes in the PR are directly related to adding test coverage for the Usage component, which is within the scope of issue #1868.

✏️ 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

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Failure to add the new IP will result in interrupted reviews.


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.

@batchu5
Copy link
Contributor Author

batchu5 commented Feb 1, 2026

@Adi-204 I think CI failures are occurring in @asyncapi/generator-react-sdk tests

@SHUBHANSHU602
Copy link
Contributor

@batchu5 , go through once the failing checks shown by codebbit ai

@batchu5
Copy link
Contributor Author

batchu5 commented Feb 2, 2026

Thanks for the suggestion @SHUBHANSHU602, but I have added the docstrings in this PR. So I think there is no need to add them here, if it gets merged this checks will pass.

@Adi-204 Adi-204 self-assigned this Feb 2, 2026
@Adi-204 Adi-204 moved this to In Progress in Maintainers work Feb 2, 2026
Copy link
Member

@Adi-204 Adi-204 left a comment

Choose a reason for hiding this comment

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

hey @batchu5 left few comments!

Comment on lines 34 to 45
if (!language || typeof language !== 'string') {
throw new Error(`Invalid "language" parameter: must be a non-empty string, received ${language}`);
}

const snippetFn = usageConfig[language];

if (!snippetFn) {
throw new Error(
`Invalid "language" parameter: unsupported value "${language}"`
);
}

Copy link
Member

Choose a reason for hiding this comment

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

no need to add error handling for now we already have a separate issue, revert this changes.

'Invalid "language" parameter: must be a non-empty string, received undefined'
);
});
});
Copy link
Member

Choose a reason for hiding this comment

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

Also remove testcases of error handling.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2026

@Adi-204
Copy link
Member

Adi-204 commented Feb 4, 2026

/rtm

@asyncapi-bot asyncapi-bot merged commit 92de9ee into asyncapi:master Feb 4, 2026
15 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Maintainers work Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add Tests for Usage, Overview, Readme Components.

4 participants