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";
33 import {ModalService} from "../../../services/modal.service";
35 describe('TypeWorkspacePropertiesComponent', () => {
36 const messages = require("../../../../../assets/languages/en_US.json");
37 let modalService: Partial<ModalService> = {};
38 let testHostComponent: TestHostComponent;
39 let testHostFixture: ComponentFixture<TestHostComponent>;
40 let dataTypeServiceMock: Partial<DataTypeService> = {
41 findAllProperties: jest.fn( (dataTypeId) => {
42 if (dataTypeId === 'dataTypeId') {
43 const property1 = new PropertyBEModel();
44 property1.name = 'property1'
45 property1.type = 'string'
46 return Observable.of([property1]);
48 return Observable.of([]);
52 let translateServiceMock: Partial<TranslateService> = {
53 'translate': jest.fn( (translateKey: string) => {
54 return messages[translateKey];
58 beforeEach(async(() => {
59 TestBed.configureTestingModule({
60 declarations: [TypeWorkspacePropertiesComponent, TestHostComponent],
66 {provide: DataTypeService, useValue: dataTypeServiceMock},
67 {provide: TranslateService, useValue: translateServiceMock},
68 {provide: ModalService, useValue: modalService}
75 testHostFixture = TestBed.createComponent(TestHostComponent);
76 testHostComponent = testHostFixture.componentInstance;
77 testHostFixture.detectChanges();
80 it('should create', () => {
81 expect(testHostComponent).toBeTruthy();
84 it('empty property list', () => {
85 const element = testHostFixture.nativeElement;
86 const div: HTMLDivElement = element.querySelector('.no-row-text');
87 expect(div.textContent).toContain(messages.PROPERTY_LIST_EMPTY_MESSAGE);
90 it('test property list', () => {
91 testHostFixture = TestBed.createComponent(TestHostComponent);
92 testHostComponent = testHostFixture.componentInstance;
93 const dataType = new DataTypeModel();
94 dataType.uniqueId = 'dataTypeId';
95 testHostComponent.typeWorkspacePropertiesComponent.dataType = dataType;
96 testHostFixture.detectChanges();
98 const element = testHostFixture.nativeElement;
99 expect(element.querySelector('.no-row-text')).toBeFalsy();
100 const expectedPropertyName = 'property1';
101 const propertyNameLink: HTMLAnchorElement = element.querySelector(`a[data-tests-id^="property-name-${expectedPropertyName}"]`);
102 expect(propertyNameLink.textContent).toContain(expectedPropertyName);
106 selector: 'host-component',
107 template: `<app-type-workspace-properties></app-type-workspace-properties>`
109 class TestHostComponent {
110 @ViewChild(TypeWorkspacePropertiesComponent)
111 public typeWorkspacePropertiesComponent: TypeWorkspacePropertiesComponent;