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

VACMS-15783: Alt-Text Validation Testing #16159

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@
"dealerdirect/phpcodesniffer-composer-installer": true,
"php-http/discovery": true,
"cweagans/composer-patches": true,
"orakili/composer-drupal-info-file-patch-helper": true
"orakili/composer-drupal-info-file-patch-helper": true,
"digitalrevolution/php-codesniffer-baseline": true
Copy link
Contributor

Choose a reason for hiding this comment

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

Strange, this should have been updated in 531ad7f. Can you double check why this change show up here?

Copy link
Contributor

Choose a reason for hiding this comment

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

@tonytaylor you might need to merge in a fresh copy of main?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

This branch isn't based off main, but 15785-alt-text-validation. So it should merge from that branch, not main. If that branch is being used as an integration branch, then it needs to be kept updated to avoid freaking out passersby.

Since this merged from main, it now includes changes to main that weren't in 15785-alt-text-validation, which makes this PR longer and weird AF to review.

Copy link
Contributor

Choose a reason for hiding this comment

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

In general, I also recommend for PRs to use rebase instead of merge to simplify the commit history for review purposes. Let me know if you need help with untangling this @tonytaylor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JunTaoLuo Thanks, I appreciate it. I could definitely stand to work on my git-fu.

Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to ping me on Slack whenever you want to sort out the git history tomorrow!

Copy link
Contributor

Choose a reason for hiding this comment

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

Noting here that this is needed because the base Tugboat image is based off of main and the base branch 15785-alt-text-validation is out of date with main, hence the need to add this tactical fix. This change will go away when the base branch is updated but we won't be blocking on that to merge the PR.

}
},
"extra": {
Expand Down
4 changes: 4 additions & 0 deletions docroot/modules/custom/va_gov_media/va_gov_media.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ type: module
description: 'Manage images and other media'
core_version_requirement: ^9 || ^10
package: 'Custom'

dependencies:
- drupal:clientside_validation
- drupal:clientside_validation_jquery
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

Feature: Alt-Text Validation
In order to enhance the veteran experience
As an editor
I need just-in-time guidance as to best practices surrounding alt-text content

Scenario: An editor supplies verbose alt-text content (server-side validation)
Given I am logged in as a user with the "administrator" role
When I save an image with 152 characters of alt-text content
Then I should see "Alternative text cannot be longer than 150 characters."

Scenario: An editor supplies redundant alt-text content (server-side validation)
Given I am logged in as a user with the "administrator" role
When I save an image with "Image of polygon" as alt-text
Then I should see "Alternative text cannot contain phrases like “image of”, “photo of”, “graphic of”, “picture of”, etc."

Scenario: An editor supplies the name of the image file as alt-text content (server-side validation)
Given I am logged in as a user with the "administrator" role
When I save an image with "polygon_image.png" as alt-text
Then I should see "Alternative text cannot contain file names."

Scenario: An editor supplies verbose alt-text content (element blur validation)
Given I am logged in as a user with the "administrator" role
When I create an image with 152 characters of alt-text content
Then I should see "Alternative text cannot be longer than 150 characters."

Scenario: An editor supplies redundant alt-text content (element blur validation)
Given I am logged in as a user with the "administrator" role
When I create an image with "Image of polygon" as alt-text
Then I should see "Alternative text cannot contain phrases like “image of”, “photo of”, “graphic of”, “picture of”, etc."

Scenario: An editor supplies the name of the image file as alt-text content (element blur validation)
Given I am logged in as a user with the "administrator" role
When I create an image with "polygon_image.png" as alt-text
Then I should see "Alternative text cannot contain file names."

Scenario: An editor supplies the name of the image file and then correctly edits field
Given I am logged in as a user with the "administrator" role
When I create an image with "polygon_image.png" as alt-text
Then I should see "Alternative text cannot contain file names."
When I update alt-text content to display "a simple polygon placeholder"
Then I should see no error message
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { When, Then } from "@badeball/cypress-cucumber-preprocessor";
import { faker } from "@faker-js/faker";

const navigateToAndFillMediaForm = () => {
cy.visit("/media/add/image");
cy.injectAxe();
cy.scrollTo("top");
cy.findAllByLabelText("Name").type(`[Test Data] ${faker.lorem.sentence()}`, {
force: true,
});
cy.findAllByLabelText("Description").type(faker.lorem.sentence(), {
force: true,
});
cy.findAllByLabelText("Section").select("VACO");
cy.get("#edit-image-0-upload")
.attachFile("images/polygon_image.png")
.wait(1000);
};

const focusOnNameField = () => {
cy.findAllByLabelText("Name").focus();
};

When("I create an image with {string} as alt-text", (altTextContent) => {
navigateToAndFillMediaForm();
cy.findAllByLabelText("Alternative text").type(altTextContent, {
force: true,
});
focusOnNameField();
});

When(
"I create an image with {int} characters of alt-text content",
(charCount) => {
navigateToAndFillMediaForm();
cy.findAllByLabelText("Alternative text").type(
faker.helpers.repeatString("a", charCount),
{
force: true,
}
);
focusOnNameField();
}
);

When("I update alt-text content to display {string}", (altTextContent) => {
cy.findAllByLabelText("Alternative text").clear();
cy.findAllByLabelText("Alternative text").type(altTextContent, {
force: true,
});
});

Then("I should see no error message", () => {
cy.get("div.form-item--error-message > strong").should(
"have.attr",
"style",
"display: none;"
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { When } from "@badeball/cypress-cucumber-preprocessor";
import { faker } from "@faker-js/faker";

const navigateToAndFillMediaForm = () => {
cy.visit("/media/add/image");
cy.injectAxe();
cy.scrollTo("top");
cy.findAllByLabelText("Name").type(`[Test Data] ${faker.lorem.sentence()}`, {
force: true,
});
cy.findAllByLabelText("Description").type(faker.lorem.sentence(), {
force: true,
});
cy.findAllByLabelText("Section").select("VACO");
cy.get("#edit-image-0-upload")
.attachFile("images/polygon_image.png")
.wait(1000);
};

const clickSaveButton = () => {
cy.get("form.media-form input#edit-submit").click();
cy.wait(1000);
};

When("I save an image with {string} as alt-text", (altTextContent) => {
navigateToAndFillMediaForm();
cy.findAllByLabelText("Alternative text").type(altTextContent, {
force: true,
});
clickSaveButton();
});

When(
"I save an image with {int} characters of alt-text content",
(charCount) => {
navigateToAndFillMediaForm();
cy.findAllByLabelText("Alternative text").type(
faker.helpers.repeatString("a", charCount),
{
force: true,
}
);
clickSaveButton();
}
);