From 480eb2edd55fceac367cd6560707196517ebc116 Mon Sep 17 00:00:00 2001 From: Devessier Date: Tue, 17 Dec 2024 16:18:06 +0100 Subject: [PATCH] test: test that the field can be cleared --- .../FormRawJsonFieldInput.stories.tsx | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/twenty-front/src/modules/object-record/record-field/form-types/components/__stories__/FormRawJsonFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/form-types/components/__stories__/FormRawJsonFieldInput.stories.tsx index e4c721bf8b0e6..d4a6b6eb62df7 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/form-types/components/__stories__/FormRawJsonFieldInput.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/form-types/components/__stories__/FormRawJsonFieldInput.stories.tsx @@ -180,9 +180,28 @@ export const CanUseVariableAsObjectProperty: Story = { await userEvent.type(editor, '": 2 }'); + await waitFor(() => { + expect(args.onPersist).toHaveBeenCalledWith('{ "{{test}}": 2 }'); + }); + }, +}; + +export const ClearField: Story = { + args: { + placeholder: 'Enter valid json', + defaultValue: '{ "a": 2 }', + }, + play: async ({ canvasElement, args }) => { + const defaultValueStringLength = args.defaultValue!.length; + + const editor = canvasElement.querySelector('.ProseMirror > p'); + expect(editor).toBeVisible(); + await Promise.all([ + userEvent.type(editor, `{Backspace>${defaultValueStringLength}}`), + waitFor(() => { - expect(args.onPersist).toHaveBeenCalledWith('{ "{{test}}": 2 }'); + expect(args.onPersist).toHaveBeenCalledWith(null); }), ]); },