summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app')
-rw-r--r--catalog-ui/src/app/ng2/app.component.spec.ts49
-rw-r--r--catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.spec.ts104
-rw-r--r--catalog-ui/src/app/ng2/pipes/entity-filter.pipe.spec.ts212
-rw-r--r--catalog-ui/src/app/ng2/pipes/entity-filter.pipe.ts338
-rw-r--r--catalog-ui/src/app/ng2/utils/ng1-upgraded-provider.spec.ts89
-rw-r--r--catalog-ui/src/app/ng2/utils/queue-service-utils.spec.ts60
6 files changed, 684 insertions, 168 deletions
diff --git a/catalog-ui/src/app/ng2/app.component.spec.ts b/catalog-ui/src/app/ng2/app.component.spec.ts
new file mode 100644
index 0000000000..0d8e3ab1c3
--- /dev/null
+++ b/catalog-ui/src/app/ng2/app.component.spec.ts
@@ -0,0 +1,49 @@
+/*
+* ============LICENSE_START=======================================================
+* SDC
+* ================================================================================
+* Copyright (C) 2022 Nordix Foundation. All rights reserved.
+* ================================================================================
+* 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.
+*
+* SPDX-License-Identifier: Apache-2.0
+* ============LICENSE_END=========================================================
+*/
+
+import { NO_ERRORS_SCHEMA, ViewContainerRef } from "@angular/core";
+import { async, TestBed } from "@angular/core/testing";
+import { AuthenticationService } from './services/authentication.service';
+import { AppComponent } from './app.component'
+
+describe('AppComponent', () => {
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ imports: [],
+ schemas: [NO_ERRORS_SCHEMA],
+ declarations: [
+ AppComponent
+ ],
+ providers: [
+ { provide: AuthenticationService },
+ { provide: ViewContainerRef }
+ ],
+ }).compileComponents();
+ }));
+
+ it('should create the app', () => {
+ const fixture = TestBed.createComponent(AppComponent);
+ const app = fixture.debugElement.componentInstance;
+ expect(app).toBeTruthy();
+ });
+
+});
diff --git a/catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.spec.ts b/catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.spec.ts
new file mode 100644
index 0000000000..570ff38174
--- /dev/null
+++ b/catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.spec.ts
@@ -0,0 +1,104 @@
+/*
+* ============LICENSE_START=======================================================
+* SDC
+* ================================================================================
+* Copyright (C) 2022 Nordix Foundation. All rights reserved.
+* ================================================================================
+* 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.
+*
+* SPDX-License-Identifier: Apache-2.0
+* ============LICENSE_END=========================================================
+*/
+
+import { async, TestBed } from "@angular/core/testing";
+import { ConfigureFn, configureTests } from "../../../jest/test-config.helper";
+import { NO_ERRORS_SCHEMA } from "@angular/core";
+import { HeadersInterceptor } from './headers-interceptor';
+import { SdcConfigToken } from "../config/sdc-config.config";
+import { Injector } from '@angular/core';
+import { of } from 'rxjs';
+import { TranslateService } from '../shared/translator/translate.service';
+import { Cookie2Service } from '../services/cookie.service';
+import { HttpHelperService } from '../services/http-hepler.service';
+import { HttpErrorResponse, HttpEvent, HttpResponse, HttpRequest } from '@angular/common/http';
+import { ModelService } from "../services/model.service";
+
+describe('HeadersInterceptor service', () => {
+
+ let headerService: HeadersInterceptor;
+ let cookieServiceMock: Partial<Cookie2Service>;
+ let httpServiceMock: Partial<HttpHelperService>;
+
+ beforeEach(
+ async(() => {
+ cookieServiceMock = {
+ getCookieByName: jest.fn(),
+ getUserIdSuffix: jest.fn().mockImplementation(() => 'urlSuffix'),
+ getUserId: jest.fn().mockImplementation(() => '009'),
+ getFirstName: jest.fn().mockImplementation(() => 'First Name'),
+ getLastName: jest.fn().mockImplementation(() => 'Last Name'),
+ getEmail: jest.fn().mockImplementation(() => 'names@test.com'),
+ };
+ httpServiceMock = {
+ getUuidValue: jest.fn().mockImplementation(() => '001'),
+ replaceUrlParams: jest.fn(),
+ getHeaderMd5: jest.fn()
+ };
+
+ const configure: ConfigureFn = testBed => {
+ testBed.configureTestingModule({
+ declarations: [],
+ imports: [],
+ schemas: [NO_ERRORS_SCHEMA],
+ providers: [HeadersInterceptor,
+ { provide: SdcConfigToken },
+ { provide: Injector },
+ { provide: Cookie2Service, useValue: cookieServiceMock },
+ { provide: HttpHelperService, useValue: httpServiceMock },
+ { provide: TranslateService },
+ { provide: ModelService }
+ ],
+ });
+ };
+ configureTests(configure).then(testBed => {
+ headerService = TestBed.get(HeadersInterceptor);
+ });
+ })
+ );
+
+ it('HeadersInterceptor should be created', () => {
+ expect(headerService).toBeTruthy();
+ });
+
+ it('should set correct request headers', done => {
+ const mockHandler = {
+ handle: jest.fn(() => of(
+ new HttpResponse({ status: 200 })))
+ };
+ of(headerService.intercept(new HttpRequest<any>('GET', '/test'), mockHandler)).subscribe(response => {
+ expect(response).toBeTruthy();
+ done();
+ });
+ });
+
+ it('should throw 500 error with correct message', done => {
+ const mockHandler = {
+ handle: jest.fn(() => of(
+ new HttpErrorResponse({ status: 500, error: 'This is a error' })))
+ };
+ of(headerService.intercept(new HttpRequest<any>('GET', '/test'), mockHandler)).subscribe(error => {
+ expect(error.source.value.name).toBe('HttpErrorResponse');
+ expect(error.source.value.status).toBe(500);
+ done();
+ });
+ });
+});
diff --git a/catalog-ui/src/app/ng2/pipes/entity-filter.pipe.spec.ts b/catalog-ui/src/app/ng2/pipes/entity-filter.pipe.spec.ts
new file mode 100644
index 0000000000..6e0a79bbed
--- /dev/null
+++ b/catalog-ui/src/app/ng2/pipes/entity-filter.pipe.spec.ts
@@ -0,0 +1,212 @@
+/*
+* ============LICENSE_START=======================================================
+* SDC
+* ================================================================================
+* Copyright (C) 2022 Nordix Foundation. All rights reserved.
+* ================================================================================
+* 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.
+*
+* SPDX-License-Identifier: Apache-2.0
+* ============LICENSE_END=========================================================
+*/
+
+import { TestBed } from "@angular/core/testing";
+import { EntityFilterPipe } from './entity-filter.pipe';
+import { IEntityFilterObject } from './entity-filter.pipe';
+import { Component } from "app/models";
+import { ISearchFilter } from './entity-filter.pipe';
+
+describe('EntityFilterPipe', () => {
+ let entityFilterPipe: EntityFilterPipe;
+ let entityFilterMock: Partial<IEntityFilterObject>;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ imports: [],
+ providers: [EntityFilterPipe],
+ });
+ entityFilterPipe = TestBed.get(EntityFilterPipe);
+ });
+
+ it('EntityFilterPipe should be created', () => {
+ expect(entityFilterPipe).toBeTruthy();
+ });
+
+ it('Transform method should filter objects by type matching with selectedComponentTypes', () => {
+ let componentList: Array<Component> = [];
+
+ const mockComponent = {
+ componentType: 'testtype',
+ isResource: jest.fn().mockImplementation(() => false)
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent);
+
+ const mockComponent1 = {
+ componentType: 'newtesttype',
+ isResource: jest.fn().mockImplementation(() => false)
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent1);
+
+ const mockComponent2 = {
+ componentType: 'newtesttype',
+ isResource: jest.fn().mockImplementation(() => true),
+ getComponentSubType: jest.fn().mockImplementation(() => 'subComponent')
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent2);
+
+ entityFilterMock = {
+ selectedComponentTypes: ['Testtype', 'Testtype1'],
+ selectedResourceSubTypes: ['subComponent']
+ };
+ let response: Array<Component> = entityFilterPipe.transform(componentList, entityFilterMock);
+ expect(response).toHaveLength(2);
+ expect(response[0]).toEqual(mockComponent);
+ expect(response[1]).toEqual(mockComponent2);
+ });
+
+ it('Transform method should filter objects by categories & subcategories matching with selectedCategoriesModel', () => {
+ let componentList: Array<Component> = [];
+ const mockComponent = {
+ componentType: 'newtesttype',
+ categoryNormalizedName: 'categoryname',
+ subCategoryNormalizedName: 'subcategoryname',
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent);
+
+ const mockComponent1 = {
+ componentType: 'newtesttype',
+ categoryNormalizedName: 'name',
+ subCategoryNormalizedName: 'subname',
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent1);
+
+ const mockComponent2 = {
+ componentType: 'RESOURCE',
+ categoryNormalizedName: 'name'
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent2);
+
+ const mockComponent3 = {
+ componentType: 'SERVICE',
+ categoryNormalizedName: 'name'
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent3);
+
+ entityFilterMock = {
+ selectedCategoriesModel: ['categoryname.subcategoryname', 'resourceNewCategory.name', 'serviceNewCategory.name']
+ };
+ let response: Array<Component> = entityFilterPipe.transform(componentList, entityFilterMock);
+ expect(response).toHaveLength(3);
+ expect(response[0]).toEqual(mockComponent);
+ expect(response[1]).toEqual(mockComponent2);
+ expect(response[2]).toEqual(mockComponent3);
+ });
+
+ it('Transform method should filter objects by statuses matching with selectedStatuses', () => {
+ let componentList: Array<Component> = [];
+ const mockComponent = {
+ lifecycleState: 'lifecyclestatus'
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent);
+
+ const mockComponent1 = {
+ lifecycleState: 'lifecycleteststatus'
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent1);
+
+ const mockComponent2 = {
+ lifecycleState: 'CERTIFIED',
+ distributionStatus: 'DISTRIBUTED'
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent2);
+
+ entityFilterMock = {
+ selectedStatuses: ['lifecyclestatus', 'DISTRIBUTED']
+ };
+ let response: Array<Component> = entityFilterPipe.transform(componentList, entityFilterMock);
+ expect(response).toHaveLength(2);
+ expect(response[0]).toEqual(mockComponent);
+ expect(response[1]).toEqual(mockComponent2);
+ });
+
+ it('Transform method should filter objects by statuses and distributed matching with selected distributed', () => {
+ let componentList: Array<Component> = [];
+ const mockComponent = {
+ distributionStatus: 'diststatus'
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent);
+
+ const mockComponent1 = {
+ distributionStatus: 'testdiststatus'
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent1);
+
+ entityFilterMock = {
+ distributed: ['diststatus', 'localstatus']
+ };
+ let response: Array<Component> = entityFilterPipe.transform(componentList, entityFilterMock);
+ expect(response).toHaveLength(1);
+ expect(response[0]).toEqual(mockComponent);
+ });
+
+ it('Transform method should filter objects by model matching with selectedModels', () => {
+ let componentList: Array<Component> = [];
+ const mockComponent = {
+ model: 'testModel'
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent);
+
+ const mockComponent1 = {
+ model: 'testModelNegative'
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent1);
+
+ const mockComponent2 = {
+ distributionStatus: 'testdiststatus'
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent2);
+
+ entityFilterMock = {
+ selectedModels: ['testModel', 'localTest', 'SDC AID']
+ };
+ let response: Array<Component> = entityFilterPipe.transform(componentList, entityFilterMock);
+ expect(response).toHaveLength(2);
+ expect(response[0]).toEqual(mockComponent);
+ expect(response[1]).toEqual(mockComponent2);
+ });
+
+ it('Transform method should filter objects by custom search matching with given keys', () => {
+ let componentList: Array<Component> = [];
+ const mockComponent = {
+ distributionStatus: 'distributionStatus',
+ model: 'testModel'
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent);
+
+ const mockComponent1 = {
+ distributionStatus: 'testDiststatus',
+ model: 'mockModel'
+ } as Partial<Component> as Component;
+ componentList.push(mockComponent1);
+
+ const searchFilter: ISearchFilter = {
+ distributionStatus: 'distributionStatus'
+ }
+ entityFilterMock = {
+ search: searchFilter
+ };
+ let response: Array<Component> = entityFilterPipe.transform(componentList, entityFilterMock);
+ expect(response).toHaveLength(1);
+ expect(response[0]).toEqual(mockComponent);
+ });
+
+});
diff --git a/catalog-ui/src/app/ng2/pipes/entity-filter.pipe.ts b/catalog-ui/src/app/ng2/pipes/entity-filter.pipe.ts
index 29b21cb6da..e1b95212e4 100644
--- a/catalog-ui/src/app/ng2/pipes/entity-filter.pipe.ts
+++ b/catalog-ui/src/app/ng2/pipes/entity-filter.pipe.ts
@@ -1,168 +1,170 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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 {Pipe, PipeTransform} from "@angular/core";
-import {Component, Resource} from "app/models";
-import {ComponentType, DEFAULT_MODEL_NAME} from "app/utils/constants";
-
-export interface ISearchFilter {
- [key:string]: string;
-}
-
-export interface IEntityFilterObject {
- // Types
- selectedComponentTypes?:Array<string>;
- selectedResourceSubTypes?:Array<string>;
- // Categories
- selectedCategoriesModel?:Array<string>;
- // Statuses
- selectedStatuses?:Array<string>;
- // Models
- selectedModels?:Array<string>;
- // distributed
- distributed?:Array<string>;
- // search
- search?:ISearchFilter;
-
-}
-
-@Pipe({name: 'entity-filter'})
-export class EntityFilterPipe implements PipeTransform{
- constructor() {
- }
-
- public static transform(components:Array<Component>, filter:IEntityFilterObject) {
- let filteredComponents:Array<Component> = components;
-
- // filter by type
- // --------------------------------------------------------------------------
- if ((filter.selectedComponentTypes && filter.selectedComponentTypes.length > 0) || (filter.selectedResourceSubTypes && filter.selectedResourceSubTypes.length > 0)) {
- let filteredTypes = [];
- angular.forEach(components, (component:Component):void => {
- // Filter by component type
- let typeLower:string = component.componentType.toLowerCase();
- let typeFirstCapital:string = typeLower.charAt(0).toUpperCase() + typeLower.slice(1);
- if (filter.selectedComponentTypes.indexOf(typeFirstCapital) !== -1) {
- filteredTypes.push(component);
- }
-
- // Filter by resource sub type, only in case the resource checkbox was not selected (because in this case we already added all the components in above section).
- if (component.isResource() && filter.selectedComponentTypes.indexOf("Resource") === -1 && filter.selectedResourceSubTypes.length > 0) {
- //filteredComponents.pop(); // Remove the last inserted component.
- let resource:Resource = <Resource>component;
- if (filter.selectedResourceSubTypes.indexOf(resource.getComponentSubType()) !== -1) {
- filteredTypes.push(component);
- }
- }
- });
- filteredComponents = filteredTypes;
- }
-
- // filter by categories & subcategories & groupings
- // --------------------------------------------------------------------------
- if (filter.selectedCategoriesModel && filter.selectedCategoriesModel.length > 0) {
- let filteredCategories = [];
- angular.forEach(filteredComponents, (component:Component):void => {
- let componentCategory = component.categoryNormalizedName +
- ((component.subCategoryNormalizedName) ? '.' + component.subCategoryNormalizedName : '');
- if (component.componentType === ComponentType.RESOURCE) {
- componentCategory = 'resourceNewCategory.' + componentCategory;
- } else if (component.componentType === ComponentType.SERVICE) {
- componentCategory = 'serviceNewCategory.' + componentCategory;
- }
- if (filter.selectedCategoriesModel.indexOf(componentCategory) !== -1) {
- filteredCategories.push(component);
- }
- });
- filteredComponents = filteredCategories;
- }
-
- // filter by statuses
- // --------------------------------------------------------------------------
- if (filter.selectedStatuses && filter.selectedStatuses.length > 0) {
-
- let filteredStatuses = [];
- angular.forEach(filteredComponents, (component:Component):void => {
- if (filter.selectedStatuses.indexOf(component.lifecycleState) > -1) {
- filteredStatuses.push(component);
- }
- //if status DISTRIBUTED && CERTIFIED are selected the component will added in CERTIFIED status , not need to add twice
- if (filter.selectedStatuses.indexOf('DISTRIBUTED') > -1 && !(filter.selectedStatuses.indexOf('CERTIFIED') > -1)) {
- if (component.distributionStatus && component.distributionStatus.indexOf('DISTRIBUTED') > -1 && component.lifecycleState.indexOf('CERTIFIED') > -1) {
- filteredStatuses.push(component);
- }
- }
- });
- filteredComponents = filteredStatuses;
- }
-
- // filter by statuses and distributed
- // --------------------------------------------------------------------------
- if (filter.distributed != undefined && filter.distributed.length > 0) {
- let filterDistributed:Array<any> = filter.distributed;
- let filteredDistributed = [];
- angular.forEach(filteredComponents, (entity) => {
- filterDistributed.forEach((distribute) => {
- let distributeItem = distribute.split(',');
- distributeItem.forEach((item) => {
- if (item !== undefined && entity.distributionStatus === item) {
- filteredDistributed.push(entity);
- }
- })
- });
- });
- filteredComponents = filteredDistributed;
- }
-
- // filter by model
- // --------------------------------------------------------------------------
- if (filter.selectedModels && filter.selectedModels.length > 0) {
- let filteredModels = [];
- let allSelectedModels = [].concat.apply([], filter.selectedModels);
- angular.forEach(filteredComponents, (component:Component):void => {
- if (component.model && allSelectedModels.indexOf(component.model) > -1) {
- filteredModels.push(component);
- } else if (!component.model && allSelectedModels.indexOf(DEFAULT_MODEL_NAME) > -1) {
- filteredModels.push(component);
- }
- });
- filteredComponents = filteredModels;
- }
-
- // filter by search
- // --------------------------------------------------------------------------
- if (filter.search != undefined) {
- Object.keys(filter.search).forEach((searchKey) => {
- let searchVal = filter.search[searchKey];
- if (searchVal) {
- searchVal = searchVal.toLowerCase();
- filteredComponents = filteredComponents.filter((component:Component) =>
- component[searchKey].toLowerCase().indexOf(searchVal) !== -1);
- }
- });
- }
-
- return filteredComponents;
- }
-
- public transform(components:Array<Component>, filter:IEntityFilterObject) {
- return EntityFilterPipe.transform(components, filter);
- }
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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 {Pipe, PipeTransform} from "@angular/core";
+import {Component, Resource} from "app/models";
+import {ComponentType, DEFAULT_MODEL_NAME} from "app/utils/constants";
+
+export interface ISearchFilter {
+ [key:string]: string;
+}
+
+const angular = require('angular');
+
+export interface IEntityFilterObject {
+ // Types
+ selectedComponentTypes?:Array<string>;
+ selectedResourceSubTypes?:Array<string>;
+ // Categories
+ selectedCategoriesModel?:Array<string>;
+ // Statuses
+ selectedStatuses?:Array<string>;
+ // Models
+ selectedModels?:Array<string>;
+ // distributed
+ distributed?:Array<string>;
+ // search
+ search?:ISearchFilter;
+
+}
+
+@Pipe({name: 'entity-filter'})
+export class EntityFilterPipe implements PipeTransform{
+ constructor() {
+ }
+
+ public static transform(components:Array<Component>, filter:IEntityFilterObject) {
+ let filteredComponents:Array<Component> = components;
+
+ // filter by type
+ // --------------------------------------------------------------------------
+ if ((filter.selectedComponentTypes && filter.selectedComponentTypes.length > 0) || (filter.selectedResourceSubTypes && filter.selectedResourceSubTypes.length > 0)) {
+ let filteredTypes = [];
+ angular.forEach(components, (component:Component):void => {
+ // Filter by component type
+ let typeLower:string = component.componentType.toLowerCase();
+ let typeFirstCapital:string = typeLower.charAt(0).toUpperCase() + typeLower.slice(1);
+ if (filter.selectedComponentTypes.indexOf(typeFirstCapital) !== -1) {
+ filteredTypes.push(component);
+ }
+
+ // Filter by resource sub type, only in case the resource checkbox was not selected (because in this case we already added all the components in above section).
+ if (component.isResource() && filter.selectedComponentTypes.indexOf("Resource") === -1 && filter.selectedResourceSubTypes.length > 0) {
+ //filteredComponents.pop(); // Remove the last inserted component.
+ let resource:Resource = <Resource>component;
+ if (filter.selectedResourceSubTypes.indexOf(resource.getComponentSubType()) !== -1) {
+ filteredTypes.push(component);
+ }
+ }
+ });
+ filteredComponents = filteredTypes;
+ }
+
+ // filter by categories & subcategories & groupings
+ // --------------------------------------------------------------------------
+ if (filter.selectedCategoriesModel && filter.selectedCategoriesModel.length > 0) {
+ let filteredCategories = [];
+ angular.forEach(filteredComponents, (component:Component):void => {
+ let componentCategory = component.categoryNormalizedName +
+ ((component.subCategoryNormalizedName) ? '.' + component.subCategoryNormalizedName : '');
+ if (component.componentType === ComponentType.RESOURCE) {
+ componentCategory = 'resourceNewCategory.' + componentCategory;
+ } else if (component.componentType === ComponentType.SERVICE) {
+ componentCategory = 'serviceNewCategory.' + componentCategory;
+ }
+ if (filter.selectedCategoriesModel.indexOf(componentCategory) !== -1) {
+ filteredCategories.push(component);
+ }
+ });
+ filteredComponents = filteredCategories;
+ }
+
+ // filter by statuses
+ // --------------------------------------------------------------------------
+ if (filter.selectedStatuses && filter.selectedStatuses.length > 0) {
+
+ let filteredStatuses = [];
+ angular.forEach(filteredComponents, (component:Component):void => {
+ if (filter.selectedStatuses.indexOf(component.lifecycleState) > -1) {
+ filteredStatuses.push(component);
+ }
+ //if status DISTRIBUTED && CERTIFIED are selected the component will added in CERTIFIED status , not need to add twice
+ if (filter.selectedStatuses.indexOf('DISTRIBUTED') > -1 && !(filter.selectedStatuses.indexOf('CERTIFIED') > -1)) {
+ if (component.distributionStatus && component.distributionStatus.indexOf('DISTRIBUTED') > -1 && component.lifecycleState.indexOf('CERTIFIED') > -1) {
+ filteredStatuses.push(component);
+ }
+ }
+ });
+ filteredComponents = filteredStatuses;
+ }
+
+ // filter by statuses and distributed
+ // --------------------------------------------------------------------------
+ if (filter.distributed != undefined && filter.distributed.length > 0) {
+ let filterDistributed:Array<any> = filter.distributed;
+ let filteredDistributed = [];
+ angular.forEach(filteredComponents, (entity) => {
+ filterDistributed.forEach((distribute) => {
+ let distributeItem = distribute.split(',');
+ distributeItem.forEach((item) => {
+ if (item !== undefined && entity.distributionStatus === item) {
+ filteredDistributed.push(entity);
+ }
+ })
+ });
+ });
+ filteredComponents = filteredDistributed;
+ }
+
+ // filter by model
+ // --------------------------------------------------------------------------
+ if (filter.selectedModels && filter.selectedModels.length > 0) {
+ let filteredModels = [];
+ let allSelectedModels = [].concat.apply([], filter.selectedModels);
+ angular.forEach(filteredComponents, (component:Component):void => {
+ if (component.model && allSelectedModels.indexOf(component.model) > -1) {
+ filteredModels.push(component);
+ } else if (!component.model && allSelectedModels.indexOf(DEFAULT_MODEL_NAME) > -1) {
+ filteredModels.push(component);
+ }
+ });
+ filteredComponents = filteredModels;
+ }
+
+ // filter by search
+ // --------------------------------------------------------------------------
+ if (filter.search != undefined) {
+ Object.keys(filter.search).forEach((searchKey) => {
+ let searchVal = filter.search[searchKey];
+ if (searchVal) {
+ searchVal = searchVal.toLowerCase();
+ filteredComponents = filteredComponents.filter((component:Component) =>
+ component[searchKey].toLowerCase().indexOf(searchVal) !== -1);
+ }
+ });
+ }
+
+ return filteredComponents;
+ }
+
+ public transform(components:Array<Component>, filter:IEntityFilterObject) {
+ return EntityFilterPipe.transform(components, filter);
+ }
+}
diff --git a/catalog-ui/src/app/ng2/utils/ng1-upgraded-provider.spec.ts b/catalog-ui/src/app/ng2/utils/ng1-upgraded-provider.spec.ts
new file mode 100644
index 0000000000..92d5f2526d
--- /dev/null
+++ b/catalog-ui/src/app/ng2/utils/ng1-upgraded-provider.spec.ts
@@ -0,0 +1,89 @@
+/*
+* ============LICENSE_START=======================================================
+* SDC
+* ================================================================================
+* Copyright (C) 2022 Nordix Foundation. All rights reserved.
+* ================================================================================
+* 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.
+*
+* SPDX-License-Identifier: Apache-2.0
+* ============LICENSE_END=========================================================
+*/
+
+import { async } from "@angular/core/testing";
+
+const Utils = require('./ng1-upgraded-provider');
+
+describe('ng1-upgraded-provider', () => {
+
+ let cacheObjMock: Partial<angular.ICacheObject>;
+ beforeEach(
+ async(() => {
+ const responseData = {
+ 'Sdc.Services.DataTypesService': 'dataTypesService',
+ 'Sdc.Services.SharingService': 'sharingService',
+ 'Sdc.Services.ComponentFactory': 'componentFactory',
+ 'Sdc.Services.CookieService': 'cookieService',
+ '$state': 'state',
+ '$stateParams': 'stateParams',
+ '$scope': 'scope',
+ 'EventListenerService': 'eventListenerService',
+ 'Notification': 'notification',
+ 'ModalsHandler': 'modalsHandler'
+ };
+ cacheObjMock = {
+ get: jest.fn().mockImplementation((input: string) => responseData[input])
+ };
+ })
+ );
+
+ it('should return dataTypesService', () => {
+ expect(Utils.dataTypesServiceFactory(cacheObjMock)).toEqual('dataTypesService');
+ });
+
+ it('should return sharingService', () => {
+ expect(Utils.sharingServiceFactory(cacheObjMock)).toEqual('sharingService');
+ });
+
+ it('should return componentFactory', () => {
+ expect(Utils.componentServiceFactory(cacheObjMock)).toEqual('componentFactory');
+ });
+
+ it('should return cookieService', () => {
+ expect(Utils.cookieServiceFactory(cacheObjMock)).toEqual('cookieService');
+ });
+
+ it('should return state', () => {
+ expect(Utils.stateServiceFactory(cacheObjMock)).toEqual('state');
+ });
+
+ it('should return stateParams', () => {
+ expect(Utils.stateParamsServiceFactory(cacheObjMock)).toEqual('stateParams');
+ });
+
+ it('should return scope', () => {
+ expect(Utils.scopeServiceFactory(cacheObjMock)).toEqual('scope');
+ });
+
+ it('should return eventListenerService', () => {
+ expect(Utils.eventListenerServiceServiceFactory(cacheObjMock)).toEqual('eventListenerService');
+ });
+
+ it('should return notification service', () => {
+ expect(Utils.notificationServiceFactory(cacheObjMock)).toEqual('notification');
+ });
+
+ it('should return modalsHandler', () => {
+ expect(Utils.ModalsHandlerFactory(cacheObjMock)).toEqual('modalsHandler');
+ });
+
+});
diff --git a/catalog-ui/src/app/ng2/utils/queue-service-utils.spec.ts b/catalog-ui/src/app/ng2/utils/queue-service-utils.spec.ts
new file mode 100644
index 0000000000..fab046044f
--- /dev/null
+++ b/catalog-ui/src/app/ng2/utils/queue-service-utils.spec.ts
@@ -0,0 +1,60 @@
+/*
+* ============LICENSE_START=======================================================
+* SDC
+* ================================================================================
+* Copyright (C) 2022 Nordix Foundation. All rights reserved.
+* ================================================================================
+* 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.
+*
+* SPDX-License-Identifier: Apache-2.0
+* ============LICENSE_END=========================================================
+*/
+
+import { TestBed } from '@angular/core/testing';
+import { QueueServiceUtils } from './queue-service-utils'
+
+describe('QueueServiceUtils', () => {
+ let service: QueueServiceUtils;
+ let updateMock;
+ let updateParamMock;
+ let updateFunctMock;
+
+ beforeEach(() => {
+ updateMock = jest.fn();
+ updateParamMock = jest.fn();
+ updateFunctMock = jest.fn();
+ TestBed.configureTestingModule({
+ imports: [],
+ providers: [QueueServiceUtils],
+ });
+ service = TestBed.get(QueueServiceUtils);
+ });
+
+ it('QueueServiceUtils should be created', () => {
+ expect(service).toBeTruthy();
+ });
+
+ it('function should be executed when added to queue using addNonBlockingUIAction', (doneCallback) => {
+ jest.setTimeout(1000);
+ service.addNonBlockingUIAction(() => {
+ doneCallback();
+ });
+ });
+
+ it('function should be executed when added to queue using addBlockingUIAction', (doneCallback) => {
+ jest.setTimeout(1000);
+ service.addBlockingUIAction(() => {
+ doneCallback();
+ });
+ });
+
+});