Add data type view/workspace
[sdc.git] / catalog-ui / src / app / ng2 / pages / type-workspace / type-workspace.component.spec.ts
1 /*
2  * -
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
9  *
10  *       http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 import {async, ComponentFixture, TestBed} from '@angular/core/testing';
23
24 import {TypeWorkspaceComponent} from './type-workspace.component';
25 import {ReactiveFormsModule} from "@angular/forms";
26 import {TranslateModule} from "../../shared/translator/translate.module";
27 import {UiElementsModule} from "../../components/ui/ui-elements.module";
28 import {DataTypeService} from "../../services/data-type.service";
29 import {TranslateService} from "../../shared/translator/translate.service";
30 import {WorkspaceMenuComponent} from "./workspace-menu/workspace-menu.component";
31 import {TypeWorkspaceGeneralComponent} from "./type-workspace-general/type-workspace-general.component";
32 import {LayoutModule} from "../../components/layout/layout.module";
33 import {CacheService} from "../../services/cache.service";
34 import {IAppMenu, SdcMenuToken} from "../../config/sdc-menu.config";
35 import {AuthenticationService} from "../../services/authentication.service";
36 import {ISdcConfig, SdcConfigToken} from "../../config/sdc-config.config";
37 import {States} from "../../../utils/constants";
38 import {IUserProperties} from "../../../models/user";
39 import {Observable} from "rxjs/Observable";
40
41 describe('TypeWorkspaceComponent', () => {
42   let component: TypeWorkspaceComponent;
43   let fixture: ComponentFixture<TypeWorkspaceComponent>;
44   let translateServiceMock: Partial<TranslateService> = {
45     'languageChangedObservable': Observable.of(),
46     'translate': jest.fn()
47   };
48   let dataTypeServiceMock: Partial<DataTypeService>;
49   let cacheService: Partial<CacheService> = {
50     'get': jest.fn(param => {
51       if (param === 'version') {
52         return 'version';
53       }
54       if (param === 'user') {
55         return {};
56       }
57     })
58   };
59   let stateMock: Partial<ng.ui.IStateService> = {
60     'current': {
61       'name': States.TYPE_WORKSPACE
62     }
63   };
64   let stateParamsMock: Partial<ng.ui.IStateParamsService> = {};
65   let injectorMock: Partial<ng.auto.IInjectorService> = {
66     'get': jest.fn(param => {
67       if (param === '$state') {
68         return stateMock;
69       }
70     })
71   };
72   let sdcMenuMock: Partial<IAppMenu> = {
73     'component_workspace_menu_option': {
74       "DataType": [
75           {"text": "General", "action": "onMenuItemPressed", "state": "general"}
76       ]
77     }
78   };
79   let sdcConfigMock: Partial<ISdcConfig>;
80   let user: Partial<IUserProperties> = {
81     'role': 'DESIGNER'
82   }
83   let authenticationService: Partial<AuthenticationService> = {
84     'getLoggedinUser': jest.fn(() => {
85       return user;
86     })
87   };
88
89   beforeEach(async(() => {
90     TestBed.configureTestingModule({
91       declarations: [ TypeWorkspaceComponent, WorkspaceMenuComponent, TypeWorkspaceGeneralComponent ],
92       imports: [
93         ReactiveFormsModule,
94         TranslateModule,
95         UiElementsModule,
96         LayoutModule
97       ],
98       providers: [
99         {provide: DataTypeService, useValue: dataTypeServiceMock},
100         {provide: TranslateService, useValue: translateServiceMock},
101         {provide: CacheService, useValue: cacheService},
102         {provide: '$state', useValue: stateMock},
103         {provide: '$stateParams', useValue: stateParamsMock},
104         {provide: '$injector', useValue: injectorMock},
105         {provide: SdcMenuToken, useValue: sdcMenuMock},
106         {provide: SdcConfigToken, useValue: sdcConfigMock},
107         {provide: AuthenticationService, useValue: authenticationService},
108       ]
109     })
110     .compileComponents();
111   }));
112
113   beforeEach(() => {
114     fixture = TestBed.createComponent(TypeWorkspaceComponent);
115     component = fixture.componentInstance;
116     fixture.detectChanges();
117   });
118
119   it('should create', () => {
120     expect(component).toBeTruthy();
121   });
122 });