Skip to content

TESTING EXTERNAL SCRIPT: external merge request from Contributor#37007

Closed
AmanAgarwal041 wants to merge 14 commits intoreleasefrom
chore/external-contribution-35363
Closed

TESTING EXTERNAL SCRIPT: external merge request from Contributor#37007
AmanAgarwal041 wants to merge 14 commits intoreleasefrom
chore/external-contribution-35363

Conversation

@AmanAgarwal041
Copy link
Contributor

@AmanAgarwal041 AmanAgarwal041 commented Oct 22, 2024

Description

Fixes #

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Caution

🔴 🔴 🔴 Some tests have failed.
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11658966145
Commit: 2cfa618
Cypress dashboard.
Tags: @tag.All
Spec:
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/ClientSide/EmbedSettings/EmbedSettings_spec.js
  2. cypress/e2e/Regression/ClientSide/Widgets/Datepicker/DatePicker2_spec.js
List of identified flaky tests.
Mon, 04 Nov 2024 08:39:43 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced the QueryDebuggerTabs component to display record counts or error messages based on API response success.
    • Introduced a new styled component for error messages, improving visual feedback.
    • Improved tab visibility management for a better user experience.
  • Bug Fixes

    • Added new tests to ensure correct behavior of the QueryDebuggerTabs component for successful and failed API responses.
  • Documentation

    • Introduced data-testid attributes for improved testing capabilities.
    • Enhanced type safety in testing by refining variable declarations.

@AmanAgarwal041 AmanAgarwal041 added the ok-to-test Required label for CI label Oct 22, 2024
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The changes in this pull request involve modifications to the QueryDebuggerTabs component and its associated test file. Enhancements include the addition of new test cases to validate the behavior of the component based on API responses, improvements to type safety, and updates to the component’s rendering logic. The component now conditionally displays results or error messages, and the test file has been adjusted to incorporate new mock responses and assertions.

Changes

File Path Change Summary
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.test.tsx - Added imports for screen, AnyAction, and Store.
- Introduced mockSuccessResponse and mockFailedResponse objects.
- Updated store type from any to Store<any, AnyAction>.
- Added new test cases for success and error scenarios.
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx - Added data-testid to Text component in ResultsCount.
- Enhanced logic for displaying result count based on action response.
- Adjusted useEffect hooks for better tab visibility management.

Possibly related PRs

Suggested labels

Task, skip-changelog, IDE Pod, IDE Product, Bug

Suggested reviewers

  • hetunandu

Poem

In the land of code where tests do play,
New mocks and types come out to stay.
With results that shine and errors that frown,
The QueryDebuggerTabs wear a testing crown!
So let’s celebrate this code so bright,
Making our app a true delight! 🎉


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2ce4bf3 and 2cfa618.

📒 Files selected for processing (2)
  • app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.test.tsx (4 hunks)
  • app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.test.tsx
  • app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

Copy link
Contributor

@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

🧹 Outside diff range and nitpick comments (3)
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.test.tsx (2)

18-42: LGTM: Mock responses added.

The mock responses are well-structured and cover both success and failure scenarios. Consider extracting these mock objects to a separate file for reusability in other tests.


117-143: LGTM: New test case for successful query.

The test case effectively checks the record count display. Consider adding an assertion for the exact number of records to ensure precise testing.

app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx (1)

272-282: Improved error handling and testability. Consider extracting the conditional rendering.

The changes enhance the component's ability to handle different response scenarios and improve testability. Good job on adding the data-testid attribute.

Consider extracting the conditional rendering into a separate function for better readability:

const renderResultText = () => {
  if (actionResponse?.isExecutionSuccess) {
    return (
      <Text type={TextType.H5}>{` ${output.length} Record${
        output.length > 1 ? "s" : ""
      }`}</Text>
    );
  }
  return (
    <Text color="red" type={TextType.H5}>
      {" Error"}
    </Text>
  );
};

Then use it in the JSX:

<Text data-testid="result-text" type={TextType.P3}>
  Result:
  {renderResultText()}
</Text>

This would make the component more maintainable and easier to test.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 554ec58 and b121f98.

📒 Files selected for processing (2)
  • app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.test.tsx (3 hunks)
  • app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (3)
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.test.tsx (3)

2-2: LGTM: New imports added.

The new imports are correctly added and necessary for the test enhancements.

Also applies to: 5-5


84-84: Improved type safety for store.

Good job updating the store type. This enhances type checking and reduces 'any' usage.


145-171: LGTM: New test case for failed query.

The test case effectively checks the error message display for failed queries.

@AmanAgarwal041
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11466642433.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37007.
recreate: .

@github-actions
Copy link

Deploy-Preview-URL: https://ce-37007.dp.appsmith.com

