X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=webapp-frontend%2Fsrc%2Fapp%2Fpolicy%2Fpolicy-instance%2Fpolicy-instance.component.spec.ts;h=12604644af913039f4fbe6881c5dbfee2ba9da77;hb=94a4ef61a407db7514f2320ea8886c1dda526d4d;hp=2546b6d2a7ad112b81aac6c6bdf912eb82a78902;hpb=cd497d449fc933316aa3e3c2aace85fc88e2a0a8;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/policy/policy-instance/policy-instance.component.spec.ts b/webapp-frontend/src/app/policy/policy-instance/policy-instance.component.spec.ts index 2546b6d..1260464 100644 --- a/webapp-frontend/src/app/policy/policy-instance/policy-instance.component.spec.ts +++ b/webapp-frontend/src/app/policy/policy-instance/policy-instance.component.spec.ts @@ -18,38 +18,109 @@ * ========================LICENSE_END=================================== */ -import { async, ComponentFixture } from "@angular/core/testing"; +import { Component, ViewChild } from "@angular/core"; +import { async, ComponentFixture, TestBed } from "@angular/core/testing"; +import { MatDialog } from "@angular/material/dialog"; +import { + PolicyInstance, + PolicyInstances, + PolicyStatus, + PolicyTypeSchema, +} from "@app/interfaces/policy.types"; import { PolicyService } from "@app/services/policy/policy.service"; +import { ConfirmDialogService } from "@app/services/ui/confirm-dialog.service"; +import { ErrorDialogService } from "@app/services/ui/error-dialog.service"; +import { NotificationService } from "@app/services/ui/notification.service"; +import { UiService } from "@app/services/ui/ui.service"; +import { ToastrModule } from "ngx-toastr"; +import { of } from "rxjs"; import { PolicyInstanceComponent } from "./policy-instance.component"; describe("PolicyInstanceComponent", () => { - let component: PolicyInstanceComponent; - let fixture: ComponentFixture; - - // beforeEach(async(() => { - // policyDataSourceSpy = jasmine.createSpyObj("PolicyInstanceDataSource", ["getPolicyType"]); - // const policyTypeSchema = JSON.parse( - // '{"title": "1", "description": "Type 1 policy type"}' - // ); - // const policyType = { policy_schema: policyTypeSchema } as PolicyType; - // policyDataSourceSpy.getPolicyType.and.returnValue(of(policyType)); - - // TestBed.configureTestingModule({ - // declarations: [ - // PolicyTypeComponent, - // MockComponent(PolicyInstanceComponent), - // ], - // providers: [{ provide: PolicyService, useValue: policyDataSourceSpy }], - // }).compileComponents(); - // })); - - // beforeEach(() => { - // fixture = TestBed.createComponent(PolicyTypeComponent); - // component = fixture.componentInstance; - // fixture.detectChanges(); - // }); - - // it("should create", () => { - // expect(component).toBeTruthy(); - // }); -}) \ No newline at end of file + let hostComponent: PolicyInstanceComponentHostComponent; + let hostFixture: ComponentFixture; + let policyServiceSpy: jasmine.SpyObj; + let dialogSpy: jasmine.SpyObj; + + @Component({ + selector: "policy-instance-compnent-host-component", + template: + "", + }) + class PolicyInstanceComponentHostComponent { + @ViewChild(PolicyInstanceComponent) + componentUnderTest: PolicyInstanceComponent; + policyTypeSchema = JSON.parse( + '{"title": "1", "description": "Type 1 policy type"}' + ); + policyType = { + id: "type1", + name: "1", + schemaObject: this.policyTypeSchema, + } as PolicyTypeSchema; + } + + beforeEach(async(() => { + policyServiceSpy = jasmine.createSpyObj("PolicyService", [ + "getPolicyInstancesByType", + "getPolicyInstance", + "getPolicyStatus", + ]); + let policyInstances = { policy_ids: ["policy1", "policy2"] } as PolicyInstances; + policyServiceSpy.getPolicyInstancesByType.and.returnValue( + of(policyInstances) + ); + let policy1 = { + policy_id: "policy1", + policy_data: "{}", + ric_id: "1", + service_id: "service", + lastModified: "Now", + } as PolicyInstance; + let policy2 = { + policy_id: "policy2", + policy_data: "{}", + ric_id: "2", + service_id: "service", + lastModified: "Now", + } as PolicyInstance; + policyServiceSpy.getPolicyInstance.and.returnValues( + of(policy1), + of(policy2) + ); + let policy1Status = { last_modified: "Just now" } as PolicyStatus; + let policy2Status = { last_modified: "Before" } as PolicyStatus; + policyServiceSpy.getPolicyStatus.and.returnValues( + of(policy1Status), + of(policy2Status) + ); + + dialogSpy = jasmine.createSpyObj("MatDialog", ["open"]); + + TestBed.configureTestingModule({ + imports: [ToastrModule.forRoot()], + declarations: [ + PolicyInstanceComponent, + PolicyInstanceComponentHostComponent, + ], + providers: [ + { provide: PolicyService, useValue: policyServiceSpy }, + { provide: MatDialog, useValue: dialogSpy }, + ErrorDialogService, + NotificationService, + ConfirmDialogService, + UiService, + ], + }).compileComponents(); + })); + + beforeEach(() => { + hostFixture = TestBed.createComponent(PolicyInstanceComponentHostComponent); + hostComponent = hostFixture.componentInstance; + hostFixture.detectChanges(); + }); + + it("should create", () => { + expect(hostComponent).toBeTruthy(); + }); +});