* ========================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<PolicyInstanceComponent>;
-
- // 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<PolicyInstanceComponentHostComponent>;
+ let policyServiceSpy: jasmine.SpyObj<PolicyService>;
+ let dialogSpy: jasmine.SpyObj<MatDialog>;
+
+ @Component({
+ selector: "policy-instance-compnent-host-component",
+ template:
+ "<nrcp-policy-instance [policyTypeSchema]=policyType></nrcp-policy-instance>",
+ })
+ 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();
+ });
+});
import { PolicyInstanceDialogComponent } from "../policy-instance-dialog/policy-instance-dialog.component";
import { getPolicyDialogProperties } from "../policy-instance-dialog/policy-instance-dialog.component";
import { HttpErrorResponse, HttpResponse } from "@angular/common/http";
-import { BehaviorSubject, Observable } from "rxjs";
+import { BehaviorSubject } from "rxjs";
import { UiService } from "@services/ui/ui.service";
import { FormControl, FormGroup } from "@angular/forms";
import { MatTableDataSource } from "@angular/material/table";
})
export class PolicyInstanceComponent implements OnInit {
@Input() policyTypeSchema: PolicyTypeSchema;
- @Input() expanded: Observable<boolean>;
policyInstances: PolicyInstance[] = [];
private policyInstanceSubject = new BehaviorSubject<PolicyInstance[]>([]);
policyTypeInfo = new Map<string, PolicyTypeInfo>();
}
ngOnInit() {
- this.expanded.subscribe((isExpanded: boolean) => this.onExpand(isExpanded));
-
this.getPolicyInstances();
this.policyInstanceSubject.subscribe((data) => {
this.instanceDataSource.data = data;
getPolicyInstances() {
this.policyInstances = [] as PolicyInstance[];
this.policySvc
- .getPolicyInstancesByType(this.policyTypeSchema.id)
- .subscribe((policies) => {
- if (policies.policy_ids.length != 0) {
- policies.policy_ids.forEach((policyId) => {
+ .getPolicyInstancesByType(this.policyTypeSchema.id)
+ .subscribe((policies) => {
+ if (policies.policy_ids.length != 0) {
+ policies.policy_ids.forEach((policyId) => {
+ this.policySvc
+ .getPolicyInstance(policyId)
+ .subscribe((policyInstance) => {
this.policySvc
- .getPolicyInstance(policyId)
- .subscribe((policyInstance) => {
- this.policySvc
.getPolicyStatus(policyId)
.subscribe((policyStatus) => {
policyInstance.lastModified = policyStatus.last_modified;