Copilot commented on code in PR #6431:
URL: https://github.com/apache/texera/pull/6431#discussion_r3583137406


##########
frontend/src/app/dashboard/component/user/markdown-description/markdown-description.component.spec.ts:
##########
@@ -0,0 +1,225 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { Provider, SimpleChange } from "@angular/core";
+import { ComponentFixture, TestBed } from "@angular/core/testing";
+import { NZ_MODAL_DATA } from "ng-zorro-antd/modal";
+import { MarkdownService } from "ngx-markdown";
+import { MarkdownDescriptionComponent } from 
"./markdown-description.component";
+
+describe("MarkdownDescriptionComponent", () => {
+  // Echo non-empty markdown as trivial HTML so `renderedDescription` is 
observable
+  // without pulling in the real (config-dependent) ngx-markdown parser.
+  const parse = vi.fn((text: string) => (text ? `<p>${text}</p>` : ""));
+
+  // Passing `modalData` provides NZ_MODAL_DATA (the "opened in a modal" case);
+  // omitting it leaves the optional injection null (the inline case).
+  async function createFixture(modalData?: {
+    description?: string;
+  }): Promise<ComponentFixture<MarkdownDescriptionComponent>> {
+    const providers: Provider[] = [{ provide: MarkdownService, useValue: { 
parse } }];
+    if (modalData !== undefined) {
+      providers.push({ provide: NZ_MODAL_DATA, useValue: modalData });
+    }
+    await TestBed.configureTestingModule({
+      imports: [MarkdownDescriptionComponent],
+      providers,
+    }).compileComponents();
+    return TestBed.createComponent(MarkdownDescriptionComponent);
+  }
+
+  // A non-first change of the `description` input.
+  const descriptionChange = (previous: string, current: string): { 
description: SimpleChange } => ({
+    description: new SimpleChange(previous, current, false),
+  });
+
+  beforeEach(() => parse.mockClear());
+
+  it("should create and render the preview template when not opened in a 
modal", async () => {
+    const fixture = await createFixture();
+    fixture.componentInstance.description = "hello";
+    fixture.detectChanges();
+    await fixture.whenStable();
+
+    expect(fixture.componentInstance).toBeTruthy();
+    expect(fixture.nativeElement.querySelector(".preview-box")).toBeTruthy();
+  });
+
+  it("shows the Edit action in preview mode when editable", async () => {
+    const fixture = await createFixture();
+    fixture.componentInstance.editable = true;
+    fixture.detectChanges();
+    expect(fixture.nativeElement.querySelector(".md-actions")).toBeTruthy();
+  });
+
+  it("hides the Edit action in preview mode when not editable", async () => {
+    const fixture = await createFixture();
+    fixture.componentInstance.editable = false;
+    fixture.detectChanges();
+    expect(fixture.nativeElement.querySelector(".md-actions")).toBeNull();
+  });
+

Review Comment:
   Issue #6428 calls out covering the `enableViewMore` `@Input` binding, but 
this spec currently has no assertions around it. Adding a small test that 
toggles `enableViewMore` and verifies the preview box’s `collapsed` class 
binding would align the suite with the task requirements and guard regressions 
in the view-more feature gate.



-- 
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]

Reply via email to