Skip to content

Commit

Permalink
feat: toggle avt test (#14449)
Browse files Browse the repository at this point in the history
* feat: toggle avt test

* fix: test arial
abelledby

* fix: test arialabelledby - test

* fix: test arialabelledby

* feat: fix tests

* fix: updating tests

* fix: update tests

* Update e2e/components/Toggle/Toggle-test.avt.e2e.js

Co-authored-by: Guilherme Datilio Ribeiro <guilhermedatilio@gmail.com>

* feat: added skeleton test

* fix: tests

* fix: tests aria

* chore: update snapshots

* feat: toggle avt test

* fix: test arial
abelledby

* fix: test arialabelledby - test

* fix: test arialabelledby

* feat: fix tests

* fix: updating tests

* fix: update tests

* Update e2e/components/Toggle/Toggle-test.avt.e2e.js

Co-authored-by: Guilherme Datilio Ribeiro <guilhermedatilio@gmail.com>

* feat: added skeleton test

* fix: tests

* fix: tests aria

* chore: update snapshots

* chore(snapshot): update snapshots

* fix: snapshots

---------

Co-authored-by: Guilherme Datilio Ribeiro <guilhermedatilio@gmail.com>
Co-authored-by: Alison Joseph <alison.joseph@us.ibm.com>
Co-authored-by: TJ Egan <tw15egan@gmail.com>
  • Loading branch information
4 people authored Aug 23, 2023
1 parent 41aa481 commit d4a0d04
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 31 deletions.
73 changes: 73 additions & 0 deletions e2e/components/Toggle/Toggle-test.avt.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const { expect, test } = require('@playwright/test');
const { visitStory } = require('../../test-utils/storybook');

test.describe('Toggle @avt', () => {
test('accessibility-checker', async ({ page }) => {
await visitStory(page, {
component: 'Toggle',
id: 'components-toggle--default',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations('Toggle');
});

test('accessibility-checker skeleton', async ({ page }) => {
await visitStory(page, {
component: 'Tabs',
id: 'components-toggle--skeleton',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations('Toggle-skeleton');
});

test('accessibility-checker small toggle', async ({ page }) => {
await visitStory(page, {
component: 'Tabs',
id: 'components-toggle--small-toggle',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations('Toggle-small');
});

test('accessibility-checker with accessible labels', async ({ page }) => {
await visitStory(page, {
component: 'Tabs',
id: 'components-toggle--with-accessible-labels',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations('Toggle-accessible-labels');
});

test('default Toggle state - keyboard nav', async ({ page }) => {
await visitStory(page, {
component: 'Tabs',
id: 'components-toggle--default',
globals: {
theme: 'white',
},
});
await page.keyboard.press('Tab');
await expect(page.getByRole('switch')).toBeVisible();
await page.keyboard.press('Space');
await page.getByText('Off');
await page.keyboard.press('Space');
await page.getByText('On');
});
});
17 changes: 2 additions & 15 deletions e2e/components/Toggle/Toggle-test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

'use strict';

const { expect, test } = require('@playwright/test'); // eslint-disable-line
const { test } = require('@playwright/test'); // eslint-disable-line
const { themes } = require('../../test-utils/env');
const { snapshotStory, visitStory } = require('../../test-utils/storybook'); // eslint-disable-line
const { snapshotStory } = require('../../test-utils/storybook'); // eslint-disable-line

test.describe('Toggle', () => {
themes.forEach((theme) => {
Expand Down Expand Up @@ -39,17 +39,4 @@ test.describe('Toggle', () => {
});
});
});

// TODO: uncomment when https://github.com/IBMa/equal-access/issues/761 is resolved

// test('accessibility-checker @avt', async ({ page }) => {
// await visitStory(page, {
// component: 'Toggle',
// id: 'components-toggle--default',
// globals: {
// theme: 'white',
// },
// });
// await expect(page).toHaveNoACViolations('Toggle');
// });
});
3 changes: 0 additions & 3 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9112,9 +9112,6 @@ Map {
},
},
"ToggleSmallSkeleton" => Object {
"defaultProps": Object {
"aria-label": "Toggle is loading",
},
"propTypes": Object {
"aria-label": Object {
"isRequired": true,
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/components/Toggle/Toggle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ describe('Toggle', () => {
});

it("doesn't render sideLabel if props.hideLabel and no props.labelText is provided", () => {
const externalElementId = 'external-element-id';
wrapper.rerender(
<Toggle
role="switch"
{...props}
hideLabel
labelText={null}
aria-labelledby={externalElementId}
aria-labelledby={props.id}
/>
);

Expand All @@ -117,7 +117,7 @@ describe('Toggle', () => {
// eslint-disable-next-line testing-library/prefer-screen-queries
expect(wrapper.getByRole('switch')).toHaveAttribute(
'aria-labelledby',
externalElementId
props.id
);

expect(
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/components/Toggle/Toggle.Skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface ToggleSkeletonProps {
}

const ToggleSkeleton: React.FC<ToggleSkeletonProps> = ({
'aria-label': ariaLabel = 'Toggle is loading',
className,
...rest
}) => {
Expand All @@ -28,7 +27,7 @@ const ToggleSkeleton: React.FC<ToggleSkeletonProps> = ({
);

return (
<div className={skeletonClassNames} {...rest} aria-label={ariaLabel}>
<div className={skeletonClassNames} {...rest}>
<div className={`${prefix}--toggle__skeleton-circle`} />
<div className={`${prefix}--toggle__skeleton-rectangle`} />
</div>
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/components/Toggle/Toggle.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Playground.argTypes = {
},
};

export const WithAcessibleLabels = () => (
export const WithAccessibleLabels = () => (
<VStack gap={7}>
<Toggle id="toggle-4" labelText="Toggle label" />

Expand All @@ -93,7 +93,7 @@ export const WithAcessibleLabels = () => (
<div id="toggle-6-label" style={{ marginBlockEnd: '0.5rem' }}>
External toggle label
</div>
<Toggle id="toggle-6" aria-labelledby="toggle-6-label" hideLabel />
<Toggle id="toggle-6" hideLabel />
</div>

<div>
Expand All @@ -109,6 +109,6 @@ export const WithAcessibleLabels = () => (

export const Skeleton = () => (
<div>
<ToggleSkeleton aria-label="Toggle is loading" />
<ToggleSkeleton />
</div>
);
2 changes: 1 addition & 1 deletion packages/react/src/components/Toggle/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export function Toggle({
role="switch"
type="button"
aria-checked={checked}
aria-labelledby={ariaLabelledby}
aria-labelledby={id}
disabled={disabled}
onClick={handleClick}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ class ToggleSmallSkeleton extends React.Component {
labelText: PropTypes.string,
};

static defaultProps = {
['aria-label']: 'Toggle is loading',
};

render() {
const { id, labelText, className, ...rest } = this.props;
return (
Expand Down

0 comments on commit d4a0d04

Please sign in to comment.