Skip to content

Commit

Permalink
test: document some JSON behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
Devessier committed Dec 17, 2024
1 parent 90e7dc2 commit dbb67d4
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"');
},
};

0 comments on commit dbb67d4

Please sign in to comment.