-
-
Notifications
You must be signed in to change notification settings - Fork 536
feat: add accessibility tests support #3162
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
385b804
feat: accessibility_tests_with_axe
Utkarsh-0304 41f3a38
fix: coderabbit_suggestions
Utkarsh-0304 decbe07
Merge branch 'main' into feat/accessibility_tests
Utkarsh-0304 bfc36aa
Merge branch 'main' of https://github.com/OWASP/Nest into feat/access…
Utkarsh-0304 1fce7ce
Merge branch 'feat/accessibility_tests' of https://github.com/Utkarsh…
Utkarsh-0304 b9c632b
fix: sonarqube_and_coderabbit_suggestions
Utkarsh-0304 75d220c
fix: code_suggestions
Utkarsh-0304 ee96230
fix: more dynamic tests cases for handling conditional rendering and …
Utkarsh-0304 00fc121
Merge branch 'main' into feat/accessibility_tests
Utkarsh-0304 e8ade76
fix: minor_coderabbit_fixes
Utkarsh-0304 c3a5b92
Merge branch 'feat/accessibility_tests' of https://github.com/Utkarsh…
Utkarsh-0304 3edde1a
Merge branch 'main' into feat/accessibility_tests
Utkarsh-0304 f2a8d1c
feat: add automated ci accessibility tests workflow script
Utkarsh-0304 d95b1b7
fix: run make check
Utkarsh-0304 50ecdd7
fix: standardise mock for next/link module
Utkarsh-0304 51c8d4d
Merge branch 'main' of https://github.com/OWASP/Nest into feat/access…
Utkarsh-0304 9388e3f
fix: distinct testid for multiple links in itemCardList component
Utkarsh-0304 6786f6e
fix: handle conditional rendering problems and remove redundant data-…
Utkarsh-0304 99c04f6
Merge branch 'main' of https://github.com/OWASP/Nest into feat/access…
Utkarsh-0304 fc5e848
fix: remove redundant mocks and typos
Utkarsh-0304 4c992c9
fix: remove multiple react imports
Utkarsh-0304 686703c
fix: return mock map object from useMap() instead of null
Utkarsh-0304 c237ce4
fix: active chapter count in mock chapter data
Utkarsh-0304 b55541d
Merge branch 'main' of https://github.com/OWASP/Nest into feat/access…
Utkarsh-0304 a691e5e
Merge branch 'main' into pr/Utkarsh-0304/3162
arkid15r f2c5357
Update code
arkid15r 40e8088
Merge branch 'feat/accessibility_tests' of https://github.com/Utkarsh…
Utkarsh-0304 6779c17
Merge branch 'main' of https://github.com/OWASP/Nest into feat/access…
Utkarsh-0304 4f6878e
fix: move mock data to __tests__, refactor imports and update needs i…
Utkarsh-0304 765deff
Merge branch 'main' into feat/accessibility_tests
Utkarsh-0304 b51cd05
fix: minor spacing issue in workflow file
Utkarsh-0304 962c62c
Merge branch 'main' of https://github.com/OWASP/Nest into feat/access…
Utkarsh-0304 5fed933
Merge branch 'feat/accessibility_tests' of https://github.com/Utkarsh…
Utkarsh-0304 840477f
Merge branch 'main' into feat/accessibility_tests
Utkarsh-0304 16ac56f
Merge branch 'main' of github.com:OWASP/Nest into pr/Utkarsh-0304/3162
kasya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| FROM node:24-alpine | ||
|
|
||
| ENV FORCE_COLOR=1 \ | ||
| NPM_CACHE="/app/.npm" \ | ||
| PNPM_HOME="/pnpm" | ||
|
|
||
| ENV NPM_CONFIG_RETRY=5 \ | ||
| NPM_CONFIG_TIMEOUT=30000 \ | ||
| PATH="$PNPM_HOME:$PATH" | ||
|
|
||
| RUN --mount=type=cache,target=${NPM_CACHE} \ | ||
| npm install --ignore-scripts -g pnpm --cache ${NPM_CACHE} | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY --chmod=444 --chown=root:root package.json pnpm-lock.yaml ./ | ||
| RUN --mount=type=cache,id=pnpm,target=/pnpm/store \ | ||
| pnpm install --frozen-lockfile --ignore-scripts && \ | ||
| chown node:node /app | ||
|
|
||
| COPY __tests__/a11y __tests__/a11y | ||
| COPY __tests__/mockData __tests__/mockData | ||
| COPY .pnpmrc jest.config.ts jest.setup.ts tsconfig.json ./ | ||
| COPY public public | ||
| COPY src src | ||
|
|
||
| USER node |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
frontend/__tests__/a11y/components/ActionButton.a11y.test.tsx
Utkarsh-0304 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { render } from '@testing-library/react' | ||
| import { axe, toHaveNoViolations } from 'jest-axe' | ||
| import ActionButton from 'components/ActionButton' | ||
|
|
||
| expect.extend(toHaveNoViolations) | ||
|
|
||
| describe('ActionButton Accessibility', () => { | ||
| it('should not have any accessibility violations when no url is provided', async () => { | ||
| const { container } = render(<ActionButton>Sample Text</ActionButton>) | ||
|
|
||
| const results = await axe(container) | ||
|
|
||
| expect(results).toHaveNoViolations() | ||
| }) | ||
|
|
||
| it('should not have any accessibility violations when url is provided', async () => { | ||
| const { container } = render(<ActionButton url="https://example.com">Visit Site</ActionButton>) | ||
|
|
||
| const results = await axe(container) | ||
|
|
||
| expect(results).toHaveNoViolations() | ||
| }) | ||
|
|
||
| it('should not have any accessibility violations when tooltipLabel is provided', async () => { | ||
| const { baseElement } = render( | ||
| <ActionButton tooltipLabel="Test Label">Test Button</ActionButton> | ||
| ) | ||
| const results = await axe(baseElement) | ||
|
|
||
| expect(results).toHaveNoViolations() | ||
| }) | ||
| }) |
15 changes: 15 additions & 0 deletions
15
frontend/__tests__/a11y/components/AnchorTitle.a11y.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { render } from '@testing-library/react' | ||
| import { axe, toHaveNoViolations } from 'jest-axe' | ||
| import AnchorTitle from 'components/AnchorTitle' | ||
|
|
||
| expect.extend(toHaveNoViolations) | ||
|
|
||
| describe('AnchorTitle Accessibility', () => { | ||
| it('should not have any accessibility violations', async () => { | ||
| const { container } = render(<AnchorTitle title="Test Title" />) | ||
|
|
||
| const results = await axe(container) | ||
|
|
||
| expect(results).toHaveNoViolations() | ||
| }) | ||
| }) |
27 changes: 27 additions & 0 deletions
27
frontend/__tests__/a11y/components/AutoScrollToTop.a11y.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { render } from '@testing-library/react' | ||
| import { axe, toHaveNoViolations } from 'jest-axe' | ||
| import AutoScrollToTop from 'components/AutoScrollToTop' | ||
|
|
||
| expect.extend(toHaveNoViolations) | ||
|
|
||
| jest.mock('next/navigation', () => ({ | ||
| usePathname: () => '/test-path', | ||
| })) | ||
|
|
||
| beforeAll(() => { | ||
| window.scrollTo = jest.fn() | ||
| }) | ||
|
|
||
| afterAll(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| describe('AutoScrollToTop Accessibility', () => { | ||
| it('should not have any accessibility violations', async () => { | ||
| const { container } = render(<AutoScrollToTop />) | ||
|
|
||
| const results = await axe(container) | ||
|
|
||
| expect(results).toHaveNoViolations() | ||
| }) | ||
| }) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { render } from '@testing-library/react' | ||
| import { axe, toHaveNoViolations } from 'jest-axe' | ||
| import Badges from 'components/Badges' | ||
|
|
||
| const defaultProps = { | ||
| name: 'Test Badge', | ||
| cssClass: 'medal', | ||
| } | ||
|
|
||
| expect.extend(toHaveNoViolations) | ||
|
|
||
| describe('Badges Accessibility', () => { | ||
| it('should not have any accessibility violations when tooltip is enabled', async () => { | ||
| const { baseElement } = render(<Badges {...defaultProps} />) | ||
|
|
||
| const results = await axe(baseElement) | ||
|
|
||
| expect(results).toHaveNoViolations() | ||
| }) | ||
|
|
||
| it('should not have any accessibility violations when tooltip is disabled', async () => { | ||
| const { baseElement } = render(<Badges {...defaultProps} showTooltip={false} />) | ||
|
|
||
| const results = await axe(baseElement) | ||
|
|
||
| expect(results).toHaveNoViolations() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import { render } from '@testing-library/react' | ||
| import { axe, toHaveNoViolations } from 'jest-axe' | ||
| import { ReactNode } from 'react' | ||
| import BarChart from 'components/BarChart' | ||
|
|
||
| const mockProps = { | ||
| title: 'Calories Burned', | ||
| labels: ['Mon', 'Tue', 'Wed'], | ||
| days: [200, 150, 100], | ||
| requirements: [180, 170, 90], | ||
| } | ||
|
|
||
| jest.mock('react-apexcharts', () => { | ||
| return function MockChart(props: { | ||
| options: unknown | ||
| series: unknown | ||
| height: number | ||
| type: string | ||
| }) { | ||
| const mockOptions = props.options as Record<string, unknown> | ||
|
|
||
| return ( | ||
| <div | ||
| data-testid="mock-chart" | ||
| data-options={JSON.stringify(mockOptions)} | ||
| data-series={JSON.stringify(props.series)} | ||
| data-height={props.height} | ||
| data-type={props.type} | ||
| /> | ||
| ) | ||
| } | ||
| }) | ||
|
|
||
| jest.mock('next/dynamic', () => { | ||
| return function mockDynamic() { | ||
| return jest.requireMock('react-apexcharts') | ||
| } | ||
| }) | ||
|
|
||
| jest.mock('next-themes', () => ({ | ||
| ThemeProvider: ({ children, ...props }: { children: ReactNode; [key: string]: unknown }) => ( | ||
| <div {...props}>{children}</div> | ||
| ), | ||
| useTheme: () => ({ theme: 'light', setTheme: jest.fn() }), | ||
| })) | ||
|
|
||
| jest.mock('components/AnchorTitle', () => { | ||
| return function MockAnchorTitle({ title }: { title: string }) { | ||
| return <div data-testid="anchor-title">{title}</div> | ||
| } | ||
| }) | ||
|
|
||
| jest.mock('components/SecondaryCard', () => { | ||
| return function MockSecondaryCard({ | ||
| title, | ||
| icon, | ||
| children, | ||
| }: { | ||
| title: ReactNode | ||
| icon?: unknown | ||
| children: ReactNode | ||
| }) { | ||
| return ( | ||
| <div data-testid="secondary-card"> | ||
| <div data-testid="card-title">{title}</div> | ||
| {icon && <div data-testid="card-icon">icon</div>} | ||
| <div data-testid="card-content">{children}</div> | ||
| </div> | ||
| ) | ||
| } | ||
| }) | ||
|
|
||
| expect.extend(toHaveNoViolations) | ||
|
|
||
| describe('BarChart Accessibility', () => { | ||
| it('should not have any accessibility violations', async () => { | ||
| const { container } = render(<BarChart {...mockProps} />) | ||
|
|
||
| const results = await axe(container) | ||
|
|
||
| expect(results).toHaveNoViolations() | ||
| }) | ||
| }) |
15 changes: 15 additions & 0 deletions
15
frontend/__tests__/a11y/components/BreadCrumbs.a11y.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { Breadcrumbs } from '@heroui/react' | ||
| import { render } from '@testing-library/react' | ||
| import { axe, toHaveNoViolations } from 'jest-axe' | ||
|
|
||
| expect.extend(toHaveNoViolations) | ||
|
|
||
| describe('Breadcrumbs a11y', () => { | ||
| it('should not have any accessibility violations', async () => { | ||
| const { container } = render(<Breadcrumbs />) | ||
|
|
||
| const results = await axe(container) | ||
|
|
||
| expect(results).toHaveNoViolations() | ||
| }) | ||
| }) |
34 changes: 34 additions & 0 deletions
34
frontend/__tests__/a11y/components/BreadCrumbsWrapper.a11y.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { render } from '@testing-library/react' | ||
| import { useBreadcrumbs } from 'hooks/useBreadcrumbs' | ||
| import { axe, toHaveNoViolations } from 'jest-axe' | ||
| import { usePathname } from 'next/navigation' | ||
| import BreadCrumbsWrapper from 'components/BreadCrumbsWrapper' | ||
|
|
||
| expect.extend(toHaveNoViolations) | ||
|
|
||
| jest.mock('next/navigation', () => ({ | ||
| usePathname: jest.fn(), | ||
| })) | ||
|
|
||
| jest.mock('hooks/useBreadcrumbs', () => ({ | ||
| useBreadcrumbs: jest.fn(), | ||
| })) | ||
|
|
||
| describe('BreadcrumbsWrapper a11y', () => { | ||
| beforeAll(() => { | ||
| ;(usePathname as jest.Mock).mockReturnValue('/projects/test-project') | ||
| ;(useBreadcrumbs as jest.Mock).mockReturnValue([ | ||
| { title: 'Home', path: '/' }, | ||
| { title: 'Projects', path: '/projects' }, | ||
| { title: 'Test Project', path: '/projects/test-project' }, | ||
| ]) | ||
| }) | ||
|
|
||
| it('should not have any accessibility violations', async () => { | ||
| const { container } = render(<BreadCrumbsWrapper />) | ||
|
|
||
| const results = await axe(container) | ||
|
|
||
| expect(results).toHaveNoViolations() | ||
| }) | ||
| }) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
38 changes: 38 additions & 0 deletions
38
frontend/__tests__/a11y/components/CalendarButton.a11y.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { render } from '@testing-library/react' | ||
| import { axe, toHaveNoViolations } from 'jest-axe' | ||
| import { FaCalendarAlt } from 'react-icons/fa' | ||
| import CalendarButton from 'components/CalendarButton' | ||
|
|
||
| expect.extend(toHaveNoViolations) | ||
|
|
||
| const mockEvent = { | ||
| title: 'Test Event', | ||
| description: 'Test description', | ||
| location: 'Test Location', | ||
| startDate: '2025-12-01', | ||
| endDate: '2025-12-02', | ||
| } | ||
|
|
||
| describe('CalendarButton Accessibility', () => { | ||
| it('should not have any accessibility violations as an icon-only button', async () => { | ||
| const { container } = render(<CalendarButton event={mockEvent} />) | ||
|
|
||
| const results = await axe(container) | ||
|
|
||
| expect(results).toHaveNoViolations() | ||
| }) | ||
|
|
||
| it('should not have any accessibility violations when showLabel is enabled', async () => { | ||
| const { container } = render(<CalendarButton event={mockEvent} showLabel />) | ||
|
|
||
| const results = await axe(container) | ||
|
|
||
| expect(results).toHaveNoViolations() | ||
| }) | ||
|
|
||
| it('should not have any accessibility violations when custom icon is provided', async () => { | ||
| const { container } = render(<CalendarButton event={mockEvent} icon={<FaCalendarAlt />} />) | ||
| const results = await axe(container) | ||
| expect(results).toHaveNoViolations() | ||
| }) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we need to add it to
needsforbuild-staging-imagesin this file (L302) and probably tobuild-production-imagesas well?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.
Yes, I do think that we should add
run-frontend-a11y-testsunder theneedssection, to make sure that accessibility tests are verified before building staging or production images. Am I correct in thinking this way?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.
Yes, let's add it.