Skip to content

TESTING EXTERNAL SCRIPT: external merge request from Contributor#37791

Closed
jacquesikot wants to merge 5 commits intoreleasefrom
chore/external-contribution-37371
Closed

TESTING EXTERNAL SCRIPT: external merge request from Contributor#37791
jacquesikot wants to merge 5 commits intoreleasefrom
chore/external-contribution-37371

Conversation

@jacquesikot
Copy link
Contributor

@jacquesikot jacquesikot commented Nov 28, 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/12064642042
Commit: f9c6707
Cypress dashboard.
Tags: @tag.All
Spec:
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/ClientSide/Widgets/Iframe/IframeTest_spec.ts
  2. cypress/e2e/Regression/ServerSide/ApiTests/API_MultiPart_Spec.ts
List of identified flaky tests.
Thu, 28 Nov 2024 08:56:51 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced accessibility for the Image Widget by adding support for alternative text.
    • Users can now specify alternative text for images, improving usability and compliance with accessibility standards.
  • Bug Fixes

    • Improved test coverage for the Image Widget functionality, ensuring validation of both image source and alternative text.
  • Documentation

    • Updated comments in test cases to clarify the new alternative text parameter.
  • Chores

    • Modified test data to include new fields for alternative text descriptions.

benjaminParisel and others added 5 commits November 13, 2024 09:39
Add the alt attribute as a new widget property

