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

[WOR-543, IA-3369] Add axe accessibility tool, first automated tests, and bug fixes. #3432

Merged
merged 5 commits into from
Oct 6, 2022
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
53 changes: 53 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"puppeteer-cluster": "^0.23.0"
},
"dependencies": {
"@axe-core/puppeteer": "^4.4.5",
"@google-cloud/secret-manager": "^4.0.0",
"date-fns": "^2.24.0",
"google-auth-library": "^7.9.2",
Expand Down
22 changes: 21 additions & 1 deletion integration-tests/tests/billing-projects.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This test is owned by the Workspaces Team.
const _ = require('lodash/fp')
const { assertTextNotFound, click, clickable, findText, gotoPage, select, signIntoTerra, waitForNoSpinners } = require('../utils/integration-utils')
const {
assertTextNotFound, click, clickable, findText, gotoPage, select, signIntoTerra, waitForNoSpinners, verifyAccessibility
} = require('../utils/integration-utils')
const { userEmail } = require('../utils/integration-config')
const { registerTest } = require('../utils/jest-utils')
const { withUserToken } = require('../utils/terra-sa-utils')
Expand Down Expand Up @@ -265,6 +267,9 @@ const testBillingSpendReportFn = withUserToken(async ({ page, testUrl, token })
await billingPage.assertText('Top 10 Spending Workspaces')
await billingPage.assertChartValue(10, 'Extra Inexpensive Workspace', 'Compute', '$0.01')

// Check accessibility of spend report page.
await verifyAccessibility(page)

// Select a billing project that is not owned by the user
await billingPage.visit()
await billingPage.selectProject(notOwnedBillingProjectName)
Expand All @@ -277,6 +282,9 @@ const testBillingSpendReportFn = withUserToken(async ({ page, testUrl, token })
await billingPage.selectProject(azureBillingProjectName, AZURE)
await billingPage.assertTextNotFound('Spend report')
await billingPage.assertTextNotFound('View billing account')

// Check accessibility of initial view.
await verifyAccessibility(page)
})

registerTest({
Expand All @@ -303,6 +311,9 @@ const testBillingWorkspacesFn = withUserToken(async ({ page, testUrl, token }) =
await billingPage.showWorkspaceDetails(`${ownedBillingProjectName}_ws`)
await billingPage.assertText(`Google Project${ownedBillingProjectName}_project`)

// Check accessibility of workspaces view (GCP).
await verifyAccessibility(page)

// Select a billing project that is not owned by the user and verify workspace tab is visible
await billingPage.visit()
await billingPage.selectProject(notOwnedBillingProjectName)
Expand All @@ -314,6 +325,9 @@ const testBillingWorkspacesFn = withUserToken(async ({ page, testUrl, token }) =
await verifyWorkspaceControls()
await billingPage.showWorkspaceDetails(`${azureBillingProjectName}_ws`)
await billingPage.assertText(`Resource Group ID${azureBillingProjectName}_mrg`)

// Check accessibility of workspaces view (Azure).
await verifyAccessibility(page)
})

registerTest({
Expand All @@ -339,6 +353,9 @@ const testBillingMembersFn = withUserToken(async ({ page, testUrl, token }) => {
await billingPage.assertText('testuser1@example.com')
await billingPage.assertText('testuser3@example.com')

// Check accessibility of users view (as owner).
await verifyAccessibility(page)

// Select a billing project that is not owned by the user
await billingPage.visit()
await billingPage.selectProject(notOwnedBillingProjectName)
Expand All @@ -353,6 +370,9 @@ const testBillingMembersFn = withUserToken(async ({ page, testUrl, token }) => {
// The test user has the User role, so they should see members with the Owner role, but not with the User role
await billingPage.assertText('testuser1@example.com')
await billingPage.assertTextNotFound('testuser3@example.com')

// Check accessibility of users view (as non-owner).
await verifyAccessibility(page)
})

registerTest({
Expand Down
10 changes: 8 additions & 2 deletions integration-tests/tests/workspace-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const _ = require('lodash/fp')
const { viewWorkspaceDashboard, withWorkspace } = require('../utils/integration-helpers')
const {
assertNavChildNotFound, assertTextNotFound, click, clickable, findElement, findText, gotoPage, navChild, noSpinnersAfter
assertNavChildNotFound, assertTextNotFound, click, clickable, findElement, findText, gotoPage, navChild, noSpinnersAfter, verifyAccessibility
} = require('../utils/integration-utils')
const { registerTest } = require('../utils/jest-utils')
const { withUserToken } = require('../utils/terra-sa-utils')
Expand Down Expand Up @@ -103,6 +103,9 @@ const testGoogleWorkspace = _.flow(

// Verify expected tabs are present.
await dashboard.assertTabs(['data', 'analyses', 'workflows', 'job history'], true)

// Check accessibility.
await verifyAccessibility(page)
})

registerTest({
Expand Down Expand Up @@ -248,8 +251,11 @@ const testAzureWorkspace = withUserToken(async ({ page, token, testUrl }) => {
// Verify tabs that currently depend on Google project ID are not present.
await dashboard.assertTabs(['data', 'notebooks', 'workflows', 'job history'], false)

// Verify Analyses tab is present (config override is set)
// Verify Analyses tab is present.
await dashboard.assertTabs(['analyses'], true)

// Check accessibility.
await verifyAccessibility(page)
})

registerTest({
Expand Down
11 changes: 10 additions & 1 deletion integration-tests/utils/integration-utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { AxePuppeteer } = require('@axe-core/puppeteer')
const _ = require('lodash/fp')
const { mkdirSync, writeFileSync } = require('fs')
const { resolve } = require('path')
Expand Down Expand Up @@ -438,6 +439,13 @@ const gotoPage = async (page, url) => {
await waitForNoSpinners(page)
}

const verifyAccessibility = async page => {
const results = await new AxePuppeteer(page).withTags(['wcag2a', 'wcag2aa']).analyze()
if (results.violations.length > 0) {
throw new Error(`Accessibility issues found:\n${JSON.stringify(results.violations, null, 2)}`)
}
}

module.exports = {
assertNavChildNotFound,
assertTextNotFound,
Expand Down Expand Up @@ -478,5 +486,6 @@ module.exports = {
maybeSaveScreenshot,
gotoPage,
savePageContent,
findButtonInDialogByAriaLabel
findButtonInDialogByAriaLabel,
verifyAccessibility
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"postinstall": "husky install"
},
"devDependencies": {
"@axe-core/react": "^4.4.5",
"@testing-library/dom": "^8.17.1",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.1.5",
Expand Down
16 changes: 16 additions & 0 deletions src/appLoader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'src/style.css'

import _ from 'lodash/fp'
import React from 'react'
import ReactDOM from 'react-dom'
import { h } from 'react-hyperscript-helpers'
import RModal from 'react-modal'
Expand All @@ -23,4 +24,19 @@ initializeClientId().then(() => {
initializeAuth()
initializeTCell()
startPollingServiceAlerts()

if (process.env.NODE_ENV === 'development') {
const axe = require('@axe-core/react')

const config = {
tags: ['wcag2a', 'wcag2aa'],
rules: [
{
id: 'color-contrast',
excludeHidden: true
}
]
}
axe(React, ReactDOM, 1000, config)
}
})
32 changes: 16 additions & 16 deletions src/components/ContextBar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,12 @@ const contextBarProps = {
describe('ContextBar - buttons', () => {
it('will render default icons', () => {
// Act
const { getByText, getByLabelText } = render(h(ContextBar, contextBarProps))
const { getByText, getByLabelText, getByTestId } = render(h(ContextBar, contextBarProps))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having to access the button by test ID is not ideal, but there is no visible text to go off of. Previously an aria-label was being added to an element that does not support that field (an anchor tag), resulting in an a11y error. I have added screenreader-only text so that the link reads out nicely, but screenreader-only text is not used by getText nor getByLabelText.

FYI @n8landolt

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this, I was hesitant to add the data id in the code on my first pass.


// Assert
expect(getByText('Rate:'))
expect(getByLabelText('Environment Configuration'))
expect(getByLabelText('Terminal button')).toHaveAttribute('disabled')
expect(getByTestId('terminal-button-id')).toHaveAttribute('disabled')
})

it('will render Jupyter button with an enabled Terminal Button', () => {
Expand All @@ -348,13 +348,13 @@ describe('ContextBar - buttons', () => {
}

// Act
const { getByText, getByLabelText } = render(h(ContextBar, jupyterContextBarProps))
const { getByText, getByLabelText, getByTestId } = render(h(ContextBar, jupyterContextBarProps))

//Assert
expect(getByText('Rate:'))
expect(getByLabelText('Environment Configuration'))
expect(getByLabelText(new RegExp(/Jupyter Environment/i)))
expect(getByLabelText('Terminal button')).toBeEnabled()
expect(getByTestId('terminal-button-id')).toBeEnabled()
expect(getByText(Utils.formatUSD(RUNTIME_COST + PERSISTENT_DISK_COST)))
expect(getByText(/Running \$.*\/hr/))
})
Expand All @@ -368,13 +368,13 @@ describe('ContextBar - buttons', () => {
}

// Act
const { getByText, getByLabelText } = render(h(ContextBar, jupyterContextBarProps))
const { getByText, getByLabelText, getByTestId } = render(h(ContextBar, jupyterContextBarProps))

//Assert
expect(getByText('Rate:'))
expect(getByLabelText('Environment Configuration'))
expect(getByLabelText(new RegExp(/Jupyter Environment/i)))
expect(getByLabelText('Terminal button')).toBeEnabled()
expect(getByTestId('terminal-button-id')).toBeEnabled()
expect(getByText(Utils.formatUSD(RUNTIME_COST + PERSISTENT_DISK_COST)))
expect(getByText(/Creating \$.*\/hr/))
})
Expand All @@ -390,15 +390,15 @@ describe('ContextBar - buttons', () => {
}

// Act
const { getByText, getByLabelText } = render(h(ContextBar, rstudioGalaxyContextBarProps))
const { getByText, getByLabelText, getByTestId } = render(h(ContextBar, rstudioGalaxyContextBarProps))

//Assert
expect(getByText('Rate:'))
expect(getByText(Utils.formatUSD(RUNTIME_COST + GALAXY_COMPUTE_COST + GALAXY_DISK_COST + PERSISTENT_DISK_COST)))
expect(getByLabelText('Environment Configuration'))
expect(getByLabelText(new RegExp(/RStudio Environment/i)))
expect(getByLabelText(new RegExp(/Galaxy Environment/i)))
expect(getByLabelText('Terminal button')).toHaveAttribute('disabled')
expect(getByTestId('terminal-button-id')).toHaveAttribute('disabled')
expect(getByText(/Running \$.*\/hr/))
expect(getByText(/Creating \$.*\/hr/))
expect(getByText(/Disk \$.*\/hr/))
Expand All @@ -413,13 +413,13 @@ describe('ContextBar - buttons', () => {
}

// Act
const { getByText, getByLabelText } = render(h(ContextBar, rstudioGalaxyContextBarProps))
const { getByText, getByLabelText, getByTestId } = render(h(ContextBar, rstudioGalaxyContextBarProps))

//Assert
expect(getByText('Rate:'))
expect(getByText('$0.00'))
expect(getByLabelText('Environment Configuration'))
expect(getByLabelText('Terminal button')).toHaveAttribute('disabled')
expect(getByTestId('terminal-button-id')).toHaveAttribute('disabled')
expect(getByLabelText(new RegExp(/Cromwell Environment/i)))
})

Expand All @@ -431,14 +431,14 @@ describe('ContextBar - buttons', () => {
}

// Act
const { getByText, getByLabelText } = render(h(ContextBar, jupyterContextBarProps))
const { getByText, getByLabelText, getByTestId } = render(h(ContextBar, jupyterContextBarProps))

//Assert
expect(getByText('Rate:'))
expect(getByText(Utils.formatUSD(RUNTIME_COST)))
expect(getByLabelText('Environment Configuration'))
expect(getByLabelText(new RegExp(/Azure Environment/i)))
expect(getByLabelText('Terminal button')).toHaveAttribute('disabled')
expect(getByTestId('terminal-button-id')).toHaveAttribute('disabled')
})

it('will render button with error status', () => {
Expand Down Expand Up @@ -551,8 +551,8 @@ describe('ContextBar - actions', () => {
}

// Act
const { getByLabelText } = render(h(ContextBar, jupyterContextBarProps))
fireEvent.click(getByLabelText('Terminal button'))
const { getByTestId } = render(h(ContextBar, jupyterContextBarProps))
fireEvent.click(getByTestId('terminal-button-id'))

// Assert
expect(Ajax().Runtimes.runtime).toBeCalledWith(jupyter.googleProject, jupyter.runtimeName)
Expand All @@ -579,8 +579,8 @@ describe('ContextBar - actions', () => {
}

// Act
const { getByLabelText } = render(h(ContextBar, jupyterContextBarProps))
fireEvent.click(getByLabelText('Terminal button'))
const { getByTestId } = render(h(ContextBar, jupyterContextBarProps))
fireEvent.click(getByTestId('terminal-button-id'))

// Assert
expect(mockRuntimesStartFn).not.toHaveBeenCalled()
Expand Down
1 change: 1 addition & 0 deletions src/components/PopupTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const MenuTrigger = ({ children, content, popupProps = {}, ...props }) =>
content: h(VerticalNavigation, [content]),
popupProps: {
role: 'menu',
'aria-modal': undefined,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was causing a failure because PopupTrigger (line 143) sets aria-modal to true, but the menu role does not support aria-modal.

'aria-orientation': 'vertical',
...popupProps
},
Expand Down
Loading