This is an automated email from the ASF dual-hosted git repository. rshah pushed a commit to branch feature/tpv2-role-details in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit c235b1a1c0453969ae85dab28f25682f14d03112 Author: Rima Shah <[email protected]> AuthorDate: Wed May 3 22:11:05 2023 -0600 Added test case (e2e and unit test for roles) --- .../traffic-portal/src/app/core/core.module.ts | 1 - .../users/roles/tables/roles-table.component.html | 2 +- .../roles/tables/roles-table.component.spec.ts | 68 ++++++++++++++++++++++ .../users/roles/tables/roles-table.component.ts | 5 +- 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/experimental/traffic-portal/src/app/core/core.module.ts b/experimental/traffic-portal/src/app/core/core.module.ts index 7ea7c23260..93fa833903 100644 --- a/experimental/traffic-portal/src/app/core/core.module.ts +++ b/experimental/traffic-portal/src/app/core/core.module.ts @@ -67,7 +67,6 @@ import { TenantsComponent } from "./users/tenants/tenants.component"; import { UserDetailsComponent } from "./users/user-details/user-details.component"; import { UserRegistrationDialogComponent } from "./users/user-registration-dialog/user-registration-dialog.component"; import { UsersComponent } from "./users/users.component"; -import { RolesTableComponent } from "./users/roles/tables/roles-table.component"; export const ROUTES: Routes = [ { component: DashboardComponent, path: "" }, diff --git a/experimental/traffic-portal/src/app/core/users/roles/tables/roles-table.component.html b/experimental/traffic-portal/src/app/core/users/roles/tables/roles-table.component.html index 550ed1bead..1ac559b6e1 100644 --- a/experimental/traffic-portal/src/app/core/users/roles/tables/roles-table.component.html +++ b/experimental/traffic-portal/src/app/core/users/roles/tables/roles-table.component.html @@ -12,7 +12,7 @@ limitations under the License. <mat-card class="table-page-content"> <div class="search-container"> - <input type="search" name="fuzzControl" aria-label="Fuzzy Search Roles" autofocus inputmode="search" role="search" accesskey="/" placeholder="Fuzzy Search" [formControl]="fuzzControl" (input)="updateURL()" /> + <input type="search" name="fuzzControl" aria-label="Fuzzy Search Roles" inputmode="search" role="search" accesskey="/" placeholder="Fuzzy Search" [formControl]="fuzzControl" (input)="updateURL()" /> </div> <tp-generic-table [data]="roles | async" diff --git a/experimental/traffic-portal/src/app/core/users/roles/tables/roles-table.component.spec.ts b/experimental/traffic-portal/src/app/core/users/roles/tables/roles-table.component.spec.ts index e69de29bb2..f7df2655fc 100644 --- a/experimental/traffic-portal/src/app/core/users/roles/tables/roles-table.component.spec.ts +++ b/experimental/traffic-portal/src/app/core/users/roles/tables/roles-table.component.spec.ts @@ -0,0 +1,68 @@ +/* +* Licensed 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, fakeAsync, TestBed, tick } from "@angular/core/testing"; +import { MatDialogModule } from "@angular/material/dialog"; +import { RouterTestingModule } from "@angular/router/testing"; + +import { APITestingModule } from "src/app/api/testing"; +import { RoleTableComponent } from "src/app/core/users/roles/table/roles-table.component"; + +describe("RoleTableComponent", () => { + let component: RoleTableComponent; + let fixture: ComponentFixture<RoleTableComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ RoleTableComponent ], + imports: [ APITestingModule, RouterTestingModule, MatDialogModule ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(RoleTableComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it("should create", () => { + expect(component).toBeTruthy(); + }); + + it("updates the fuzzy search output", fakeAsync(() => { + let called = false; + const text = "testquest"; + const spy = jasmine.createSpy("subscriber", (txt: string): void =>{ + if (!called) { + expect(txt).toBe(""); + called = true; + } else { + expect(txt).toBe(text); + } + }); + component.fuzzySubject.subscribe(spy); + tick(); + expect(spy).toHaveBeenCalled(); + component.fuzzControl.setValue(text); + component.updateURL(); + tick(); + expect(spy).toHaveBeenCalledTimes(2); + })); + + it("handles contextmenu events", () => { + expect(async () => component.handleContextMenu({ + action: component.contextMenuItems[0].name, + data: {name: "test", description: "Can only read", lastUpdated: new Date()} + })).not.toThrow(); + }); +}); diff --git a/experimental/traffic-portal/src/app/core/users/roles/tables/roles-table.component.ts b/experimental/traffic-portal/src/app/core/users/roles/tables/roles-table.component.ts index e8bbba1603..814e4863b9 100644 --- a/experimental/traffic-portal/src/app/core/users/roles/tables/roles-table.component.ts +++ b/experimental/traffic-portal/src/app/core/users/roles/tables/roles-table.component.ts @@ -14,15 +14,14 @@ import { Component, type OnInit } from "@angular/core"; import { FormControl } from "@angular/forms"; +import { ActivatedRoute } from "@angular/router"; import { BehaviorSubject } from "rxjs"; import type { ResponseRole } from "trafficops-types"; import { UserService } from "src/app/api"; import { CurrentUserService } from "src/app/shared/current-user/current-user.service"; -import type { ContextMenuItem } from "src/app/shared/generic-table/generic-table.component"; +import type { ContextMenuActionEvent, ContextMenuItem } from "src/app/shared/generic-table/generic-table.component"; import { NavigationService } from "src/app/shared/navigation/navigation.service"; -import { ActivatedRoute } from "@angular/router"; -import {ContextMenuActionEvent} from "src/app/shared/generic-table/generic-table.component"; /** * AsnsTableComponent is the controller for the "Asns" table. */
