This is an automated email from the ASF dual-hosted git repository.

bobbai00 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git


The following commit(s) were added to refs/heads/main by this push:
     new 33533217bd test(frontend): cover about-page login visibility branches 
(#4894)
33533217bd is described below

commit 33533217bdfa216d2ef27fa5fb1199d74d2a9937
Author: Jiadong Bai <[email protected]>
AuthorDate: Sun May 3 22:09:27 2026 -0700

    test(frontend): cover about-page login visibility branches (#4894)
    
    ### What changes were proposed in this PR?
    
    Adds 3 unit tests to `about.component.spec.ts` covering the `*ngIf`
    branches in `about.component.html` that codecov flagged on #4890:
    
    - `<texera-local-login>` is hidden when the user is logged in.
    - It is shown when the user is logged out and `config.env.localLogin` is
    true.
    - It is hidden when the user is logged out but `config.env.localLogin`
    is false.
    
    Provides `RouterTestingModule.withRoutes([])` plus a
    `NotificationService` spy via `useValue` so the real
    `LocalLoginComponent` renders under TestBed (matching the spy-mocked
    `NotificationService` pattern in `download.service.spec.ts` and
    `workflow-result-export.service.spec.ts`).
    
    ### Any related issues, documentation, discussions?
    
    Sibling of #4890 (the actual `/about` layout fix). Split out of #4890
    because the release branch still uses the old frontend testing
    framework, and the layout fix needs to backport cleanly without dragging
    the new spec along. This PR targets `main` only — no backport.
    
    ### How was this PR tested?
    
    `yarn ng test --watch=false
    --include=\"src/app/hub/component/about/about.component.spec.ts\"` → 4
    passed.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (claude-opus-4-7)
    
    Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
---
 .../hub/component/about/about.component.spec.ts    | 56 ++++++++++++++++++++--
 1 file changed, 51 insertions(+), 5 deletions(-)

diff --git a/frontend/src/app/hub/component/about/about.component.spec.ts 
b/frontend/src/app/hub/component/about/about.component.spec.ts
index 1666394b06..15acfb5da1 100644
--- a/frontend/src/app/hub/component/about/about.component.spec.ts
+++ b/frontend/src/app/hub/component/about/about.component.spec.ts
@@ -18,27 +18,73 @@
  */
 
 import { ComponentFixture, TestBed } from "@angular/core/testing";
+import { RouterTestingModule } from "@angular/router/testing";
+import { NzIconModule } from "ng-zorro-antd/icon";
+import { UserOutline, LockOutline } from "@ant-design/icons-angular/icons";
+import { vi } from "vitest";
 
 import { AboutComponent } from "./about.component";
 import { UserService } from "../../../common/service/user/user.service";
 import { StubUserService } from 
"../../../common/service/user/stub-user.service";
+import { GuiConfigService } from "../../../common/service/gui-config.service";
+import { MockGuiConfigService } from 
"../../../common/service/gui-config.service.mock";
+import { NotificationService } from 
"../../../common/service/notification/notification.service";
 import { commonTestProviders } from "../../../common/testing/test-utils";
 
 describe("AboutComponent", () => {
   let component: AboutComponent;
   let fixture: ComponentFixture<AboutComponent>;
+  let userService: StubUserService;
+  let configService: MockGuiConfigService;
 
-  beforeEach(() => {
-    TestBed.configureTestingModule({
-      imports: [AboutComponent],
-      providers: [{ provide: UserService, useClass: StubUserService }, 
...commonTestProviders],
-    });
+  function build() {
     fixture = TestBed.createComponent(AboutComponent);
     component = fixture.componentInstance;
     fixture.detectChanges();
+  }
+
+  beforeEach(() => {
+    const notificationSpy = { info: vi.fn(), success: vi.fn(), error: vi.fn() 
};
+    TestBed.configureTestingModule({
+      imports: [
+        AboutComponent,
+        RouterTestingModule.withRoutes([]),
+        // Register the icons used by <texera-local-login>'s nzPrefixIcon
+        // bindings. jsdom can't fetch icon SVGs over HTTP, so without this
+        // the icon registry emits unhandled errors that fail the run in CI.
+        NzIconModule.forChild([UserOutline, LockOutline]),
+      ],
+      providers: [
+        { provide: UserService, useClass: StubUserService },
+        { provide: NotificationService, useValue: notificationSpy },
+        ...commonTestProviders,
+      ],
+    });
+    userService = TestBed.inject(UserService) as unknown as StubUserService;
+    configService = TestBed.inject(GuiConfigService) as unknown as 
MockGuiConfigService;
   });
 
   it("should create", () => {
+    build();
     expect(component).toBeTruthy();
   });
+
+  it("hides the local login form when the user is already logged in", () => {
+    // StubUserService starts with MOCK_USER, so isLogin() === true.
+    build();
+    
expect(fixture.nativeElement.querySelector("texera-local-login")).toBeNull();
+  });
+
+  it("shows the local login form when logged out and localLogin is enabled", 
() => {
+    userService.user = undefined;
+    build();
+    
expect(fixture.nativeElement.querySelector("texera-local-login")).not.toBeNull();
+  });
+
+  it("hides the local login form when localLogin is disabled in config", () => 
{
+    userService.user = undefined;
+    configService.setConfig({ localLogin: false });
+    build();
+    
expect(fixture.nativeElement.querySelector("texera-local-login")).toBeNull();
+  });
 });

Reply via email to