Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer committed Sep 9, 2024
1 parent 0b12295 commit ae78968
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
20 changes: 10 additions & 10 deletions packages/circuit-ui/components/ColorInput/ColorInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ import { ColorInput } from './ColorInput.js';
describe('ColorInput', () => {
const baseProps = { label: 'Car color', pickerLabel: 'Pick car color' };

it('should merge a custom class name with the default ones', () => {
const className = 'foo';
const { container } = render(
<ColorInput {...baseProps} inputClassName={className} />,
);
const input = container.querySelector('input[type="text"]');
expect(input?.className).toContain(className);
});

it('should forward a ref', () => {
const ref = createRef<InputElement>();
const { container } = render(<ColorInput {...baseProps} ref={ref} />);
Expand All @@ -38,15 +47,6 @@ describe('ColorInput', () => {
});

describe('Labeling', () => {
const HEX_SYMBOL = '#';

it('should have the hex symbol as part of its accessible description', () => {
render(<ColorInput {...baseProps} />);
expect(screen.getByRole('textbox')).toHaveAccessibleDescription(
HEX_SYMBOL,
);
});

it('should accept a custom description via aria-describedby', () => {
const customDescription = 'Custom description';
const customDescriptionId = 'customDescriptionId';
Expand All @@ -57,7 +57,7 @@ describe('ColorInput', () => {
</>,
);
expect(screen.getByRole('textbox')).toHaveAccessibleDescription(
`${HEX_SYMBOL} ${customDescription}`,
customDescription,
);
});
});
Expand Down
10 changes: 4 additions & 6 deletions packages/circuit-ui/components/ColorInput/ColorInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const ColorInput = forwardRef<InputElement, ColorInputProps>(
validationHint,
readOnly,
required,
inputClassName,
style,
value,
...props
Expand Down Expand Up @@ -120,12 +121,7 @@ export const ColorInput = forwardRef<InputElement, ColorInputProps>(
};

return (
<FieldSet
className={className}
style={style}
disabled={disabled}
aria-orientation="horizontal"
>
<FieldSet className={className} style={style} disabled={disabled}>
<FieldLegend id={labelId}>
<FieldLabelText
label={label}
Expand All @@ -150,13 +146,15 @@ export const ColorInput = forwardRef<InputElement, ColorInputProps>(
<span className={classes.symbol}>#</span>
<input
id={id}
type="text"
aria-labelledby={labelId}
aria-describedby={descriptionIds}
className={clsx(
inputClasses.base,
!disabled && hasWarning && inputClasses.warning,
hasSuffix && inputClasses['has-suffix'],
classes.input,
inputClassName,
)}
aria-invalid={invalid && 'true'}
required={required}
Expand Down

0 comments on commit ae78968

Please sign in to comment.