Skip to content
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

feat: alt text in image widget #37371

Closed
wants to merge 4 commits into from

Conversation

vhemery
Copy link
Contributor

@vhemery vhemery commented Nov 13, 2024

Description

Add the alt attribute as a new widget property for the image widget.

Fixes #13383

Automation

/test Image
/ok-to-test tags="Image"

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for alternative text in the Image Widget, improving accessibility.
    • Enhanced test coverage for the Image Widget to validate both image sources and alternative text.
  • Bug Fixes

    • Improved error handling for image loading within the Image Widget.
  • Documentation

    • Updated test cases and data sets to include new fields for alternative text, enhancing clarity and accessibility.

Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

Walkthrough

The pull request introduces enhancements to the Image Widget functionality, specifically focusing on adding and validating alternative text (alt text) for images. Modifications include updates to test cases for validating alt text, updates to JSON test data, and changes to the ImageComponent and ImageWidget classes to support the new alt text property. These changes aim to improve accessibility and ensure proper functionality of the Image Widget.

Changes

File Path Change Summary
app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_base64_spec.js Added tests for validating the alt text of the image widget alongside existing image source validation.
app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_spec.js Introduced new test case for validating alternative text for the image widget.
app/client/cypress/fixtures/TestDataSet1.json Added new fields for alternative text in the test data set, enhancing descriptive capabilities.
app/client/src/widgets/ImageWidget/component/index.tsx Updated ImageComponentProps to include alt property and modified rendering logic for the image.
app/client/src/widgets/ImageWidget/widget/index.tsx Added alt property to ImageWidgetProps and configured property pane for alternative text.

Assessment against linked issues

