Fix of new policy components 17/5717/1
authorelinuxhenrik <henrik.b.andersson@est.tech>
Fri, 5 Mar 2021 07:08:27 +0000 (08:08 +0100)
committerelinuxhenrik <henrik.b.andersson@est.tech>
Fri, 5 Mar 2021 07:08:31 +0000 (08:08 +0100)
Change-Id: I63333a6f9d950aa7da48ee55ac58696489cbb120
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Issue-ID: NONRTRIC-457

webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.html
webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.spec.ts
webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts
webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.ts
webapp-frontend/src/app/policy/policy-instance/policy-instance.component.html
webapp-frontend/src/app/policy/ric-selector/ric-selector.component.spec.ts
webapp-frontend/src/app/policy/ric-selector/ric-selector.component.ts

index 6fe3ca9..0be8837 100644 (file)
@@ -1,6 +1,6 @@
 <mat-form-field style="width: 800px;"  appearance="fill">
     <textarea id="policyJsonTextArea" formControlName="policyJsonTextArea" matInput cdkTextareaAutosize
-        cdkAutosizeMinRows="10" required [(value)]="this.policyJson" placeholder="Policy properties"
+        cdkAutosizeMinRows="10" required [value]="this.policyJson" placeholder="Policy properties"
         matTooltip="The properties of the policy instance, in JSON format" matTooltipPosition="before">
     </textarea>
     <div *ngIf="policyJsonTextArea.invalid && (policyJsonTextArea.dirty || policyJsonTextArea.touched)">
index b0700fd..77477ed 100644 (file)
@@ -1,30 +1,58 @@
+// -
+//   ========================LICENSE_START=================================
+//   O-RAN-SC
+//   %%
+//   Copyright (C) 2021: Nordix Foundation
+//   %%
+//   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.
+//   ========================LICENSE_END===================================
+//  /
+//
+
 import { HarnessLoader } from '@angular/cdk/testing';
 import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
