-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: alt text in image widget #37371
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,20 @@ describe( | |
| 200, | ||
| ); | ||
| cy.EvaluateCurrentValue(this.dataSet.base64image.withPrefix); | ||
| 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.get(viewWidgetsPage.imageinner) | ||
| .invoke("attr", "src") | ||
| .should("contain", this.dataSet.base64image.withPrefix); | ||
| cy.get(viewWidgetsPage.imageinner) | ||
| .invoke("attr", "alt") | ||
| .should("contain", this.dataSet.base64image.altText); | ||
|
Comment on lines
+35
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use data- attributes for selectors* Replace the usage of - cy.get(viewWidgetsPage.imageinner)
+ cy.get('[data-testid="image-widget"]')
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consistent with "src" check.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
| cy.closePropertyPane(); | ||
| }); | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,13 @@ describe( | |||||||||||||||||||||
| cy.get(viewWidgetsPage.imageinner) | ||||||||||||||||||||||
| .invoke("attr", "src") | ||||||||||||||||||||||
| .should("contain", this.dataSet.validateImage); | ||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * @param{TEXT} Alternative text | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| cy.testCodeMirrorLast(this.dataSet.NewImageAltText); | ||||||||||||||||||||||
| cy.get(viewWidgetsPage.imageinner) | ||||||||||||||||||||||
| .invoke("attr", "alt") | ||||||||||||||||||||||
| .should("contain", this.dataSet.validateImageAltText); | ||||||||||||||||||||||
|
Comment on lines
+44
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
📝 Committable suggestion
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If committed anywhere, this suggestion should be on "src" check...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vhemery, understood. Thank you for pointing that out. ✏️ Learnings added
|
||||||||||||||||||||||
| cy.closePropertyPane(); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -133,6 +133,23 @@ class ImageWidget extends BaseWidget<ImageWidgetProps, WidgetState> { | |||||||
| isTriggerProperty: false, | ||||||||
| validation: { type: ValidationTypes.IMAGE_URL }, | ||||||||
| }, | ||||||||
| { | ||||||||
| 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 | ||||||||
| } | ||||||||
| }, | ||||||||
| }, | ||||||||
| ], | ||||||||
| }, | ||||||||
| { | ||||||||
|
|
@@ -328,6 +345,7 @@ class ImageWidget extends BaseWidget<ImageWidgetProps, WidgetState> { | |||||||
| disableDrag={(disable: boolean) => { | ||||||||
| this.disableDrag(disable); | ||||||||
| }} | ||||||||
| alt={this.props.alt ? this.props.alt : undefined} | ||||||||
| enableDownload={this.props.enableDownload} | ||||||||
| enableRotation={this.props.enableRotation} | ||||||||
| imageUrl={this.props.image} | ||||||||
|
|
@@ -368,6 +386,7 @@ export interface ImageWidgetProps extends WidgetProps { | |||||||
| onClick?: string; | ||||||||
| borderRadius: string; | ||||||||
| boxShadow?: string; | ||||||||
| alt?: string; | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vhemery, understood. Keeping the ✏️ Learnings added
|
||||||||
| } | ||||||||
|
|
||||||||
| export default ImageWidget; | ||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.waitas 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistent with "image" update.
There was a problem hiding this comment.
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.
🐰😔