Add contenteditable change event test

This commit is contained in:
Anders Borch
2023-04-25 11:48:54 +02:00
parent 4e517fa8f9
commit a6254197b1
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,24 @@
import EditableCell from '../EditableCell';
import { ThemeProvider } from '@emotion/react';
import { lightTheme } from '../../../layout/styles/themes';
const component = {
title: 'EditableCell',
component: EditableCell,
};
export default component;
type OwnProps = {
changeHandler: () => void;
};
export const RegularEditableCell = ({ changeHandler }: OwnProps) => {
return (
<ThemeProvider theme={lightTheme}>
<div data-testid="content-editable-parent">
<EditableCell content={''} changeHandler={changeHandler} />,
</div>
</ThemeProvider>
);
};

View File

@ -0,0 +1,17 @@
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { RegularEditableCell } from '../__stories__/EditableCell.stories';
it('Checks the EditableCell editing event bubbles up', async () => {
const func = jest.fn(() => null);
const { getByTestId } = render(<RegularEditableCell changeHandler={func} />);
const parent = getByTestId('content-editable-parent');
expect(parent).not.toBeNull();
const editable = parent.querySelector('[contenteditable]');
expect(editable).not.toBeNull();
editable && userEvent.click(editable);
userEvent.keyboard('a');
expect(func).toBeCalled();
});