Skip to content

test: add tests and snapshot for QueryParamsVariables component #1622

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
merged 10 commits into from
Jun 25, 2025

Conversation

blazethunderstorm
Copy link
Contributor

@blazethunderstorm blazethunderstorm commented Jun 19, 2025

Description

Added a new test file and corresponding snapshot for the QueryParamsVariables component to verify its rendering behavior with different query parameter inputs. This ensures the component correctly handles query parameters from AsyncAPI documents and renders as expected.

Proof

image

All test are successfully running

Related issue(s)

Resolves #1545

Summary by CodeRabbit

  • Tests
    • Added a new test suite for the QueryParamsVariables component to verify its rendering behavior with various query parameter inputs.

Copy link

changeset-bot bot commented Jun 19, 2025

⚠️ No Changeset found

Latest commit: 0ed3195

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

Copy link

coderabbitai bot commented Jun 19, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • packages/templates/clients/websocket/python/test/components/__snapshots__/QueryParamsVariables.test.js.snap is excluded by !**/*.snap

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

A new test suite was introduced for the QueryParamsVariables React component. The tests use an AsyncAPI YAML fixture to validate the component’s rendering, including snapshot testing when query parameters are present and checks for empty renders when query parameters are absent or invalid.

Changes

Files Changed Change Summary
packages/templates/clients/websocket/python/test/components/QueryParamsVariables.test.js Added a test suite for QueryParamsVariables, including snapshot and empty render tests.

Assessment against linked issues

Objective Addressed Explanation
Add snapshot test for python QueryParamsVariables.js (#1545)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found.


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@blazethunderstorm
Copy link
Contributor Author

@Adi-204 pls review the pr , thanks

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: 0

🧹 Nitpick comments (1)
packages/templates/clients/websocket/python/test/components/QueryParamsVariables.test.js (1)

8-11: Consider using a more robust path resolution approach.

The current file path construction uses multiple directory traversals (../../../../../../) which makes it brittle and prone to breaking if the directory structure changes.

Consider using a more robust approach:

-const asyncapiFilePath = path.resolve(
-  __dirname,
-  '../../../../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml'
-);
+const asyncapiFilePath = path.resolve(
+  process.cwd(),
+  'helpers/test/__fixtures__/asyncapi-websocket-query.yml'
+);

Or use a helper function to locate the project root and build paths from there.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ba15fb and 3ea6200.

⛔ Files ignored due to path filters (1)
  • packages/templates/clients/websocket/python/test/components/__snapshots__/QueryParamsVariables.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • packages/templates/clients/websocket/python/test/components/QueryParamsVariables.test.js (1 hunks)
🔇 Additional comments (3)
packages/templates/clients/websocket/python/test/components/QueryParamsVariables.test.js (3)

16-23: Excellent error handling in async setup.

The beforeAll hook properly handles the asynchronous AsyncAPI document parsing with comprehensive error handling. The descriptive error message will help with debugging if the fixture file is missing or invalid.


25-31: Robust test implementation with proper null checking.

The test correctly:

  • Extracts query parameters from the parsed AsyncAPI document
  • Handles potential null values from getQueryParams
  • Converts the Map to Array format as expected by the component
  • Uses snapshot testing for comprehensive rendering verification

33-41: Comprehensive edge case coverage.

Both test cases properly verify the component's behavior when query parameters are null or undefined, ensuring the component gracefully handles missing data by returning an empty string.

Copy link
Contributor

@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.

@blazethunderstorm also please add 1 more testcase in which directly pass empty array. something like - <QueryParamsVariables queryParams={[]} />

Comment on lines 17 to 22
try {
const parseResult = await fromFile(parser, asyncapiFilePath).parse();
parsedAsyncAPIDocument = parseResult.document;
} catch (error) {
throw new Error(`Failed to parse AsyncAPI document: ${error.message}`);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

remove try and catch from here also write code inside try directly.

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: 1

🧹 Nitpick comments (1)
packages/templates/clients/websocket/python/test/components/Requires.test.js (1)

16-23: Good error handling, consider adding document validation.

The beforeAll setup with error handling is well-implemented. However, consider adding validation to ensure the parsed document contains expected channels/query parameters.

  beforeAll(async () => {
    try {
      const parseResult = await fromFile(parser, asyncapiFilePath).parse();
      parsedAsyncAPIDocument = parseResult.document;
+     
+     // Validate that the document has the expected structure
+     if (!parsedAsyncAPIDocument.channels() || parsedAsyncAPIDocument.channels().length === 0) {
+       throw new Error('AsyncAPI document does not contain expected channels');
+     }
    } catch (error) {
      throw new Error(`Failed to parse AsyncAPI document: ${error.message}`);
    }
  });
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ea6200 and c0c630d.

⛔ Files ignored due to path filters (1)
  • packages/templates/clients/websocket/python/test/components/__snapshots__/Requires.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • packages/templates/clients/websocket/python/test/components/QueryParamsVariables.test.js (1 hunks)
  • packages/templates/clients/websocket/python/test/components/Requires.test.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/templates/clients/websocket/python/test/components/QueryParamsVariables.test.js
🔇 Additional comments (2)
packages/templates/clients/websocket/python/test/components/Requires.test.js (2)

1-5: LGTM!

The imports are well-organized and include all necessary dependencies for testing the Requires component with AsyncAPI integration.


25-40: Verify fixture file exists and add data validation.

The test cases provide good coverage of different scenarios, but consider adding verification that the fixture file exists and contains expected data.

#!/bin/bash
# Description: Verify the AsyncAPI fixture file exists and contains expected query parameters
# Expected: File should exist and contain channels with query parameters

# Check if the fixture file exists
fixture_path="packages/helpers/test/__fixtures__/asyncapi-websocket-query.yml"
if [ -f "$fixture_path" ]; then
    echo "✓ Fixture file exists: $fixture_path"
    
    # Check if the file contains query-related content
    if grep -q "query" "$fixture_path"; then
        echo "✓ Fixture file contains query-related content"
        
        # Show relevant sections
        echo "Query-related content in fixture:"
        grep -A 5 -B 5 "query" "$fixture_path"
    else
        echo "⚠ Fixture file does not contain query-related content"
    fi
else
    echo "✗ Fixture file not found: $fixture_path"
    
    # Search for similar files
    echo "Searching for similar AsyncAPI fixture files:"
    fd -e yml -e yaml "asyncapi.*websocket" .
fi

Comment on lines 8 to 11
const asyncapiFilePath = path.resolve(
__dirname,
'../../../../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml'
);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider a more maintainable approach for fixture file path.

The deep relative path with 7 directory levels up (../../../../../../) makes the test fragile to directory structure changes. Consider alternatives for better maintainability.

Options to improve path reliability:

  1. Use a dedicated test fixtures directory at a consistent location
  2. Use an environment variable or configuration for the fixtures path
  3. Copy the fixture to a local test directory
-const asyncapiFilePath = path.resolve(
-  __dirname,
-  '../../../../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml'
-);
+// Option 1: Use a more stable relative path
+const asyncapiFilePath = path.resolve(__dirname, '../fixtures/asyncapi-websocket-query.yml');
+
+// Option 2: Use process.cwd() for project root
+const asyncapiFilePath = path.resolve(process.cwd(), 'packages/helpers/test/__fixtures__/asyncapi-websocket-query.yml');

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/templates/clients/websocket/python/test/components/Requires.test.js
around lines 8 to 11, the fixture file path uses a fragile deep relative path
with many directory levels up. To improve maintainability, refactor the code to
use a more reliable approach such as placing test fixtures in a dedicated
directory with a consistent path, referencing the fixture path via an
environment variable or configuration setting, or copying the fixture file into
a local test directory within the current test folder. Update the path
resolution accordingly to avoid fragile relative paths.

@blazethunderstorm
Copy link
Contributor Author

@Adi-204 i have made the eq changes , thanks

Copy link
Contributor

@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.

@blazethunderstorm also we are doing snapshot testing so it is better to replace expect(result).toBe(''); with expect(result.trim()).toMatchSnapshot(); in testcases.

@blazethunderstorm
Copy link
Contributor Author

@Adi-204 i have made rew changes , thanks

@Adi-204
Copy link
Contributor

Adi-204 commented Jun 19, 2025

@blazethunderstorm just a suggestion whenever you make changes and feel it is ready for review again. In top of PR on right side you can see Reviewers and it will have my name and a re-request review button, just click on it.

Copy link
Contributor

@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.

LGTM 🚀

@blazethunderstorm
Copy link
Contributor Author

@Adi-204 thanks

@blazethunderstorm
Copy link
Contributor Author

@derberg @jonaslagoni @magicmatatjahu pls review it

derberg
derberg previously approved these changes Jun 23, 2025
@derberg
Copy link
Member

derberg commented Jun 23, 2025

@blazethunderstorm @Adi-204 tests are failing

@Adi-204
Copy link
Contributor

Adi-204 commented Jun 23, 2025

@blazethunderstorm test are failing. I think because of snapshots. Run npm run test:update and push changes.

@blazethunderstorm
Copy link
Contributor Author

blazethunderstorm commented Jun 24, 2025

@Adi-204 i couldn't see any change in snapshots

@Adi-204
Copy link
Contributor

Adi-204 commented Jun 24, 2025

@blazethunderstorm locally when you are running npm run test it is throwing error right?

@blazethunderstorm
Copy link
Contributor Author

blazethunderstorm commented Jun 24, 2025

@Adi-204 @asyncapi/template-dart-websocket-client#test its showing this error but it was showing for the require.js also but for that tests passed

@Adi-204
Copy link
Contributor

Adi-204 commented Jun 24, 2025

@blazethunderstorm I think you are talking about the warning about key props. That is just warning not issue.

image

I have tried this code locally and your snapshots are old run npm run test:update if you still no snapshot are updated share screenshot.

@blazethunderstorm
Copy link
Contributor Author

blazethunderstorm commented Jun 24, 2025

nope the snapshots arent updated , yeah i am just getting that key prop error

@Adi-204
Copy link
Contributor

Adi-204 commented Jun 24, 2025

@blazethunderstorm that is strange because I am running same code locally and snapshots are updated. can you please share screenshot of logs(just last part not entire) when you run npm run test:update.

@blazethunderstorm
Copy link
Contributor Author

image

@Adi-204
Copy link
Contributor

Adi-204 commented Jun 24, 2025

the last part when command is execution is stoped

@blazethunderstorm
Copy link
Contributor Author

image

@Adi-204
Copy link
Contributor

Adi-204 commented Jun 24, 2025

@blazethunderstorm thanks, ok their is some kind of problem with dependency.
I would suggest to run npm install once again inside /python. If still it throws same error, can you please post it on slack so someone with same problem can maybe help.

also you can delete and re-install node_modules

@blazethunderstorm
Copy link
Contributor Author

@Adi-204 thanks for your help the tests got updated

Copy link

@derberg
Copy link
Member

derberg commented Jun 25, 2025

/rtm

@asyncapi-bot asyncapi-bot merged commit 915249f into asyncapi:master Jun 25, 2025
16 checks passed
@derberg
Copy link
Member

derberg commented Jun 25, 2025

@allcontributors please add @blazethunderstorm for test

Copy link
Contributor

@derberg

I've put up a pull request to add @blazethunderstorm! 🎉

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

Successfully merging this pull request may close these issues.

add snapshot test for python QueryParamsVariables.js
4 participants