Copy link
Contributor

@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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b121f98 and 2ce4bf3.

📒 Files selected for processing (2)
  • app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.test.tsx (4 hunks)
  • app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx (2 hunks)
🔇 Additional comments (4)
app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.test.tsx (3)

2-2: LGTM! Well-structured mock responses.

The mock responses are comprehensive and properly typed, covering both success and failure scenarios with appropriate fields.

Also applies to: 13-13, 17-41


83-83: Good type safety improvement.

Removing the any type and directly initializing the store with proper typing enhances code reliability.


115-141: LGTM! Clear and focused test case.

The test properly validates the success scenario with appropriate assertions.

app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx (1)

46-48: LGTM: Styled component follows design system.

The ErrorText component correctly uses the design system color variable for error states.

Comment on lines +143 to +169
it("should show error as result if the query response returns the error", () => {
render(
<Provider store={store}>
<ThemeProvider theme={lightTheme}>
<Router>
<QueryDebuggerTabs
actionName="Query1"
actionResponse={mockFailedResponse}
actionSource={{
id: "ID1",
name: "Query1",
type: ENTITY_TYPE.ACTION,
}}
isRunning={false}
onRunClick={() => {}}
/>
</Router>
</ThemeProvider>
</Provider>,
);

const expectedResultText = "Result: Error";
const resultTextElement = screen.getByTestId("result-text");

expect(resultTextElement).toBeInTheDocument();
expect(resultTextElement?.textContent).toContain(expectedResultText);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider enhancing test isolation.

While the test implementation is correct, consider moving the common render setup to a helper function to reduce duplication and improve maintainability.

const renderQueryDebuggerTabs = (actionResponse?: ActionResponse) => {
  return render(
    <Provider store={store}>
      <ThemeProvider theme={lightTheme}>
        <Router>
          <QueryDebuggerTabs
            actionName="Query1"
            actionResponse={actionResponse}
            actionSource={{
              id: "ID1",
              name: "Query1",
              type: ENTITY_TYPE.ACTION,
            }}
            isRunning={false}
            onRunClick={() => {}}
          />
        </Router>
      </ThemeProvider>
    </Provider>
  );
};

Comment on lines +276 to +284
<Text data-testid="result-text" type={TextType.P3}>
Result:
<Text type={TextType.H5}>{` ${output.length} Record${
output.length > 1 ? "s" : ""
}`}</Text>
{actionResponse?.isExecutionSuccess ? (
<Text type={TextType.H5}>{` ${output.length} Record${
output.length > 1 ? "s" : ""
}`}</Text>
) : (
<ErrorText type={TextType.H5}>{" Error"}</ErrorText>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve readability and accessibility of the results display.

The current implementation could be simplified and made more accessible.

Consider this refactor:

-          <Text data-testid="result-text" type={TextType.P3}>
-            Result:
-            {actionResponse?.isExecutionSuccess ? (
-              <Text type={TextType.H5}>{` ${output.length} Record${
-                output.length > 1 ? "s" : ""
-              }`}</Text>
-            ) : (
-              <ErrorText type={TextType.H5}>{" Error"}</ErrorText>
-            )}
-          </Text>
+          <Text 
+            data-testid="result-text" 
+            type={TextType.P3}
+            role="status"
+            aria-live="polite"
+          >
+            {actionResponse?.isExecutionSuccess ? (
+              `Result: ${output.length} Record${output.length !== 1 ? 's' : ''}`
+            ) : (
+              'Result: Error'
+            )}
+          </Text>

Changes:

  1. Removed nested Text component for simpler structure
  2. Simplified string interpolation
  3. Added accessibility attributes
  4. Improved plural condition check
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Text data-testid="result-text" type={TextType.P3}>
Result:
<Text type={TextType.H5}>{` ${output.length} Record${
output.length > 1 ? "s" : ""
}`}</Text>
{actionResponse?.isExecutionSuccess ? (
<Text type={TextType.H5}>{` ${output.length} Record${
output.length > 1 ? "s" : ""
}`}</Text>
) : (
<ErrorText type={TextType.H5}>{" Error"}</ErrorText>
)}
<Text
data-testid="result-text"
type={TextType.P3}
role="status"
aria-live="polite"
>
{actionResponse?.isExecutionSuccess ? (
`Result: ${output.length} Record${output.length !== 1 ? 's' : ''}`
) : (
'Result: Error'
)}
</Text>

@sagar-qa007 sagar-qa007 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Nov 4, 2024
@AmanAgarwal041
Copy link
Contributor Author

Closing as the external contributors PR is already merged.

@AmanAgarwal041 AmanAgarwal041 deleted the chore/external-contribution-35363 branch November 4, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants