diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts index 0ecc9c3bfb..7ec0975b08 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts @@ -33,7 +33,7 @@ import { TranslateModule } from '@ngx-translate/core'; import { SearchQueryBuilderService } from '../search'; import { mockQueryBody } from '../mock/search-query.mock'; import { ContentNodeSelectorPanelService } from './content-node-selector-panel.service'; -import { mockContentModelProperty } from '../mock/content-model.mock'; +import { mockContentModelTextProperty } from '../mock/content-model.mock'; const fakeResultSetPaging: ResultSetPaging = { list: { @@ -1179,7 +1179,7 @@ describe('ContentNodeSelectorPanelComponent', () => { }); it ('should search panel be collapsed by default and expand when clicking the filter button', async() => { - contentNodeSelectorPanelService.customModels = [mockContentModelProperty]; + contentNodeSelectorPanelService.customModels = [mockContentModelTextProperty]; fixture.detectChanges(); expect(component.searchPanelExpanded).toEqual(false); @@ -1203,7 +1203,7 @@ describe('ContentNodeSelectorPanelComponent', () => { }); it('should filter button be present only when there are custom models', () => { - contentNodeSelectorPanelService.customModels = [mockContentModelProperty]; + contentNodeSelectorPanelService.customModels = [mockContentModelTextProperty]; fixture.detectChanges(); const toggleFiltersPanelButton = fixture.debugElement.query(By.css('[data-automation-id="adf-toggle-search-panel-button"]')); diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.service.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.service.spec.ts new file mode 100644 index 0000000000..eb5d1cac27 --- /dev/null +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.service.spec.ts @@ -0,0 +1,53 @@ +/*! + * @license + * Copyright 2019 Alfresco Software, Ltd. + * + * 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. + */ + +import { ContentNodeSelectorPanelService } from './content-node-selector-panel.service'; +import { mockContentModelDateProperty, mockContentModelTextProperty, mockConvertedSearchCategoriesFromModels } from '../mock/content-model.mock'; + +describe('ContentNodeSelectorPanelService', () => { + + const contentNodeSelectorPanelService = new ContentNodeSelectorPanelService(); + + it('should support text type', () => { + expect(contentNodeSelectorPanelService.modelPropertyTypeToSearchFilterTypeMap.get('d:text')).toEqual('text'); + expect(contentNodeSelectorPanelService.isTypeSupported('d:text')).toEqual(true); + }); + + it('should support date type', () => { + expect(contentNodeSelectorPanelService.modelPropertyTypeToSearchFilterTypeMap.get('d:date')).toEqual('date-range'); + expect(contentNodeSelectorPanelService.isTypeSupported('d:date')).toEqual(true); + }); + + it('should return false for an unsupported type', () => { + expect(contentNodeSelectorPanelService.isTypeSupported('d:unsupported')).toEqual(false); + }); + + it('should modelPropertyTypeToSearchFilterTypeMap contain only the supported types', () => { + const expectedSupportedTypesMap = new Map (); + expectedSupportedTypesMap.set('d:text', 'text'); + expectedSupportedTypesMap.set('d:date', 'date-range'); + + expect(contentNodeSelectorPanelService.modelPropertyTypeToSearchFilterTypeMap).toEqual(expectedSupportedTypesMap); + }); + + it('should search config contain the correct filters converted from the custom content model properties', () => { + contentNodeSelectorPanelService.customModels = [mockContentModelTextProperty, mockContentModelDateProperty]; + const expectedConvertedPropertiesToSearchCategories = contentNodeSelectorPanelService.convertCustomModelPropertiesToSearchCategories(); + + expect(expectedConvertedPropertiesToSearchCategories).toEqual(mockConvertedSearchCategoriesFromModels); + }); +}); diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.service.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.service.ts index c7e12f1d45..7ccca67a7b 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.service.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.service.ts @@ -16,17 +16,24 @@ */ import { Injectable } from '@angular/core'; -import { SearchCategory } from '../search'; +import { SearchCategory } from '../search/search-category.interface'; @Injectable({ providedIn: 'root' }) export class ContentNodeSelectorPanelService { + propertyTypes = ['d:text', 'd:date']; + modelPropertyTypeToSearchFilterTypeMap = new Map (); customModels: any[]; - convertCustomModelPropertiesToSearchCategories(): any[] { - const searchConfig = []; + constructor() { + this.modelPropertyTypeToSearchFilterTypeMap.set(this.propertyTypes[0], 'text'); + this.modelPropertyTypeToSearchFilterTypeMap.set(this.propertyTypes[1], 'date-range'); + } + + convertCustomModelPropertiesToSearchCategories(): SearchCategory[] { + const searchConfig: SearchCategory[] = []; this.customModels?.forEach( (propertyModel) => { searchConfig.push(this.convertModelPropertyIntoSearchFilter(propertyModel)); }); @@ -36,14 +43,14 @@ export class ContentNodeSelectorPanelService { convertModelPropertyIntoSearchFilter(modelProperty: any): SearchCategory { let filterSearch: SearchCategory; - if (modelProperty.dataType === 'd:text') { + if (this.isTypeSupported(modelProperty.dataType)) { filterSearch = { id : modelProperty.prefixedName, name: modelProperty.prefixedName, expanded: false, enabled: true, component: { - selector: 'text', + selector: this.modelPropertyTypeToSearchFilterTypeMap.get(modelProperty.dataType), settings: { pattern: `${modelProperty.prefixedName}:'(.*?)'`, field: `${modelProperty.prefixedName}`, @@ -55,4 +62,8 @@ export class ContentNodeSelectorPanelService { return filterSearch; } + isTypeSupported(dataType: string): boolean { + return this.propertyTypes.includes(dataType); + } + } diff --git a/lib/content-services/src/lib/mock/content-model.mock.ts b/lib/content-services/src/lib/mock/content-model.mock.ts index 6ad3586380..c77b0b7b1a 100644 --- a/lib/content-services/src/lib/mock/content-model.mock.ts +++ b/lib/content-services/src/lib/mock/content-model.mock.ts @@ -15,7 +15,9 @@ * limitations under the License. */ -export const mockContentModelProperty = { +import { SearchCategory } from '../search/search-category.interface'; + +export const mockContentModelTextProperty = { name: 'name', prefixedName: 'account:name', title: 'name', @@ -30,3 +32,50 @@ export const mockContentModelProperty = { indexTokenisationMode: '', constraints: [] }; + +export const mockContentModelDateProperty = { + name: 'creation', + prefixedName: 'account:creation', + title: 'creation', + description: '', + dataType: 'd:date', + multiValued: false, + mandatory: false, + defaultValue: '', + mandatoryEnforced: false, + indexed: false, + facetable: 'FALSE', + indexTokenisationMode: '', + constraints: [] +}; + +export const mockConvertedSearchCategoriesFromModels: SearchCategory[] = [ + { + id: 'account:name', + name: 'account:name', + expanded: false, + enabled: true, + component: { + selector: 'text', + settings: { + pattern: `account:name:'(.*?)'`, + field: `account:name`, + placeholder: `Enter the name` + } + } + }, + { + id: 'account:creation', + name: 'account:creation', + expanded: false, + enabled: true, + component: { + selector: 'date-range', + settings: { + pattern: `account:creation:'(.*?)'`, + field: `account:creation`, + placeholder: `Enter the creation` + } + } + } +];