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

Refs #4770 - Accessibility acceptance tests for blocks #6329

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
216 changes: 209 additions & 7 deletions packages/volto/cypress/tests/core/basic/a11y.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,224 @@
describe('Accessibility Tests', () => {
describe('Accessibility Test for contact form', () => {
beforeEach(() => {
cy.visit('/');
cy.injectAxe(); // make sure axe is available on the page
});

it('Front page has not a11y violations', () => {
cy.checkA11y(); // fail for a11y violations
});

it('Contact form has not a11y violations', () => {
it('Test contact form with cypress-axe', () => {
cy.navigate('/contact-form');
cy.get('#field-name').click().type('input');
cy.get('#field-from').click().type('[email protected]');
cy.get('#field-subject').click().type('input');
cy.get('#field-message').click().type('input');
cy.checkA11y(); // fail for a11y violations
});
});

describe('Accessibility Tests', () => {
beforeEach(() => {
cy.autologin();
cy.visit('/');
cy.injectAxe(); // make sure axe is available on the page
});

it('Test front page with cypress-axe', () => {
cy.checkA11y(); // fail for a11y violations
});

it('Test image block with cypress-axe', () => {
cy.createContent({
contentType: 'Document',
contentId: 'a11y-image-block',
contentTitle: 'a11y image block',
});
cy.visit('/a11y-image-block');
cy.wait(500);
// Add an image block
cy.navigate('/a11y-image-block/edit');
cy.get('.block .slate-editor [contenteditable=true]').click();
cy.get('.button .block-add-button').click({ force: true });
cy.get('.blocks-chooser .mostUsed')
.findByText('Image')
.click({ force: true });
cy.get('.block-editor-image [tabindex="0"]').last().focus();
cy.findByLabelText('Enter a URL to an image').click();
cy.get('.ui.input.editor-link.input-anchorlink-theme input').type(
`https://github.com/plone/volto/raw/main/logos/volto-colorful.png{enter}`,
);
cy.wait(1000);
cy.get('#toolbar-save').click();
cy.get('img').should('exist');
cy.get('img').should('have.attr', 'src');
cy.wait(1000);
cy.injectAxe();
cy.checkA11y(); // fail for a11y violations
});

it('Test table block with cypress-axe', () => {
cy.createContent({
contentType: 'Document',
contentId: 'a11y-table-block',
contentTitle: 'a11y table block',
});
cy.visit('/a11y-table-block/edit');
// Add a table block
cy.get('.block .slate-editor [contenteditable=true]').click();
cy.get('.button .block-add-button').click({ force: true });
cy.get('[aria-label="Unfold Common blocks"]').click();
cy.get('.blocks-chooser .common')
.findByText('Table')
.click({ force: true });
cy.get('tbody > :nth-child(1) > :nth-child(1)').click().type('headline 1');
cy.get('tbody > :nth-child(1) > :nth-child(2)').click().type('headline 2');
cy.get('#toolbar-save').click();
// Ensure the table exists and has correct structure
cy.get('table').should('exist'); // Wait for the table to render
cy.get('thead').should('exist'); // Ensure the table has a header
// Wait for the headers to exist and contain correct content
cy.get('thead th').should('have.length', 2);
cy.get('thead th').first().should('exist');
cy.get('thead th').last().should('exist');
cy.wait(500);
cy.injectAxe();
cy.checkA11y(); // fail for a11y violations
});

it('Test maps block with cypress-axe', () => {
cy.createContent({
contentType: 'Document',
contentId: 'a11y-maps-block',
contentTitle: 'a11y table block',
});
cy.visit('/a11y-maps-block/edit');
// Add a maps block
cy.get('.block .slate-editor [contenteditable=true]').click();
cy.get('.button .block-add-button').click({ force: true });
cy.get('[aria-label="Unfold Common blocks"]').click();
cy.get('.blocks-chooser .common').findByText('Maps').click({ force: true });
cy.get('.block.maps .toolbar-inner .ui.input input').type(
`<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2849.5450170616454!2d26.09630651539734!3d44.43966397910285!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x40b1ff21fbe45e2b%3A0x4b4116b92d4338d3!2sBucharest%2C%20Romania!5e0!3m2!1sen!2sin!4v1684408874419!5m2!1sen!2sin" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>{enter}`,
);
cy.get(
'#sidebar #blockform-fieldset-default .field-wrapper-title #field-title',
).type('plone location');
cy.get('#toolbar-save').click();
cy.wait(1000);
cy.injectAxe();
cy.checkA11y(); // fail for a11y violations
});

it('Test text block with cypress-axe', () => {
cy.createContent({
contentType: 'Document',
contentId: 'a11y-text-block',
contentTitle: 'a11y text block',
});
cy.visit('/a11y-text-block/edit');
// Add a text block
cy.get('.block .slate-editor [contenteditable=true]').click();
cy.get('.button .block-add-button').click({ force: true });
cy.get('[aria-label="Unfold Text blocks"]').click();
cy.get('.blocks-chooser .slate').findByText('Text').click({ force: true });
cy.getSlateEditorAndType('My text').contains('My text');
cy.get('#toolbar-save').click();
cy.wait(1000);
cy.injectAxe();
cy.checkA11y(); // fail for a11y violations
});

it('Test teaser block with cypress-axe', () => {
cy.createContent({
contentType: 'Document',
contentId: 'a11y-teaser-block',
contentTitle: 'a11y teaser block',
});
cy.createContent({
contentType: 'Document',
contentId: 'blue-orchids',
contentTitle: 'Blue Orchids',
contentDescription: 'are growing on the mountain tops',
image: true,
path: '/a11y-teaser-block',
});
cy.visit('/a11y-teaser-block/edit');
// Add a teaser block
cy.get('.block .slate-editor [contenteditable=true]').click();
cy.get('.button .block-add-button').click({ force: true });
cy.get('.blocks-chooser .mostUsed .button.teaser')
.contains('Teaser')
.click({ force: true });
cy.get(
'.objectbrowser-field[aria-labelledby="fieldset-default-field-label-href"] button[aria-label="Open object browser"]',
).click();
cy.get('[aria-label="Select Blue Orchids"]').dblclick();
cy.wait(500);
cy.get('.align-buttons .ui.buttons button[aria-label="Center"]').click();
cy.get('#toolbar-save').click();
cy.wait(1000);
cy.injectAxe();
cy.checkA11y(); // fail for a11y violations
});

it('Test Anchors and TOC block with cypress-axe', () => {
cy.createContent({
contentType: 'Document',
contentId: 'a11y-anchors-block',
contentTitle: 'a11y anchors block',
});
cy.visit('/a11y-anchors-block/edit');

// Add TOC block
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get(".blocks-chooser .ui.form .field.searchbox input[type='text']").type(
'table of contents',
);
cy.get('.button.toc').click();

// Add headings
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get(".blocks-chooser .ui.form .field.searchbox input[type='text']").type(
'text',
);
cy.get('.button.slate').click();
cy.get('.ui.drag.block.inner.slate').eq(0).click().type('Title 1').click();
cy.contains('Title 1').setSelection('Title 1');
cy.get('.slate-inline-toolbar .button-wrapper a[title="Title"]').click({
force: true,
});

cy.get('#toolbar-save').click();
cy.url().should('eq', Cypress.config().baseUrl + '/a11y-anchors-block');

cy.wait(1000);
cy.injectAxe();
cy.checkA11y();
});

// TODO: Update video block
// a11y tests are failing because placeholder image has no alt attribute.
// Embed component from semantic-ui doesn't accept alt property.

// it('Video block has no a11y violations', () => {
// cy.autologin();
// cy.createContent({
// contentType: 'Document',
// contentId: 'a11y-video-block',
// contentTitle: 'a11y video block',
// });
// cy.visit('/a11y-video-block/edit');
// // Add a video block
// cy.getSlate().click();
// cy.get('.ui.basic.icon.button.block-add-button').click();
// cy.get('.ui.basic.icon.button.video').contains('Video').click();
// cy.get('.toolbar-inner > .ui > input')
// .click()
// .type('https://youtu.be/T6J3d35oIAY')
// .type('{enter}');
// cy.get('#toolbar-save').click();
// cy.wait(1000);
// cy.injectAxe();
// cy.checkA11y();
// });

// TODO: Adapt this to volto-slate table
// it('Table has no a11y violations', () => {
// cy.createContent({
Expand Down
1 change: 1 addition & 0 deletions packages/volto/news/6329.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Accessibility acceptance tests for: image block, table block, maps block, text block, video block, teaser block. @iRohitSingh @tedw87