Copilot commented on code in PR #7657:
URL: https://github.com/apache/texera/pull/7657#discussion_r3780856586
##########
frontend/src/app/dashboard/component/user/markdown-description/markdown-description.component.spec.ts:
##########
@@ -398,4 +399,74 @@ describe("MarkdownDescriptionComponent", () => {
expect(fixture.nativeElement.querySelector(".view-more-btn")).toBeNull();
});
});
+
+ // The edit-mode markup (toolbar + textarea) only renders once currentMode
is "edit".
+ describe("edit-mode template", () => {
+ async function enterEditMode():
Promise<ComponentFixture<MarkdownDescriptionComponent>> {
+ const fixture = await createFixture();
+ fixture.componentInstance.description = "hello";
+ fixture.componentInstance.editable = true;
+ fixture.detectChanges();
+
+ // Go through the Edit button so its (click) binding executes.
+ const editButton = fixture.debugElement.query(By.css(".md-actions
button"));
+ expect(editButton).toBeTruthy();
+ editButton.triggerEventHandler("click", new MouseEvent("click"));
+ fixture.detectChanges();
+ return fixture;
+ }
+
+ it("renders one toolbar button per action and a textarea bound to the
draft", async () => {
+ const fixture = await enterEditMode();
+
+ const buttons = fixture.debugElement.queryAll(By.css(".md-toolbar
button"));
+ expect(buttons.length).toBe(fixture.componentInstance.toolbar.length);
+ const textarea = fixture.debugElement.query(By.css(".md-textarea"));
+ expect(textarea).toBeTruthy();
+ expect((textarea.nativeElement as
HTMLTextAreaElement).value).toBe("hello");
+ });
+
+ it("wraps the inserted markup into the draft when a toolbar button is
clicked", async () => {
+ const fixture = await enterEditMode();
+
+ // The first action is Bold; with the caret at the end of the draft and
no selection,
+ // it appends the wrapped default text.
+ fixture.debugElement
+ .queryAll(By.css(".md-toolbar button"))[0]
+ .triggerEventHandler("click", new MouseEvent("click"));
+ fixture.detectChanges();
+
+ expect(fixture.componentInstance.editingContent).toBe("hello**bold**");
Review Comment:
This test assumes the caret is at the end of the textarea, but it never sets
`selectionStart/selectionEnd`. Since `insert()` uses the textarea selection
offsets, the expected string (`"hello**bold**"`) depends on jsdom/browser
defaults and can become flaky. Set the selection range explicitly before
clicking the toolbar button to make the insertion position deterministic.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]