mengw15 commented on code in PR #7657:
URL: https://github.com/apache/texera/pull/7657#discussion_r3780882149
##########
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:
Good catch — the test now sets the textarea selection explicitly instead of
relying on the environment's default caret position, and I split it in two so
both `insert()` paths are pinned: an explicit `setSelectionRange(0,
"hello".length)` wraps the selection (`**hello**`), and an explicit empty
selection at the end falls back to the action's default text (`hello**bold**`).
--
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]