mengw15 commented on code in PR #5232: URL: https://github.com/apache/texera/pull/5232#discussion_r3314602442
########## frontend/src/app/hub/component/hub.component.spec.ts: ########## @@ -0,0 +1,63 @@ +/** + * 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 { ComponentFixture, TestBed } from "@angular/core/testing"; +import { HttpClientTestingModule } from "@angular/common/http/testing"; +import { NoopAnimationsModule } from "@angular/platform-browser/animations"; +import { RouterTestingModule } from "@angular/router/testing"; + +import { HubComponent } from "./hub.component"; +import { commonTestProviders } from "../../common/testing/test-utils"; +import { SidebarTabs } from "../../common/type/gui-config"; + +// HubComponent is largely presentational: it renders sidebar tabs driven by +// @Input bindings and the GuiConfigService. The behaviors worth asserting are +// that the configured sidebar tabs determine which menu items render. +describe("HubComponent", () => { + let component: HubComponent; + let fixture: ComponentFixture<HubComponent>; + + function setupComponent(isLogin: boolean, sidebarTabs: SidebarTabs): HubComponent { + TestBed.configureTestingModule({ + imports: [HubComponent, HttpClientTestingModule, NoopAnimationsModule, RouterTestingModule.withRoutes([])], + providers: [...commonTestProviders], + }); + fixture = TestBed.createComponent(HubComponent); + component = fixture.componentInstance; + component.isLogin = isLogin; + component.sidebarTabs = sidebarTabs; + fixture.detectChanges(); + return component; + } + + it("exposes the provided isLogin and sidebarTabs inputs", () => { + const tabs = { hub_workflow: true, hub_dataset: true } as unknown as SidebarTabs; + const c = setupComponent(true, tabs); + expect(c.isLogin).toBe(true); + expect(c.sidebarTabs).toBe(tabs); + }); + + it("renders a menu when sidebar tabs are enabled", () => { + const tabs = { hub_workflow: true, hub_dataset: true } as unknown as SidebarTabs; + setupComponent(false, tabs); + // At least one menu item should be present in the DOM when tabs are on. + const menuItems = fixture.nativeElement.querySelectorAll("[nz-menu-item]"); + expect(menuItems.length).toBeGreaterThanOrEqual(0); Review Comment: This assertion is tautological — `Array.prototype.length` is always `>= 0`, so the test passes regardless of what (if anything) was rendered. Combined with the `setupComponent` call on line 58 also using made-up flag names (see other comment), this test currently asserts nothing about HubComponent's render behavior. ########## frontend/src/app/hub/component/hub.component.spec.ts: ########## @@ -0,0 +1,63 @@ +/** + * 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 { ComponentFixture, TestBed } from "@angular/core/testing"; +import { HttpClientTestingModule } from "@angular/common/http/testing"; +import { NoopAnimationsModule } from "@angular/platform-browser/animations"; +import { RouterTestingModule } from "@angular/router/testing"; + +import { HubComponent } from "./hub.component"; +import { commonTestProviders } from "../../common/testing/test-utils"; +import { SidebarTabs } from "../../common/type/gui-config"; + +// HubComponent is largely presentational: it renders sidebar tabs driven by +// @Input bindings and the GuiConfigService. The behaviors worth asserting are +// that the configured sidebar tabs determine which menu items render. +describe("HubComponent", () => { + let component: HubComponent; + let fixture: ComponentFixture<HubComponent>; + + function setupComponent(isLogin: boolean, sidebarTabs: SidebarTabs): HubComponent { + TestBed.configureTestingModule({ + imports: [HubComponent, HttpClientTestingModule, NoopAnimationsModule, RouterTestingModule.withRoutes([])], + providers: [...commonTestProviders], + }); + fixture = TestBed.createComponent(HubComponent); + component = fixture.componentInstance; + component.isLogin = isLogin; + component.sidebarTabs = sidebarTabs; + fixture.detectChanges(); + return component; + } + + it("exposes the provided isLogin and sidebarTabs inputs", () => { + const tabs = { hub_workflow: true, hub_dataset: true } as unknown as SidebarTabs; + const c = setupComponent(true, tabs); + expect(c.isLogin).toBe(true); + expect(c.sidebarTabs).toBe(tabs); + }); + + it("renders a menu when sidebar tabs are enabled", () => { + const tabs = { hub_workflow: true, hub_dataset: true } as unknown as SidebarTabs; Review Comment: `hub_workflow` and `hub_dataset` are not keys on `SidebarTabs` — the type at `frontend/src/app/common/type/gui-config.ts:49` defines `hub_enabled`, `home_enabled`, `workflow_enabled`, `dataset_enabled`, etc., and the template at `hub.component.html` gates its three `*ngIf`s on `sidebarTabs.home_enabled`, `sidebarTabs.workflow_enabled`, and `sidebarTabs.dataset_enabled`. The `as unknown as SidebarTabs` cast silences the TypeScript error that would have flagged this, so the test compiles, but no menu items will ever render under this setup. Even if comment 1's assertion were strengthened to `toBeGreaterThan(0)`, the test would fail because the flags don't match the template. ########## frontend/src/app/hub/component/hub.component.spec.ts: ########## @@ -0,0 +1,63 @@ +/** + * 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 { ComponentFixture, TestBed } from "@angular/core/testing"; +import { HttpClientTestingModule } from "@angular/common/http/testing"; +import { NoopAnimationsModule } from "@angular/platform-browser/animations"; +import { RouterTestingModule } from "@angular/router/testing"; + +import { HubComponent } from "./hub.component"; +import { commonTestProviders } from "../../common/testing/test-utils"; +import { SidebarTabs } from "../../common/type/gui-config"; + +// HubComponent is largely presentational: it renders sidebar tabs driven by +// @Input bindings and the GuiConfigService. The behaviors worth asserting are +// that the configured sidebar tabs determine which menu items render. +describe("HubComponent", () => { + let component: HubComponent; + let fixture: ComponentFixture<HubComponent>; + + function setupComponent(isLogin: boolean, sidebarTabs: SidebarTabs): HubComponent { + TestBed.configureTestingModule({ + imports: [HubComponent, HttpClientTestingModule, NoopAnimationsModule, RouterTestingModule.withRoutes([])], + providers: [...commonTestProviders], + }); + fixture = TestBed.createComponent(HubComponent); + component = fixture.componentInstance; + component.isLogin = isLogin; + component.sidebarTabs = sidebarTabs; + fixture.detectChanges(); + return component; + } + + it("exposes the provided isLogin and sidebarTabs inputs", () => { + const tabs = { hub_workflow: true, hub_dataset: true } as unknown as SidebarTabs; + const c = setupComponent(true, tabs); + expect(c.isLogin).toBe(true); + expect(c.sidebarTabs).toBe(tabs); + }); + + it("renders a menu when sidebar tabs are enabled", () => { + const tabs = { hub_workflow: true, hub_dataset: true } as unknown as SidebarTabs; + setupComponent(false, tabs); + // At least one menu item should be present in the DOM when tabs are on. + const menuItems = fixture.nativeElement.querySelectorAll("[nz-menu-item]"); + expect(menuItems.length).toBeGreaterThanOrEqual(0); + }); +}); Review Comment: Relative to what issue #5224 asks for, this spec is missing: - Default state: `isLogin = false`, empty `sidebarTabs` → no menu items render. - Per-flag gating: for each of `home_enabled` / `workflow_enabled` / `dataset_enabled`, toggle that flag alone and assert exactly the matching menu item appears and the other two don't. - `routerLink` bindings: confirm each rendered menu item points at `DASHBOARD_HOME` / `DASHBOARD_HUB_WORKFLOW_RESULT` / `DASHBOARD_HUB_DATASET_RESULT` respectively (the PR description mentions reading via the `routerLinkInput` signal, but no such code is present). These are the substantive coverage points the description promises and the issue explicitly lists. -- 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]
