ntheanh201 commented on code in PR #7881: URL: https://github.com/apache/trafficcontrol/pull/7881#discussion_r1465075242
########## experimental/traffic-portal/src/app/core/origins/detail/origin-detail.component.spec.ts: ########## @@ -0,0 +1,124 @@ +/* + * 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 { HarnessLoader } from "@angular/cdk/testing"; +import { TestbedHarnessEnvironment } from "@angular/cdk/testing/testbed"; +import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { MatButtonHarness } from "@angular/material/button/testing"; +import { MatDialogModule } from "@angular/material/dialog"; +import { MatDialogHarness } from "@angular/material/dialog/testing"; +import { ActivatedRoute } from "@angular/router"; +import { RouterTestingModule } from "@angular/router/testing"; +import { ReplaySubject } from "rxjs"; + +import { OriginService } from "src/app/api"; +import { APITestingModule } from "src/app/api/testing"; +import { NavigationService } from "src/app/shared/navigation/navigation.service"; + +import { OriginDetailComponent } from "./origin-detail.component"; + +describe("OriginDetailComponent", () => { + let component: OriginDetailComponent; + let fixture: ComponentFixture<OriginDetailComponent>; + let route: ActivatedRoute; + let paramMap: jasmine.Spy; + let loader: HarnessLoader; + let service: OriginService; + + const navSvc = jasmine.createSpyObj([], { + headerHidden: new ReplaySubject<boolean>(), + headerTitle: new ReplaySubject<string>(), + }); + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [OriginDetailComponent], + imports: [APITestingModule, RouterTestingModule, MatDialogModule], + providers: [{provide: NavigationService, useValue: navSvc}], + }).compileComponents(); + + route = TestBed.inject(ActivatedRoute); + paramMap = spyOn(route.snapshot.paramMap, "get"); + paramMap.and.returnValue(null); + fixture = TestBed.createComponent(OriginDetailComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + service = TestBed.inject(OriginService); + loader = TestbedHarnessEnvironment.documentRootLoader(fixture); + await fixture.whenStable(); + }); + + it("should create", () => { + expect(component).toBeTruthy(); + }); + + it("new origin", async () => { + paramMap.and.returnValue("new"); + + fixture = TestBed.createComponent(OriginDetailComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + await fixture.whenStable(); + expect(paramMap).toHaveBeenCalled(); + expect(component.origin).not.toBeNull(); + expect(component.origin.name).toBe(""); + expect(component.new).toBeTrue(); + }); + + it("existing origin", async () => { + const id = 1; + paramMap.and.returnValue(id); + const origin = await service.getOrigins(id); + fixture = TestBed.createComponent(OriginDetailComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + await fixture.whenStable(); + expect(paramMap).toHaveBeenCalled(); + expect(component.origin).not.toBeNull(); + expect(component.origin.name).toBe(origin.name); + expect(component.new).toBeFalse(); + }); + + it("deletes existing Origins", async () => { Review Comment: @ocket8888 I've added the test for delete origin but I still have no idea why this.originService.deleteOrigin wasn't to be called -- 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]
