Skip to content

Commit

Permalink
[PR feedback] tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen authored Apr 16, 2024
1 parent 08c8aa3 commit 0ccc7a4
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions src/components/form/range/range.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import React from 'react';
import { fireEvent, getByRole } from '@testing-library/react';
import { fireEvent } from '@testing-library/react';
import { shouldRenderCustomStyles } from '../../../test/internal';
import { requiredProps } from '../../../test/required_props';
import { render } from '../../../test/rtl';
Expand Down Expand Up @@ -233,31 +233,34 @@ describe('EuiRange', () => {
});

describe('input aria-valuetext', () => {
const ticksWithLabels = [
{
label: '20kb',
value: 20,
accessibleLabel: 'twenty kilobytes',
},
{
label: '100kb',
value: 100,
accessibleLabel: 'one-hundred kilobytes',
},
];

it('should exist when the current value has an accessible label', () => {
const { container } = render(
<EuiRange {...props} showTicks ticks={ticksWithLabels} value={20} />
const { getByRole } = render(
<EuiRange
{...props}
showTicks
ticks={[
{
label: '20kb',
value: 20,
accessibleLabel: 'twenty kilobytes',
},
{
label: '100kb',
value: 100,
accessibleLabel: 'one-hundred kilobytes',
},
]}
value={20}
/>
);
const input = getByRole(container, 'slider');
expect(input.getAttribute('aria-valuetext')).toEqual(
expect(getByRole('slider')).toHaveAttribute(
'aria-valuetext',
'20, (twenty kilobytes)'
);
});

it('should exist when the current value has a label with typeof string', () => {
const { container } = render(
it('falls back to string `label`s if `accessibleLabel` does not exist', () => {
const { getByRole } = render(
<EuiRange
{...props}
showTicks
Expand All @@ -268,16 +271,16 @@ describe('EuiRange', () => {
value={20}
/>
);
const input = getByRole(container, 'slider');
expect(input.getAttribute('aria-valuetext')).toEqual('20, (20kb)');

expect(getByRole('slider')).toHaveAttribute('aria-valuetext', '20, (20kb)');
});

it('should not exist when the current value does not have a matching label', () => {
const { container } = render(
const { getByRole } = render(
<EuiRange {...props} showTicks ticks={ticksWithLabels} />
);
const input = getByRole(container, 'slider');
expect(input.getAttribute('aria-valuetext')).toBeNull();

expect(getByRole('slider')).not.toHaveAttribute('aria-valuetext');
});
});
});

0 comments on commit 0ccc7a4

Please sign in to comment.