2 * ========================LICENSE_START=================================
5 * Copyright (C) 2020 Nordix Foundation
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 import { Component, ViewChild } from "@angular/core";
22 import { async, ComponentFixture, TestBed } from "@angular/core/testing";
23 import { MatDialog } from "@angular/material/dialog";
29 } from "@app/interfaces/policy.types";
30 import { PolicyService } from "@app/services/policy/policy.service";
31 import { ConfirmDialogService } from "@app/services/ui/confirm-dialog.service";
32 import { ErrorDialogService } from "@app/services/ui/error-dialog.service";
33 import { NotificationService } from "@app/services/ui/notification.service";
34 import { UiService } from "@app/services/ui/ui.service";
35 import { ToastrModule } from "ngx-toastr";
36 import { of } from "rxjs";
37 import { PolicyInstanceComponent } from "./policy-instance.component";
39 describe("PolicyInstanceComponent", () => {
40 let hostComponent: PolicyInstanceComponentHostComponent;
41 let hostFixture: ComponentFixture<PolicyInstanceComponentHostComponent>;
42 let policyServiceSpy: jasmine.SpyObj<PolicyService>;
43 let dialogSpy: jasmine.SpyObj<MatDialog>;
46 selector: "policy-instance-compnent-host-component",
48 "<nrcp-policy-instance [policyTypeSchema]=policyType></nrcp-policy-instance>",
50 class PolicyInstanceComponentHostComponent {
51 @ViewChild(PolicyInstanceComponent)
52 componentUnderTest: PolicyInstanceComponent;
53 policyTypeSchema = JSON.parse(
54 '{"title": "1", "description": "Type 1 policy type"}'
59 schemaObject: this.policyTypeSchema,
60 } as PolicyTypeSchema;
63 beforeEach(async(() => {
64 policyServiceSpy = jasmine.createSpyObj("PolicyService", [
65 "getPolicyInstancesByType",
69 let policyInstances = { policy_ids: ["policy1", "policy2"] } as PolicyInstances;
70 policyServiceSpy.getPolicyInstancesByType.and.returnValue(
77 service_id: "service",
84 service_id: "service",
87 policyServiceSpy.getPolicyInstance.and.returnValues(
91 let policy1Status = { last_modified: "Just now" } as PolicyStatus;
92 let policy2Status = { last_modified: "Before" } as PolicyStatus;
93 policyServiceSpy.getPolicyStatus.and.returnValues(
98 dialogSpy = jasmine.createSpyObj("MatDialog", ["open"]);
100 TestBed.configureTestingModule({
101 imports: [ToastrModule.forRoot()],
103 PolicyInstanceComponent,
104 PolicyInstanceComponentHostComponent,
107 { provide: PolicyService, useValue: policyServiceSpy },
108 { provide: MatDialog, useValue: dialogSpy },
111 ConfirmDialogService,
114 }).compileComponents();
118 hostFixture = TestBed.createComponent(PolicyInstanceComponentHostComponent);
119 hostComponent = hostFixture.componentInstance;
120 hostFixture.detectChanges();
123 it("should create", () => {
124 expect(hostComponent).toBeTruthy();