From dbb67d4219246cee961a25e6deb02d7603a4a586 Mon Sep 17 00:00:00 2001 From: Devessier Date: Tue, 17 Dec 2024 18:37:01 +0100 Subject: [PATCH] test: document some JSON behaviors --- .../FormRawJsonFieldInput.stories.tsx | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) 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 d4a6b6eb62df..c2b8aaa93758 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 @@ -206,3 +206,41 @@ export const ClearField: Story = { ]); }, }; + +/** + * Line breaks are not authorized in JSON strings. Users should instead put newlines characters themselves. + * See https://stackoverflow.com/a/42073. + */ +export const BreaksWhenUserInsertsNewlineInJsonString: Story = { + args: { + placeholder: 'Enter valid json', + onPersist: fn(), + }, + play: async ({ canvasElement, args }) => { + const editor = canvasElement.querySelector('.ProseMirror > p'); + expect(editor).toBeVisible(); + + await userEvent.type(editor, '"a{Enter}b"'); + + await userEvent.click(canvasElement); + + expect(args.onPersist).not.toHaveBeenCalled(); + }, +}; + +export const AcceptsJsonEncodedNewline: Story = { + args: { + placeholder: 'Enter valid json', + onPersist: fn(), + }, + play: async ({ canvasElement, args }) => { + const editor = canvasElement.querySelector('.ProseMirror > p'); + expect(editor).toBeVisible(); + + await userEvent.type(editor, '"a\\nb"'); + + await userEvent.click(canvasElement); + + expect(args.onPersist).toHaveBeenCalledWith('"a\\nb"'); + }, +};