Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jassmith committed Jun 20, 2022
1 parent d637a4a commit ae32e1c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
32 changes: 32 additions & 0 deletions packages/core/src/data-editor/data-editor.test.tsx
Expand Up @@ -529,6 +529,38 @@ describe("data-editor", () => {
);
});

test.only("Does not edit when validation fails", async () => {
const spy = jest.fn();
jest.useFakeTimers();
render(<DataEditor {...basicProps} onCellEdited={spy} validateCell={() => false} />, {
wrapper: Context,
});
prep();
const canvas = screen.getByTestId("data-grid-canvas");
fireEvent.mouseDown(canvas, {
clientX: 300, // Col B
clientY: 36 + 32 + 16, // Row 1 (0 indexed)
});

fireEvent.keyDown(canvas, {
keyCode: 74,
key: "j",
});

const overlay = screen.getByDisplayValue("j");

jest.useFakeTimers();
fireEvent.keyDown(overlay, {
key: "Enter",
});

act(() => {
jest.runAllTimers();
});

expect(spy).not.toBeCalled();
});

test("Emits header click", async () => {
const spy = jest.fn();

Expand Down
Expand Up @@ -58,7 +58,11 @@ const DataGridOverlayEditor: React.FunctionComponent<DataGridOverlayEditorProps>

const [tempValue, setTempValueRaw] = React.useState<GridCell | undefined>(forceEditMode ? content : undefined);

const [isValid, setIsValid] = React.useState(true);
const [isValid, setIsValid] = React.useState(() => {
if (validateCell === undefined) return true;
if (isEditableGridCell(content) && validateCell?.(cell, content) === false) return false;
return true;
});

const onFinishEditing = React.useCallback<typeof onFinishEditingIn>(
(newCell, movement) => {
Expand Down

0 comments on commit ae32e1c

Please sign in to comment.