Skip to content

Commit

Permalink
chore(deps)!: update '@alfalab/core-components'
Browse files Browse the repository at this point in the history
 BREAKING CHANGE: use version 43.0.0-44.x.x of '@alfalab/core-components'
  • Loading branch information
ekabolotina committed Nov 27, 2024
1 parent aae12fa commit 31d3d0d
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 271 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"postpublish": "git clean -fd"
},
"devDependencies": {
"@alfalab/core-components": "^42.15.0",
"@alfalab/core-components": "^44.7.5",
"@babel/cli": "^7.18.10",
"@babel/core": "^7.18.10",
"@babel/preset-env": "^7.18.10",
Expand Down Expand Up @@ -60,7 +60,7 @@
"typescript": "^4.7.4"
},
"peerDependencies": {
"@alfalab/core-components": "42.x.x",
"@alfalab/core-components": ">=43.0.0 <45.0.0",
"formik": "^2.0.0",
"react": ">=16.8.0"
},
Expand Down
107 changes: 36 additions & 71 deletions src/InputAutocomplete/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ const matchMediaMock = createMatchMediaMock();

const handleChange = jest.fn();

const handleFilter = jest.fn();

beforeAll(() => {
matchMediaMock.desktop();
});
Expand All @@ -36,13 +34,12 @@ it('should render original component', () => {
options={OPTIONS}
id="id"
onChange={handleChange}
onFilter={handleFilter}
/>
</div>,
);
renderWithFormik<Values>(
<div data-testid="bindingComponent">
<InputAutocomplete name="field" options={OPTIONS} id="id" onFilter={handleFilter} />
<InputAutocomplete name="field" options={OPTIONS} id="id" />
</div>,
{ initialValues: { field: '' } },
);
Expand All @@ -54,39 +51,30 @@ it('should render original component', () => {
});

it('should render value from formik context', () => {
renderWithFormik<Values>(
<InputAutocomplete name="field" options={OPTIONS} onFilter={handleFilter} />,
{
initialValues: { field: 'two' },
},
);
renderWithFormik<Values>(<InputAutocomplete name="field" options={OPTIONS} />, {
initialValues: { field: 'two' },
});

expect(screen.getByDisplayValue('two')).toBeInTheDocument();
});

it('should update value inside formik context', async () => {
const formikRef = createRef<FormikProps<Values>>();

renderWithFormik<Values>(
<InputAutocomplete name="field" options={OPTIONS} onFilter={handleFilter} />,
{
initialValues: { field: '' },
innerRef: formikRef,
},
);
renderWithFormik<Values>(<InputAutocomplete name="field" options={OPTIONS} />, {
initialValues: { field: '' },
innerRef: formikRef,
});
await userEvent.click(screen.getByRole('textbox'));
await userEvent.click(screen.getByText('Two'));

expect(formikRef.current?.values.field).toBe('two');
});

it('should allow to type custom text', async () => {
renderWithFormik<Values>(
<InputAutocomplete name="field" options={OPTIONS} onFilter={handleFilter} />,
{
initialValues: { field: 'Initial text' },
},
);
renderWithFormik<Values>(<InputAutocomplete name="field" options={OPTIONS} />, {
initialValues: { field: 'Initial text' },
});

await userEvent.clear(screen.getByRole('textbox'));
await userEvent.type(screen.getByRole('textbox'), 'New text');
Expand All @@ -95,12 +83,9 @@ it('should allow to type custom text', async () => {
});

it('should reset typed text if option was not selected', async () => {
renderWithFormik<Values>(
<InputAutocomplete name="field" options={OPTIONS} onFilter={handleFilter} />,
{
initialValues: { field: 'Initial text' },
},
);
renderWithFormik<Values>(<InputAutocomplete name="field" options={OPTIONS} />, {
initialValues: { field: 'Initial text' },
});

await userEvent.clear(screen.getByRole('textbox'));
await userEvent.type(screen.getByRole('textbox'), 'New text');
Expand All @@ -110,12 +95,9 @@ it('should reset typed text if option was not selected', async () => {
});

it('should render text from selected option', async () => {
renderWithFormik<Values>(
<InputAutocomplete name="field" options={OPTIONS} onFilter={handleFilter} />,
{
initialValues: { field: '' },
},
);
renderWithFormik<Values>(<InputAutocomplete name="field" options={OPTIONS} />, {
initialValues: { field: '' },
});

await userEvent.type(screen.getByRole('textbox'), 'New text');
await userEvent.click(screen.getByText('Two'));
Expand All @@ -126,52 +108,38 @@ it('should render text from selected option', async () => {
it('should update `touched` state inside formik context', async () => {
const formikRef = createRef<FormikProps<Values>>();

renderWithFormik<Values>(
<InputAutocomplete name="field" options={OPTIONS} onFilter={handleFilter} />,
{
initialValues: { field: '' },
innerRef: formikRef,
},
);
renderWithFormik<Values>(<InputAutocomplete name="field" options={OPTIONS} />, {
initialValues: { field: '' },
innerRef: formikRef,
});
await userEvent.click(screen.getByRole('textbox'));
await userEvent.click(document.body);

expect(formikRef.current?.touched.field).toBe(true);
});

it('should not render error from formik context if not touched', () => {
renderWithFormik<Values>(
<InputAutocomplete name="field" options={OPTIONS} onFilter={handleFilter} />,
{
initialValues: { field: '' },
initialErrors: { field: 'Error text' },
},
);
renderWithFormik<Values>(<InputAutocomplete name="field" options={OPTIONS} />, {
initialValues: { field: '' },
initialErrors: { field: 'Error text' },
});

expect(screen.queryByText('Error text')).not.toBeInTheDocument();
});

it('should not render error from formik context if `error={false}` provided', () => {
renderWithFormik<Values>(
<InputAutocomplete name="field" options={OPTIONS} error={false} onFilter={handleFilter} />,
{
initialValues: { field: '' },
initialErrors: { field: 'Error text' },
initialTouched: { field: true },
},
);
renderWithFormik<Values>(<InputAutocomplete name="field" options={OPTIONS} error={false} />, {
initialValues: { field: '' },
initialErrors: { field: 'Error text' },
initialTouched: { field: true },
});

expect(screen.queryByText('Error text')).not.toBeInTheDocument();
});

it('should render provided error instead of the one from formik context', () => {
renderWithFormik<Values>(
<InputAutocomplete
name="field"
options={OPTIONS}
error="Custom error"
onFilter={handleFilter}
/>,
<InputAutocomplete name="field" options={OPTIONS} error="Custom error" />,
{
initialValues: { field: '' },
initialErrors: { field: 'Error text' },
Expand All @@ -184,14 +152,11 @@ it('should render provided error instead of the one from formik context', () =>
});

it('should render error from formik context if touched', () => {
renderWithFormik<Values>(
<InputAutocomplete name="field" options={OPTIONS} onFilter={handleFilter} />,
{
initialValues: { field: '' },
initialErrors: { field: 'Error text' },
initialTouched: { field: true },
},
);
renderWithFormik<Values>(<InputAutocomplete name="field" options={OPTIONS} />, {
initialValues: { field: '' },
initialErrors: { field: 'Error text' },
initialTouched: { field: true },
});

expect(screen.queryByText('Error text')).toBeInTheDocument();
});
6 changes: 3 additions & 3 deletions src/InputAutocomplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export const InputAutocomplete: FC<InputAutocompleteProps> = (props) => {
}
};

const handleInput: CoreComponentsInputAutocompleteProps['onInput'] = (event) => {
setInputValue(event.target.value);
const handleInput: CoreComponentsInputAutocompleteProps['onInput'] = (event, payload) => {
setInputValue(payload.value);

if (onInput) {
onInput(event);
onInput(event, payload);
}
};

Expand Down
Loading

0 comments on commit 31d3d0d

Please sign in to comment.