Objective Addressed Explanation
Add Alt-Text property for Image widget (#13383)

Possibly related PRs

Suggested labels

Task, Anvil Pod, ok-to-test

Suggested reviewers

  • ApekshaBhosale
  • sagar-qa007

🎨 In the realm of code where widgets play,
Alt text now shines, brightening the way.
With tests that ensure, all's in its place,
Accessibility blooms, a beautiful grace.
So here's to the changes, both big and small,
In the world of images, we’re enhancing it all! 🌟

Warning

Rate limit exceeded

@vhemery has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 51 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3a96e40 and 20a37de.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3a96e40 and 20a37de.

📒 Files selected for processing (1)
  • app/client/src/widgets/ImageWidget/widget/index.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/src/widgets/ImageWidget/widget/index.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: 6

🧹 Outside diff range and nitpick comments (5)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_base64_spec.js (2)

Line range hint 41-43: Remove afterEach block

The afterEach block should be removed as per our guidelines. If cleanup is necessary, consider using API calls or more direct approaches.

- afterEach(() => {
-   // put your clean up code if any
- });

Line range hint 1-43: Additional test improvements needed

Several improvements are needed to align with our testing guidelines:

  1. Login/logout operations should use API calls (LoginFromAPI/LogOutviaAPI)
  2. Consider combining multiple assertions for better test efficiency
  3. Move selector strings to locator variables
app/client/src/widgets/ImageWidget/widget/index.tsx (1)

341-341: Simplify alt text prop passing

The conditional check can be simplified since undefined is already the desired fallback value.

-alt={this.props.alt ? this.props.alt : undefined}
+alt={this.props.alt}
app/client/cypress/fixtures/TestDataSet1.json (2)

98-99: Consider standardizing alt text property name

The property is named altText here but NewImageAltText and validateImageAltText elsewhere in the file.

Consider using consistent property naming across all image objects:

-    "altText": "A single pixel"
+    "imageAltText": "A single pixel"

123-123: Avoid duplicate alt text descriptions

The same alt text is used for both NewImageAltText and validateImageAltText. While this might be intentional for testing, consider using distinct descriptions to better test different scenarios.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d90faa2 and 243f6a3.

📒 Files selected for processing (5)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_base64_spec.js (1 hunks)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_spec.js (1 hunks)
  • app/client/cypress/fixtures/TestDataSet1.json (2 hunks)
  • app/client/src/widgets/ImageWidget/component/index.tsx (2 hunks)
  • app/client/src/widgets/ImageWidget/widget/index.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_base64_spec.js (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_spec.js (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/fixtures/TestDataSet1.json (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
🔇 Additional comments (4)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_spec.js (1)

41-43: LGTM! Documentation is clear and consistent.

app/client/src/widgets/ImageWidget/widget/index.tsx (1)

341-341: Verify alt text implementation in ImageComponent and usage

Let's ensure the alt text is properly implemented in the ImageComponent and handled in existing image instances.

app/client/src/widgets/ImageWidget/component/index.tsx (1)

413-413: LGTM! Verify accessibility implementation

The alt property is correctly defined as an optional string.

Let's verify the accessibility implementation:

✅ Verification successful

Alt property implementation is complete and correct

The alt property is:

  • Properly defined in both ImageWidgetProps and ImageComponentProps interfaces
  • Correctly passed through the component hierarchy
  • Properly rendered in the img element with appropriate fallback
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if alt property is properly used in test files
rg -g "*.{tsx,ts}" "alt.*=.*" app/client/src/widgets/ImageWidget/

Length of output: 273


Script:

#!/bin/bash
# Check if alt property is properly defined in widget props
ast-grep --pattern 'interface ImageWidgetProps {
  $$$
  alt?: string;
  $$$
}'

# Check if alt property is properly passed through component hierarchy
rg -g "*.{tsx,ts}" "alt.*:.*" app/client/src/widgets/ImageWidget/

Length of output: 398

app/client/cypress/fixtures/TestDataSet1.json (1)

95-95: LGTM: Alt text property added for NewImage

The alt text description is clear and descriptive, aligning well with accessibility best practices.

Comment on lines +24 to +30
cy.testJsontext("alternativetext", this.dataSet.base64image.altText);
cy.wait("@updateLayout").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.EvaluateCurrentValue(this.dataSet.base64image.altText);
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 13, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace cy.wait with better alternatives

The test implementation should avoid using cy.wait as per our guidelines. Consider using Cypress's built-in retry-ability with assertions instead.

  cy.testJsontext("alternativetext", this.dataSet.base64image.altText);
- cy.wait("@updateLayout").should(
-   "have.nested.property",
-   "response.body.responseMeta.status",
-   200,
- );
+ cy.get("@updateLayout").should("have.nested.property", "response.body.responseMeta.status", 200);
📝 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
cy.testJsontext("alternativetext", this.dataSet.base64image.altText);
cy.wait("@updateLayout").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.EvaluateCurrentValue(this.dataSet.base64image.altText);
cy.testJsontext("alternativetext", this.dataSet.base64image.altText);
cy.get("@updateLayout").should("have.nested.property", "response.body.responseMeta.status", 200);
cy.EvaluateCurrentValue(this.dataSet.base64image.altText);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consistent with "image" update.

Copy link
Contributor

Choose a reason for hiding this comment

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

@vhemery, understood. Maintaining consistency with the "image" update makes sense. Thank you for the clarification.

🐰😔

Comment on lines +35 to +37
cy.get(viewWidgetsPage.imageinner)
.invoke("attr", "alt")
.should("contain", this.dataSet.base64image.altText);
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 13, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use data- attributes for selectors*

Replace the usage of viewWidgetsPage.imageinner with a data-* attribute selector for better test stability.

- cy.get(viewWidgetsPage.imageinner)
+ cy.get('[data-testid="image-widget"]')

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consistent with "src" check.

Copy link
Contributor

Choose a reason for hiding this comment

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

@vhemery, understood. Maintaining consistency with the "src" check makes sense. Thanks for clarifying.


✏️ Learnings added
Learnt from: vhemery
PR: appsmithorg/appsmith#37371
File: app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_base64_spec.js:35-37
Timestamp: 2024-11-13T09:11:36.663Z
Learning: In the file `app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_base64_spec.js`, when writing Cypress end-to-end tests for the Image Widget in JavaScript, use `viewWidgetsPage.imageinner` as the selector when asserting 'src' and 'alt' attributes to maintain consistency.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment on lines +44 to +47
cy.testCodeMirrorLast(this.dataSet.NewImageAltText);
cy.get(viewWidgetsPage.imageinner)
.invoke("attr", "alt")
.should("contain", this.dataSet.validateImageAltText);
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 13, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor test implementation to follow Cypress best practices.

The current implementation needs improvements to align with our coding guidelines:

-      cy.testCodeMirrorLast(this.dataSet.NewImageAltText);
-      cy.get(viewWidgetsPage.imageinner)
-        .invoke("attr", "alt")
-        .should("contain", this.dataSet.validateImageAltText);
+      const expectedAltText = this.dataSet.validateImageAltText;
+      cy.testCodeMirrorLast(this.dataSet.NewImageAltText);
+      cy.get('[data-testid="styledImage"]')
+        .should("be.visible")
+        .and("have.attr", "alt")
+        .and("contain", expectedAltText);

Changes:

  1. Use data-testid attribute instead of viewWidgetsPage.imageinner
  2. Add multiple assertions as per guidelines
  3. Store expected value in a variable to avoid string literals in assertions
📝 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
cy.testCodeMirrorLast(this.dataSet.NewImageAltText);
cy.get(viewWidgetsPage.imageinner)
.invoke("attr", "alt")
.should("contain", this.dataSet.validateImageAltText);
const expectedAltText = this.dataSet.validateImageAltText;
cy.testCodeMirrorLast(this.dataSet.NewImageAltText);
cy.get('[data-testid="styledImage"]')
.should("be.visible")
.and("have.attr", "alt")
.and("contain", expectedAltText);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If committed anywhere, this suggestion should be on "src" check...

Copy link
Contributor

Choose a reason for hiding this comment

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

@vhemery, understood. Thank you for pointing that out.


✏️ Learnings added
Learnt from: vhemery
PR: appsmithorg/appsmith#37371
File: app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_spec.js:44-47
Timestamp: 2024-11-13T09:07:54.787Z
Learning: When reviewing code in `app/client/cypress/**` paths, ensure that suggestions are appropriate for test code and not for `src` code. Avoid applying source code checks to test code unless relevant.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@@ -368,6 +379,7 @@ export interface ImageWidgetProps extends WidgetProps {
onClick?: string;
borderRadius: string;
boxShadow?: string;
alt?: string;
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 13, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Make alt text required and add JSDoc

For better accessibility compliance, alt text should be a required property with proper documentation.

-alt?: string;
+/** Alternative text for accessibility. Required for WCAG compliance. */
+alt: string;
📝 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
alt?: string;
/** Alternative text for accessibility. Required for WCAG compliance. */
alt: string;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alt should not be required as we have fallback values in case the user does not fill it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@vhemery, understood. Keeping the alt attribute optional makes sense given the fallback values when it's not provided.


✏️ Learnings added
Learnt from: vhemery
PR: appsmithorg/appsmith#37371
File: app/client/src/widgets/ImageWidget/widget/index.tsx:382-382
Timestamp: 2024-11-13T09:13:10.854Z
Learning: In the `ImageWidget` component (`app/client/src/widgets/ImageWidget/widget/index.tsx`), the `alt` property should remain optional (`alt?: string;`) because there are fallback values when the user does not provide alternative text.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

app/client/src/widgets/ImageWidget/widget/index.tsx Outdated Show resolved Hide resolved
app/client/src/widgets/ImageWidget/component/index.tsx Outdated Show resolved Hide resolved
vhemery and others added 2 commits November 13, 2024 10:04
Use fallback values for alt property

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Dynamic binding and length validation.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Nov 20, 2024
@vhemery
Copy link
Contributor Author

vhemery commented Nov 21, 2024

🆙 This PR is awaiting review by a code owner.

Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Nov 30, 2024
Copy link

github-actions bot commented Dec 7, 2024

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]-[658]:Add Alt-Text property for Image widget
2 participants