Skip to content

Commit

Permalink
Add test and update snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris committed Sep 5, 2023
1 parent 0e6afa3 commit e0bb598
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 31 deletions.
112 changes: 81 additions & 31 deletions src/__tests__/field/__snapshots__/custom_input.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,95 @@

exports[`CustomInput when type == checkbox and when placeholderHTML is set renders correctly as a CheckBoxInput 1`] = `
<div
className="auth0-lock-input-checkbox"
className="auth0-lock-input-block auth0-lock-input-custom_input auth0-lock-input-checkbox"
>
<label>
<input
aria-label="Custom Input"
checked={false}
id="1-custom_input"
name="custom_input"
onChange={[Function]}
type="checkbox"
/>
<span
dangerouslySetInnerHTML={
{
"__html": "<b>Placeholder</b>",
<div
className="auth0-lock-input-wrap"
>
<label>
<input
aria-invalid={false}
aria-label="Custom Input"
checked={false}
id="1-custom_input"
name="custom_input"
onChange={[Function]}
type="checkbox"
/>
<span
dangerouslySetInnerHTML={
{
"__html": "<b>Placeholder</b>",
}
}
}
/>
</label>
/>
</label>
</div>
</div>
`;

exports[`CustomInput when type == checkbox renders correctly as a CheckBoxInput 1`] = `
<div
className="auth0-lock-input-checkbox"
className="auth0-lock-input-block auth0-lock-input-custom_input auth0-lock-input-checkbox"
>
<label>
<input
aria-label="Custom Input"
checked={false}
id="1-custom_input"
name="custom_input"
onChange={[Function]}
type="checkbox"
/>
<span>
placeholder
</span>
</label>
<div
className="auth0-lock-input-wrap"
>
<label>
<input
aria-invalid={false}
aria-label="Custom Input"
checked={false}
id="1-custom_input"
name="custom_input"
onChange={[Function]}
type="checkbox"
/>
<span>
placeholder
</span>
</label>
</div>
</div>
`;

exports[`CustomInput when type == checkbox shows an error when value is incorrect 1`] = `
<div
className="auth0-lock-input-block auth0-lock-input-custom_input auth0-lock-error auth0-lock-input-checkbox"
>
<div
className="auth0-lock-input-wrap"
>
<label>
<input
aria-invalid={true}
aria-label="Custom Input"
checked={false}
id="1-custom_input"
name="custom_input"
onChange={[Function]}
type="checkbox"
/>
<span
dangerouslySetInnerHTML={
{
"__html": "<b>Placeholder</b>",
}
}
/>
</label>
</div>
<div
className="auth0-lock-error-msg"
id="auth0-lock-error-msg-custom_input"
role="alert"
>
<div
className="auth0-lock-error-invalid-hint"
>
invalid-hint-custom_input
</div>
</div>
</div>
`;

Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/field/custom_input.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,31 @@ describe('CustomInput', () => {
describe('when type == checkbox', () => {
beforeEach(() => (defaultProps.type = 'checkbox'));
it('renders correctly as a CheckBoxInput', () => {
require('field/index').isFieldVisiblyInvalid = () => false;
const CustomInput = getComponent();

expectComponent(<CustomInput {...defaultProps} />).toMatchSnapshot();
});

describe('and when placeholderHTML is set', () => {
it('renders correctly as a CheckBoxInput', () => {
require('field/index').isFieldVisiblyInvalid = () => false;

const CustomInput = getComponent();

expectComponent(
<CustomInput {...defaultProps} placeholderHTML={'<b>Placeholder</b>'} />
).toMatchSnapshot();
});
});

it('shows an error when value is incorrect', () => {
const CustomInput = getComponent();

expectComponent(
<CustomInput {...defaultProps} placeholderHTML={'<b>Placeholder</b>'} />
).toMatchSnapshot();
});
});
describe('when type == hidden', () => {
beforeEach(() => {
Expand Down

0 comments on commit e0bb598

Please sign in to comment.