-
Notifications
You must be signed in to change notification settings - Fork 140
test: cover hub.component sidebar gating and routerLinks #5232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion is tautological — |
||
| }); | ||
| }); | ||
|
Comment on lines
+32
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Relative to what issue #5224 asks for, this spec is missing:
These are the substantive coverage points the description promises and the issue explicitly lists. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hub_workflowandhub_datasetare not keys onSidebarTabs— the type atfrontend/src/app/common/type/gui-config.ts:49defineshub_enabled,home_enabled,workflow_enabled,dataset_enabled, etc., and the template athub.component.htmlgates its three*ngIfs onsidebarTabs.home_enabled,sidebarTabs.workflow_enabled, andsidebarTabs.dataset_enabled. Theas unknown as SidebarTabscast 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 totoBeGreaterThan(0), the test would fail because the flags don't match the template.