-import { Component, ViewChild } from '@angular/core';
-import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { Component, ViewChild, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
+import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { FormBuilder, FormGroup } from '@angular/forms';
 import { MatButtonModule } from '@angular/material/button';
 import { MatButtonHarness } from '@angular/material/button/testing';
-import { MatInput, MatInputModule } from '@angular/material/input';
+import { MatFormFieldModule } from '@angular/material/form-field';
+import { MatInputModule } from '@angular/material/input';
 import { MatInputHarness } from '@angular/material/input/testing';
+import { BrowserModule } from '@angular/platform-browser';
 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
 
 import { NoTypePolicyEditorComponent } from './no-type-policy-editor.component';
 
-let formGroup: FormGroup = new FormGroup({});
-
 describe('NoTypePolicyEditorComponent', () => {
+  let formGroup: FormGroup = new FormGroup({});
+
   let component: TestNoTypePolicyEditorComponentHostComponent;
   let fixture: ComponentFixture<TestNoTypePolicyEditorComponentHostComponent>;
   let loader: HarnessLoader;
 
-  beforeEach(async(() => {
+  beforeEach(async () => {
     TestBed.configureTestingModule({
       imports: [
+        BrowserModule,
         BrowserAnimationsModule,
         MatButtonModule,
+        MatFormFieldModule,
         MatInputModule
       ],
+      schemas: [
+        CUSTOM_ELEMENTS_SCHEMA
+      ],
       declarations: [
         NoTypePolicyEditorComponent,
         TestNoTypePolicyEditorComponentHostComponent
@@ -39,7 +67,7 @@ describe('NoTypePolicyEditorComponent', () => {
     component = fixture.componentInstance;
     fixture.detectChanges();
     loader = TestbedHarnessEnvironment.loader(fixture);
-  }));
+  });
 
   it('should create', () => {
     expect(component).toBeTruthy();
@@ -61,22 +89,29 @@ describe('NoTypePolicyEditorComponent', () => {
     expect(await formatButton.isDisabled()).toBeFalsy();
   });
 
-  it('Format button should be disabled wen json not valid', async () => {
-    let textArea: MatInputHarness = await loader.getHarness(MatInputHarness.with({ selector: '#policyJsonTextArea' }));
-    await textArea.setValue('{');
+  it('Format button should be disabled when json not valid', async () => {
+    const ele = formGroup.get('policyJsonTextArea');
+    ele.setValue('{');
 
     let formatButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({ selector: '#formatButton' }));
-    // expect(await formatButton.isDisabled()).toBeTruthy();
+    expect(await formatButton.isDisabled()).toBeTruthy();
   });
-});
 
-@Component({
-  selector: `no-type-policy-editor-host-component`,
-  template: `<nrcp-no-type-policy-editor [policyJson]="this.policyJson" [instanceForm]="instanceForm"></nrcp-no-type-policy-editor>`
-})
-export class TestNoTypePolicyEditorComponentHostComponent {
-  @ViewChild(NoTypePolicyEditorComponent)
-  private noTypePolicyEditorComponentHostComponent: NoTypePolicyEditorComponent;
-  instanceForm: FormGroup = formGroup;
-  policyJson: string = '{"A":"A"}';
-}
+  it('should format unformatted json', async () => {
+    const textArea = formGroup.get('policyJsonTextArea');
+    textArea.setValue('{"A":"A"}');
+    component.noTypePolicyEditorComponent.formatJsonInput();
+    expect(component.noTypePolicyEditorComponent.policyJson).toEqual('{\n  "A": "A"\n}');
+  });
+
+  @Component({
+    selector: `no-type-policy-editor-host-component`,
+    template: `<nrcp-no-type-policy-editor [policyJson]="this.policyJson" [instanceForm]="instanceForm"></nrcp-no-type-policy-editor>`
+  })
+  class TestNoTypePolicyEditorComponentHostComponent {
+    @ViewChild(NoTypePolicyEditorComponent)
+    noTypePolicyEditorComponent: NoTypePolicyEditorComponent;
+    instanceForm: FormGroup = formGroup;
+    policyJson: string = '{"A":"A"}';
+  }
+});
index a4ce36f..f167ada 100644 (file)
@@ -1,3 +1,24 @@
+// -
+//   ========================LICENSE_START=================================
+//   O-RAN-SC
+//   %%
+//   Copyright (C) 2021: Nordix Foundation
+//   %%
+//   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.
+//   ========================LICENSE_END===================================
+//  /
+//
+
 import { Component, Input, OnInit } from '@angular/core';
 import { AbstractControl, ControlContainer, FormBuilder, FormControl, FormGroup, FormGroupDirective, ValidatorFn, Validators } from '@angular/forms';
 
index ef6bfd0..855d718 100644 (file)
@@ -90,7 +90,7 @@ export class NoTypePolicyInstanceDialogComponent implements OnInit {
     createPolicyInstance.policy_data = JSON.parse(policyJson);
     createPolicyInstance.policy_id = this.policyInstanceId;
     createPolicyInstance.policytype_id = '';
-    createPolicyInstance.ric_id = this.ricSelectorComponent.selectedRic;
+    createPolicyInstance.ric_id = this.ricSelectorComponent ? this.ricSelectorComponent.selectedRic : this.ric;
     createPolicyInstance.service_id = 'controlpanel';
     return createPolicyInstance;
   }
index eca57ab..9c7032c 100644 (file)
@@ -81,7 +81,3 @@
     </mat-footer-row>
 
 </table>
-
-<div class="spinner-container" *ngIf="instanceDataSource.loading$ | async">
-    <mat-spinner diameter="50"></mat-spinner>
-</div>
\ No newline at end of file
index 0306ec4..ab75c5e 100644 (file)
@@ -1,6 +1,27 @@
+// -
+//   ========================LICENSE_START=================================
+//   O-RAN-SC
+//   %%
+//   Copyright (C) 2021: Nordix Foundation
+//   %%
+//   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.
+//   ========================LICENSE_END===================================
+//  /
+//
+
 import { HarnessLoader } from '@angular/cdk/testing';
 import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
-import { Component, ViewChild } from '@angular/core';
+import { Component, ViewChild, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
 import { FormBuilder, FormGroup } from '@angular/forms';
 import { MatSelectModule } from '@angular/material/select';
@@ -12,9 +33,9 @@ import { PolicyService } from 'src/app/services/policy/policy.service';
 
 import { RicSelectorComponent } from './ric-selector.component';
 
-let formGroup: FormGroup = new FormGroup({});
 
 describe('RicSelectorComponent', () => {
+  let formGroup: FormGroup = new FormGroup({});
   let component: TestRicSelectorHostComponent;
   let fixture: ComponentFixture<TestRicSelectorHostComponent>;
   let loader: HarnessLoader;
@@ -38,6 +59,9 @@ describe('RicSelectorComponent', () => {
         BrowserAnimationsModule,
         MatSelectModule,
       ],
+      schemas: [
+        CUSTOM_ELEMENTS_SCHEMA
+      ],
       declarations: [
         RicSelectorComponent,
         TestRicSelectorHostComponent
@@ -47,7 +71,7 @@ describe('RicSelectorComponent', () => {
         FormBuilder
       ]
     })
-      .compileComponents();
+    .compileComponents();
 
     fixture = TestBed.createComponent(TestRicSelectorHostComponent);
     component = fixture.componentInstance;
@@ -80,15 +104,15 @@ describe('RicSelectorComponent', () => {
     const count = (await ricSelector.getOptions()).length;
     expect(count).toEqual(2);
   });
-});
 
-@Component({
-  selector: `ric-selector-host-component`,
-  template: `<nrcp-ric-selector [instanceForm]="instanceForm" [policyTypeName]="policyTypeName"></nrcp-ric-selector>`
-})
-export class TestRicSelectorHostComponent {
-  @ViewChild(RicSelectorComponent)
-  private ricSelectorComponent: RicSelectorComponent;
-  instanceForm: FormGroup = formGroup;
-  policyTypeName: string = 'policyTypeName';
-}
+  @Component({
+    selector: `ric-selector-host-component`,
+    template: `<nrcp-ric-selector [instanceForm]="instanceForm" [policyTypeName]="policyTypeName"></nrcp-ric-selector>`
+  })
+  class TestRicSelectorHostComponent {
+    @ViewChild(RicSelectorComponent)
+    private ricSelectorComponent: RicSelectorComponent;
+    instanceForm: FormGroup = formGroup;
+    policyTypeName: string = 'policyTypeName';
+  }
+});
index 583f02a..d4b50c0 100644 (file)
@@ -1,3 +1,24 @@
+// -
+//   ========================LICENSE_START=================================
+//   O-RAN-SC
+//   %%
+//   Copyright (C) 2021: Nordix Foundation
+//   %%
+//   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.
+//   ========================LICENSE_END===================================
+//  /
+//
+
 import { Component, Input, OnInit } from '@angular/core';
 import { AbstractControl, ControlContainer, FormBuilder, FormControl, FormGroup, FormGroupDirective, Validators } from '@angular/forms';
 import { Ric, Rics } from 'src/app/interfaces/ric';