-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1511 from dhis2/accessibility-updates-from-alpha
feat: accessibility updates from alpha
- Loading branch information
Showing
13 changed files
with
339 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,85 @@ | ||
import { render, fireEvent, cleanup, waitFor } from '@testing-library/react' | ||
import React from 'react' | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { SplitButton } from './split-button.js' | ||
|
||
describe('SplitButton', () => { | ||
afterEach(cleanup) | ||
|
||
it('renders button with children', () => { | ||
const { getByText } = render(<SplitButton>Click me</SplitButton>) | ||
expect(getByText('Click me')).toBeInTheDocument() | ||
}) | ||
|
||
it('toggles dropdown when left button is clicked', () => { | ||
const { getByTestId, queryByTestId } = render(<SplitButton />) | ||
const toggleButton = getByTestId('dhis2-uicore-splitbutton-toggle') | ||
|
||
fireEvent.click(toggleButton) | ||
expect( | ||
queryByTestId('dhis2-uicore-splitbutton-menu') | ||
).toBeInTheDocument() | ||
|
||
fireEvent.click(toggleButton) | ||
expect( | ||
queryByTestId('dhis2-uicore-splitbutton-menu') | ||
).not.toBeInTheDocument() | ||
}) | ||
|
||
it('renders dropdown content when open is true', () => { | ||
const { getByTestId } = render( | ||
<SplitButton component={<div>Dropdown Content</div>} /> | ||
) | ||
|
||
const toggleButton = getByTestId('dhis2-uicore-splitbutton-toggle') | ||
fireEvent.click(toggleButton) | ||
|
||
expect(getByTestId('dhis2-uicore-splitbutton-menu')).toBeInTheDocument() | ||
}) | ||
|
||
it("does not close dropdown 'Enter' key is pressed", async () => { | ||
const { getByTestId } = render( | ||
<SplitButton component={<div>Dropdown Content</div>} /> | ||
) | ||
|
||
const toggleButton = getByTestId('dhis2-uicore-splitbutton-toggle') | ||
fireEvent.click(toggleButton) | ||
expect(getByTestId('dhis2-uicore-splitbutton-menu')).toBeInTheDocument() | ||
|
||
fireEvent.keyDown(document, { key: 'Enter' }) | ||
|
||
// Use waitFor to wait for the DOM to update | ||
await waitFor(() => { | ||
expect( | ||
getByTestId('dhis2-uicore-splitbutton-menu') | ||
).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
it('closes dropdown when escape key is pressed', async () => { | ||
const { getByTestId, queryByTestId } = render( | ||
<SplitButton component={<div>Dropdown Content</div>} /> | ||
) | ||
|
||
const toggleButton = getByTestId('dhis2-uicore-splitbutton-toggle') | ||
fireEvent.click(toggleButton) | ||
expect(getByTestId('dhis2-uicore-splitbutton-menu')).toBeInTheDocument() | ||
|
||
fireEvent.keyDown(document, { key: 'Escape' }) | ||
|
||
// Use waitFor to wait for the DOM to update | ||
await waitFor(() => { | ||
expect( | ||
queryByTestId('dhis2-uicore-splitbutton-menu') | ||
).not.toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
it('adds title and aria-label attributes to the right button', () => { | ||
const { getByTestId } = render(<SplitButton />) | ||
const toggleButton = getByTestId('dhis2-uicore-splitbutton-toggle') | ||
|
||
expect(toggleButton).toHaveAttribute('title', 'Toggle dropdown') | ||
expect(toggleButton).toHaveAttribute('aria-label', 'Toggle dropdown') | ||
}) | ||
}) |
26 changes: 26 additions & 0 deletions
26
components/loader/src/circular-loader/__tests__/circular-loader.test.js
This file contains 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,26 @@ | ||
import { mount } from 'enzyme' | ||
import React from 'react' | ||
import { CircularLoader } from '../circular-loader.js' | ||
|
||
describe('Circular Loader', () => { | ||
it('renders the circular loader with aria label', () => { | ||
const wrapper = mount( | ||
<CircularLoader | ||
dataTest={'circular-loader-test'} | ||
aria-label="Circular Loader" | ||
/> | ||
) | ||
const actual = wrapper.find({ 'data-test': 'circular-loader-test' }) | ||
expect(actual.prop('role')).toBe('progressbar') | ||
expect(actual.prop('aria-label')).toBe('Circular Loader') | ||
}) | ||
|
||
it('renders the circular loader without aria label', () => { | ||
const wrapper = mount( | ||
<CircularLoader dataTest={'circular-loader-test'} /> | ||
) | ||
const actual = wrapper.find({ 'data-test': 'circular-loader-test' }) | ||
expect(actual.prop('aria-label')).toBe(undefined) | ||
expect(actual.prop('role')).toBe('progressbar') | ||
}) | ||
}) |
This file contains 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 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
29 changes: 29 additions & 0 deletions
29
components/loader/src/linear-loader/__tests__/linear-loader.test.js
This file contains 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,29 @@ | ||
import { mount } from 'enzyme' | ||
import React from 'react' | ||
import { LinearLoader } from '../linear-loader.js' | ||
|
||
describe('Linear Loader', () => { | ||
it('renders the linear loader with provided aria attributes', () => { | ||
const wrapper = mount( | ||
<LinearLoader | ||
dataTest={'linear-loader-test'} | ||
aria-label="Linear Loader" | ||
amount={15} | ||
/> | ||
) | ||
const actual = wrapper.find({ 'data-test': 'linear-loader-test' }) | ||
expect(actual.prop('role')).toBe('progressbar') | ||
expect(actual.prop('aria-label')).toBe('Linear Loader') | ||
expect(actual.prop('aria-valuenow')).toBe(15) | ||
}) | ||
|
||
it('renders the linear loader without aria label', () => { | ||
const wrapper = mount( | ||
<LinearLoader dataTest={'linear-loader-test'} amount={45} /> | ||
) | ||
const actual = wrapper.find({ 'data-test': 'linear-loader-test' }) | ||
expect(actual.prop('role')).toBe('progressbar') | ||
expect(actual.prop('aria-label')).toBe(undefined) | ||
expect(actual.prop('aria-valuenow')).toBe(45) | ||
}) | ||
}) |
This file contains 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 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 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
Oops, something went wrong.