Fixes [#13383](#13383)
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>
@jacquesikot jacquesikot added the ok-to-test Required label for CI label Nov 28, 2024
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

Walkthrough

The changes in this pull request enhance the testing and functionality of the Image Widget, particularly focusing on Base64 image validation and alternative text. New tests have been added to verify the presence of alternative text in images, and the test suite has been updated to include these checks. Additionally, the Image Widget's code has been modified to support an alt property for accessibility, ensuring that images can be described appropriately when displayed.

Changes

File Path Change Summary
app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_base64_spec.js Added tests for alternative text associated with Base64 images, including validation of the alt attribute.
app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_spec.js Enhanced tests to verify the alt attribute of the image widget, including updated comments for clarity.
app/client/cypress/fixtures/TestDataSet1.json Added fields for NewImageAltText and validateImageAltText, and updated base64image with an altText field.
app/client/src/widgets/ImageWidget/component/index.tsx Introduced alt property in ImageComponentProps and updated the <img> element to utilize this property.
app/client/src/widgets/ImageWidget/widget/index.tsx Added alt property to ImageWidget, including configuration options and integration into the widget's view.

Possibly related PRs

Suggested labels

Bug, Widgets Product, Medium, Help enterprise

Suggested reviewers

  • ApekshaBhosale
  • sagar-qa007
  • rahulbarwal
  • albinAppsmith

🎉 In the world of code, where images reside,
Alternative text now takes a proud stride.
Tests have been added, coverage enhanced,
With every new line, our widgets have danced.
So here's to the changes, both big and small,
Making our images accessible for all! 🌟


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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6a31cac and f9c6707.

📒 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.
📓 Learnings (4)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_base64_spec.js (1)
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.959Z
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.
app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_spec.js (2)
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.959Z
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.
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.931Z
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.
app/client/src/widgets/ImageWidget/component/index.tsx (1)
Learnt from: vhemery
PR: appsmithorg/appsmith#37371
File: app/client/src/widgets/ImageWidget/widget/index.tsx:382-382
Timestamp: 2024-11-13T09:13:11.481Z
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.
app/client/src/widgets/ImageWidget/widget/index.tsx (1)
Learnt from: vhemery
PR: appsmithorg/appsmith#37371
File: app/client/src/widgets/ImageWidget/widget/index.tsx:382-382
Timestamp: 2024-11-13T09:13:11.481Z
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.
🔇 Additional comments (8)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_base64_spec.js (2)

31-31: LGTM!

The evaluation of the alternative text value is implemented correctly.


35-37: LGTM! Follows recommended selector usage

The implementation correctly uses the viewWidgetsPage.imageinner selector as recommended in previous reviews.

app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image_spec.js (1)

Line range hint 1-100: Test structure follows best practices

The test follows Cypress best practices with:

  • Proper use of describe and it blocks
  • Appropriate test grouping and naming
  • Correct use of data attributes and selectors
  • Multiple assertions where appropriate
app/client/src/widgets/ImageWidget/widget/index.tsx (2)

348-348: LGTM!

Clean implementation of the alt property with proper undefined fallback.


389-389: LGTM!

Correct TypeScript interface definition with optional alt property.

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

294-294: Well-structured alt text implementation with proper fallbacks.

The implementation follows accessibility best practices by providing meaningful fallbacks when alt text is not specified.


413-413: LGTM - Interface addition follows established patterns.

The optional alt property is correctly typed and follows the component's existing property patterns.

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

95-95: LGTM! Good accessibility enhancement.

The addition of alt text fields enhances image accessibility by providing descriptive text for both base64 and regular images.

Let's verify the alt text usage in tests:

Also applies to: 99-99, 123-123

✅ Verification successful

Alt text fields are properly used in tests

The verification shows that the alt text fields are being properly tested:

  • Image_spec.js verifies the alt text "Thor's hammer planted into the ground"
  • Image_base64_spec.js validates the alt text "A single pixel" for base64 images
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new alt text fields are being used in tests
rg -A 5 "NewImageAltText|validateImageAltText|altText"

Length of output: 6484

Comment on lines +24 to +29
cy.testJsontext("alternativetext", this.dataSet.base64image.altText);
cy.wait("@updateLayout").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
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

Replace cy.wait with better assertions

Instead of using cy.wait, consider using Cypress's built-in retry-ability with assertions that wait for the expected state.

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

Comment on lines +41 to +47
/**
* @param{TEXT} Alternative text
*/
cy.testCodeMirrorLast(this.dataSet.NewImageAltText);
cy.get(viewWidgetsPage.imageinner)
.invoke("attr", "alt")
.should("contain", this.dataSet.validateImageAltText);
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

Alt text validation looks good, but remove cy.wait usage

The alt text validation is well implemented using the correct selector and fixture data. However, there's a cy.wait(1000) earlier in the test that should be replaced with a proper assertion.

Replace the wait with an assertion:

- cy.wait(1000);
+ cy.get(viewWidgetsPage.imageinner).should('exist');
📝 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
/**
* @param{TEXT} Alternative text
*/
cy.testCodeMirrorLast(this.dataSet.NewImageAltText);
cy.get(viewWidgetsPage.imageinner)
.invoke("attr", "alt")
.should("contain", this.dataSet.validateImageAltText);
/**
* @param{TEXT} Alternative text
*/
cy.get(viewWidgetsPage.imageinner).should('exist');
cy.testCodeMirrorLast(this.dataSet.NewImageAltText);
cy.get(viewWidgetsPage.imageinner)
.invoke("attr", "alt")
.should("contain", this.dataSet.validateImageAltText);

Comment on lines +136 to +152
{
helpText: "Sets alternative text for the image",
propertyName: "alt",
label: "Alternative text",
controlType: "INPUT_TEXT",
placeholderText: "Alternative text",
isBindProperty: true,
defaultValue: "",
isTriggerProperty: false,
validation: {
type: ValidationTypes.TEXT,
params: {
required: true,
maxLength: 125
}
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove required validation for alt property

The alt property should remain optional as there are fallback values when users don't provide alternative text.

Apply this diff to fix the validation:

             validation: { 
               type: ValidationTypes.TEXT,
               params: {
-                required: true,
                 maxLength: 125
               }
             },
📝 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
{
helpText: "Sets alternative text for the image",
propertyName: "alt",
label: "Alternative text",
controlType: "INPUT_TEXT",
placeholderText: "Alternative text",
isBindProperty: true,
defaultValue: "",
isTriggerProperty: false,
validation: {
type: ValidationTypes.TEXT,
params: {
required: true,
maxLength: 125
}
},
},
{
helpText: "Sets alternative text for the image",
propertyName: "alt",
label: "Alternative text",
controlType: "INPUT_TEXT",
placeholderText: "Alternative text",
isBindProperty: true,
defaultValue: "",
isTriggerProperty: false,
validation: {
type: ValidationTypes.TEXT,
params: {
maxLength: 125
}
},
},

"base64image": {
"withoutPrefix": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==",
"withPrefix": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg=="
"withPrefix": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the trailing comma in base64 string.

The base64 string in withPrefix field contains a trailing comma which could cause parsing issues.

Apply this diff to fix the trailing comma:

-    "withPrefix": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==",
+    "withPrefix": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg=="
📝 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
"withPrefix": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==",
"withPrefix": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg=="

@jacquesikot jacquesikot added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Nov 28, 2024
);
cy.EvaluateCurrentValue(this.dataSet.base64image.withPrefix);
cy.testJsontext("alternativetext", this.dataSet.base64image.altText);
cy.wait("@updateLayout").should(
Copy link
Contributor

Choose a reason for hiding this comment

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

kindly remove waits.

@github-actions
Copy link

github-actions bot commented Dec 5, 2024

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 Dec 5, 2024
@github-actions
Copy link

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Dec 12, 2024
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 Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants