Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only close annotation form on focus loss when empty #4958

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add tests
jorg-vr committed Sep 12, 2023
commit 51549c15f3c5a47d099368c34817001a54705507
27 changes: 27 additions & 0 deletions test/javascript/code_listing.test.ts
Original file line number Diff line number Diff line change
@@ -385,3 +385,30 @@ test("click on comment button", async () => {
await userEvent.click(annotationButton);
expect(document.querySelectorAll("d-annotation-form").length).toBe(1);
});

test("empty form should close on click outside", async () => {
codeListing.initAnnotateButtons();
await nextFrame();
expect(document.querySelectorAll("d-annotation-form").length).toBe(0);
const annotationButton: HTMLButtonElement = document.querySelector(".annotation-button .btn");
await userEvent.click(annotationButton);
expect(document.querySelectorAll("d-annotation-form").length).toBe(1);
await userEvent.click(document.body);
expect(document.querySelectorAll("d-annotation-form").length).toBe(0);
});

test("form should not close when it has content", async () => {
codeListing.initAnnotateButtons();
await nextFrame();
expect(document.querySelectorAll("d-annotation-form").length).toBe(0);
const annotationButton: HTMLButtonElement = document.querySelector(".annotation-button .btn");
await userEvent.click(annotationButton);
expect(document.querySelectorAll("d-annotation-form").length).toBe(1);
const textarea: HTMLTextAreaElement = document.querySelector("d-annotation-form textarea");
await userEvent.type(textarea, "This is a test");
await userEvent.click(document.body);
expect(document.querySelectorAll("d-annotation-form").length).toBe(1);
await userEvent.clear(textarea);
await userEvent.click(document.body);
expect(document.querySelectorAll("d-annotation-form").length).toBe(0);
});