-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): prevent search field input from inheriting unintended sty…
…les from default TextField (#1425)
- Loading branch information
Showing
4 changed files
with
42 additions
and
33 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
57 changes: 33 additions & 24 deletions
57
packages/react/src/components/internal/TextFieldWrapper/TextFieldWrapper.test.tsx
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 |
---|---|---|
@@ -1,51 +1,60 @@ | ||
import React from 'react'; | ||
import { render as testingRender, screen } from '@testing-library/react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { spy } from 'sinon'; | ||
import { axe } from 'jest-axe'; | ||
|
||
import TextFieldWrapper, { TextFieldWrapperProps } from './'; | ||
|
||
type RenderProps = Partial<TextFieldWrapperProps> & { | ||
[key: string]: any; | ||
}; | ||
|
||
const render = ({ className, children, ...otherProps }: RenderProps = {}) => | ||
testingRender( | ||
<TextFieldWrapper className={className} {...otherProps}> | ||
{children || <p>Children</p>} | ||
test('should render children', () => { | ||
render( | ||
<TextFieldWrapper> | ||
<p>Children</p> | ||
</TextFieldWrapper> | ||
); | ||
|
||
test('should render children', () => { | ||
render(); | ||
expect(screen.getByText('Children')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render TextFieldWrapper with default className', () => { | ||
render(); | ||
expect(screen.getByText('Children').parentElement).toHaveClass( | ||
'TextFieldWrapper' | ||
test('should support className prop', () => { | ||
render( | ||
<TextFieldWrapper className="banana"> | ||
<input /> | ||
</TextFieldWrapper> | ||
); | ||
}); | ||
|
||
test('should render TextFieldWrapper with custom className', () => { | ||
render({ className: 'banana' }); | ||
expect(screen.getByText('Children').parentElement).toHaveClass( | ||
expect(screen.getByRole('textbox').parentElement).toHaveClass( | ||
'TextFieldWrapper', | ||
'banana' | ||
); | ||
}); | ||
|
||
test('should support ref prop', () => { | ||
const ref = React.createRef<HTMLDivElement>(); | ||
render( | ||
<TextFieldWrapper className="banana" ref={ref}> | ||
<input /> | ||
</TextFieldWrapper> | ||
); | ||
expect(ref.current).toBeDefined(); | ||
expect(ref.current).toBeInstanceOf(HTMLDivElement); | ||
}); | ||
|
||
test('should render TextFieldWrapper with other props', () => { | ||
render({ id: 'banana' }); | ||
expect(screen.getByText('Children').parentElement).toHaveAttribute( | ||
render( | ||
<TextFieldWrapper id="banana"> | ||
<input /> | ||
</TextFieldWrapper> | ||
); | ||
expect(screen.getByRole('textbox').parentElement).toHaveAttribute( | ||
'id', | ||
'banana' | ||
); | ||
}); | ||
|
||
test('should have no axe violations with TextFieldWrapper', async () => { | ||
const { container } = render(); | ||
const { container } = render( | ||
<TextFieldWrapper> | ||
<p>Children</p> | ||
</TextFieldWrapper> | ||
); | ||
expect(await axe(container)).toHaveNoViolations(); | ||
}); |
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