3 * ============LICENSE_START=======================================================
4 * Copyright (C) 2022 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 import {async, ComponentFixture, TestBed} from '@angular/core/testing';
24 import {TypeWorkspacePropertiesComponent} from './type-workspace-properties.component';
25 import {FormsModule} from "@angular/forms";
26 import {TranslateModule} from "../../../shared/translator/translate.module";
27 import {TranslateService} from "../../../shared/translator/translate.service";
28 import {DataTypeService} from "../../../services/data-type.service";
29 import {Observable} from "rxjs/Observable";
30 import {DataTypeModel} from "../../../../models/data-types";
31 import {Component, ViewChild} from "@angular/core";
32 import {PropertyBEModel} from "../../../../models/properties-inputs/property-be-model";
34 describe('TypeWorkspacePropertiesComponent', () => {
35 const messages = require("../../../../../assets/languages/en_US.json");
36 let testHostComponent: TestHostComponent;
37 let testHostFixture: ComponentFixture<TestHostComponent>;
38 let dataTypeServiceMock: Partial<DataTypeService> = {
39 findAllProperties: jest.fn( (dataTypeId) => {
40 if (dataTypeId === 'dataTypeId') {
41 const property1 = new PropertyBEModel();
42 property1.name = 'property1'
43 property1.type = 'string'
44 return Observable.of([property1]);
46 return Observable.of([]);
50 let translateServiceMock: Partial<TranslateService> = {
51 'translate': jest.fn( (translateKey: string) => {
52 return messages[translateKey];
56 beforeEach(async(() => {
57 TestBed.configureTestingModule({
58 declarations: [TypeWorkspacePropertiesComponent, TestHostComponent],
64 {provide: DataTypeService, useValue: dataTypeServiceMock},
65 {provide: TranslateService, useValue: translateServiceMock}
72 testHostFixture = TestBed.createComponent(TestHostComponent);
73 testHostComponent = testHostFixture.componentInstance;
74 testHostFixture.detectChanges();
77 it('should create', () => {
78 expect(testHostComponent).toBeTruthy();
81 it('empty property list', () => {
82 const element = testHostFixture.nativeElement;
83 const div: HTMLDivElement = element.querySelector('.no-row-text');
84 expect(div.textContent).toContain(messages.PROPERTY_LIST_EMPTY_MESSAGE);
87 it('test property list', () => {
88 testHostFixture = TestBed.createComponent(TestHostComponent);
89 testHostComponent = testHostFixture.componentInstance;
90 const dataType = new DataTypeModel();
91 dataType.uniqueId = 'dataTypeId';
92 testHostComponent.typeWorkspacePropertiesComponent.dataType = dataType;
93 testHostFixture.detectChanges();
95 const element = testHostFixture.nativeElement;
96 expect(element.querySelector('.no-row-text')).toBeFalsy();
97 const expectedPropertyName = 'property1';
98 const propertyNameLink: HTMLAnchorElement = element.querySelector(`a[data-tests-id^="property-name-${expectedPropertyName}"]`);
99 expect(propertyNameLink.textContent).toContain(expectedPropertyName);
103 selector: 'host-component',
104 template: `<app-type-workspace-properties></app-type-workspace-properties>`
106 class TestHostComponent {
107 @ViewChild(TypeWorkspacePropertiesComponent)
108 public typeWorkspacePropertiesComponent: TypeWorkspacePropertiesComponent;