1 import { HarnessLoader } from '@angular/cdk/testing';
2 import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
3 import { Component, ViewChild } from '@angular/core';
4 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
5 import { FormBuilder, FormGroup } from '@angular/forms';
6 import { MatButtonModule } from '@angular/material/button';
7 import { MatButtonHarness } from '@angular/material/button/testing';
8 import { MatInput, MatInputModule } from '@angular/material/input';
9 import { MatInputHarness } from '@angular/material/input/testing';
10 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
12 import { NoTypePolicyEditorComponent } from './no-type-policy-editor.component';
14 let formGroup: FormGroup = new FormGroup({});
16 describe('NoTypePolicyEditorComponent', () => {
17 let component: TestNoTypePolicyEditorComponentHostComponent;
18 let fixture: ComponentFixture<TestNoTypePolicyEditorComponentHostComponent>;
19 let loader: HarnessLoader;
21 beforeEach(async(() => {
22 TestBed.configureTestingModule({
24 BrowserAnimationsModule,
29 NoTypePolicyEditorComponent,
30 TestNoTypePolicyEditorComponentHostComponent
38 fixture = TestBed.createComponent(TestNoTypePolicyEditorComponentHostComponent);
39 component = fixture.componentInstance;
40 fixture.detectChanges();
41 loader = TestbedHarnessEnvironment.loader(fixture);
44 it('should create', () => {
45 expect(component).toBeTruthy();
48 it('should be added to form group with required validator', async () => {
49 let textArea: MatInputHarness = await loader.getHarness(MatInputHarness.with({ selector: '#policyJsonTextArea' }));
51 expect(formGroup.get('policyJsonTextArea')).toBeTruthy();
52 expect(await textArea.isRequired()).toBeTruthy();
55 it('should contain provided policy json and enabled Format button', async () => {
56 let textArea: MatInputHarness = await loader.getHarness(MatInputHarness.with({ selector: '#policyJsonTextArea' }));
57 expect(await textArea.getValue()).toEqual('{"A":"A"}');
59 console.log('Validity:',formGroup.valid);
60 let formatButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({ selector: '#formatButton' }));
61 expect(await formatButton.isDisabled()).toBeFalsy();
64 it('Format button should be disabled wen json not valid', async () => {
65 let textArea: MatInputHarness = await loader.getHarness(MatInputHarness.with({ selector: '#policyJsonTextArea' }));
66 await textArea.setValue('{');
68 let formatButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({ selector: '#formatButton' }));
69 // expect(await formatButton.isDisabled()).toBeTruthy();
74 selector: `no-type-policy-editor-host-component`,
75 template: `<nrcp-no-type-policy-editor [policyJson]="this.policyJson" [instanceForm]="instanceForm"></nrcp-no-type-policy-editor>`
77 export class TestNoTypePolicyEditorComponentHostComponent {
78 @ViewChild(NoTypePolicyEditorComponent)
79 private noTypePolicyEditorComponentHostComponent: NoTypePolicyEditorComponent;
80 instanceForm: FormGroup = formGroup;
81 policyJson: string = '{"A":"A"}';