mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
ACS-8224 Make Multi Value Pipe internal (#11530)
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. 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.
|
||||
*/
|
||||
|
||||
import { MultiValuePipe } from './multi-value.pipe';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
describe('MultiValuePipe', () => {
|
||||
let pipe: MultiValuePipe;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [MultiValuePipe],
|
||||
providers: [MultiValuePipe]
|
||||
});
|
||||
pipe = TestBed.inject(MultiValuePipe);
|
||||
});
|
||||
|
||||
it('should add the separator when a string list is provided', () => {
|
||||
const values = ['cat', 'house', 'dog'];
|
||||
expect(pipe.transform(values)).toBe('cat, house, dog');
|
||||
});
|
||||
|
||||
it('should add the separator when a number list is provided', () => {
|
||||
const values = [1, 2, 3];
|
||||
expect(pipe.transform(values)).toBe('1, 2, 3');
|
||||
});
|
||||
|
||||
it('should add custom separator when set', () => {
|
||||
const values = ['cat', 'house', 'dog'];
|
||||
const customSeparator = ' - ';
|
||||
expect(pipe.transform(values, customSeparator)).toBe('cat - house - dog');
|
||||
});
|
||||
|
||||
it('should not add separator when the list has only one item', () => {
|
||||
const values = ['cat'];
|
||||
expect(pipe.transform(values)).toBe('cat');
|
||||
});
|
||||
|
||||
it('should return empty string when an empty list is passed', () => {
|
||||
const values = [];
|
||||
expect(pipe.transform(values)).toBe('');
|
||||
});
|
||||
|
||||
it('should return empty string when an empty string is passed', () => {
|
||||
const values = '';
|
||||
expect(pipe.transform(values)).toBe('');
|
||||
});
|
||||
|
||||
it('should return same string when the value passed is a string', () => {
|
||||
const values = 'cat';
|
||||
expect(pipe.transform(values)).toBe('cat');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. 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.
|
||||
*/
|
||||
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'multiValue'
|
||||
})
|
||||
export class MultiValuePipe implements PipeTransform {
|
||||
static DEFAULT_SEPARATOR = ', ';
|
||||
|
||||
transform(values: any | any[], valueSeparator: string = MultiValuePipe.DEFAULT_SEPARATOR): string {
|
||||
if (values && values instanceof Array) {
|
||||
return values.join(valueSeparator);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -30,12 +30,12 @@ import {
|
||||
CardViewTextItemModel,
|
||||
DecimalNumberPipe,
|
||||
LogService,
|
||||
MultiValuePipe,
|
||||
UserPreferencesService
|
||||
} from '@alfresco/adf-core';
|
||||
import { CardViewGroup, OrganisedPropertyGroup, Property } from '../interfaces/content-metadata.interfaces';
|
||||
import { of } from 'rxjs';
|
||||
import { Constraint, Definition, Property as PropertyBase } from '@alfresco/js-api';
|
||||
import { MultiValuePipe } from './pipes/multi-value.pipe';
|
||||
|
||||
const D_TEXT = 'd:text';
|
||||
const D_MLTEXT = 'd:mltext';
|
||||
|
||||
Reference in New Issue
Block a user