Skip to content

Commit

Permalink
Merge pull request #2490 from adevinta/fix-unreachable-a11y-report
Browse files Browse the repository at this point in the history
refactor: fix unreachable a11y report
  • Loading branch information
soykje authored Oct 23, 2024
2 parents c95734e + 03ef408 commit 73d3ffd
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions documentation/helpers/A11yReport/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,44 @@ import type { Report } from 'e2e/a11y/utils'
import { useEffect, useState } from 'react'

export const A11yReport = ({ of }: { of: string }) => {
const [errors, setErrors] = useState<Report['violations']>([])
const [errors, setErrors] = useState<Report['violations'] | 404>()

useEffect(() => {
const fetchReport = async (name: string) => {
const { violations }: Report = await fetch(`/a11y/a11y-report-${name}.json`)
.then(response => response.json())
.then(data => data[`@spark-ui/${name}`])
.catch(() => console.error('Unable to find accessibility report'))
.catch(() => {
console.error('Unable to find accessibility report')
setErrors(404)
})

if (violations.length) setErrors(violations)
}

fetchReport(of)
}, [of])

return errors.length ? (
if (!errors || (Array.isArray(errors) && !errors.length)) {
return (
<Callout kind="success" marginY="large">
<p>
This component has been successfully tested for <strong>WCAG 2.0 levels A and AA</strong>,{' '}
<strong>WCAG 2.1 levels A and AA</strong> and for common accessibility best practices.
</p>
</Callout>
)
}

if (errors === 404) {
return (
<Callout kind="error" marginY="large">
<p>No accessibility report were find for this component.</p>
</Callout>
)
}

return (
<Callout kind="error" marginY="large">
<p>
This component didn&apos;t pass all tests for <strong>WCAG 2.0 levels A and AA</strong>,{' '}
Expand All @@ -38,12 +60,5 @@ export const A11yReport = ({ of }: { of: string }) => {
))}
</ul>
</Callout>
) : (
<Callout kind="success" marginY="large">
<p>
This component has been successfully tested for <strong>WCAG 2.0 levels A and AA</strong>,{' '}
<strong>WCAG 2.1 levels A and AA</strong> and for common accessibility best practices.
</p>
</Callout>
)
}

0 comments on commit 73d3ffd

Please sign in to comment.