mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { DisplayNamePipe } from './name.pipe';
|
|
|
|
describe('DisplayNamePipe', () => {
|
|
it('should return empty text if value is null or undefined', () => {
|
|
const pipe = new DisplayNamePipe();
|
|
|
|
expect(pipe.transform(null)).toBe('');
|
|
expect(pipe.transform(undefined)).toBe('');
|
|
});
|
|
|
|
it('should return value from nested object', () => {
|
|
const pipe = new DisplayNamePipe();
|
|
|
|
expect(pipe.transform({ properties: { label: 'name' } }, 'properties.label')).toBe('name');
|
|
});
|
|
|
|
it('should return label if value is valid', () => {
|
|
const pipe = new DisplayNamePipe();
|
|
|
|
expect(pipe.transform({ label: 'name' })).toBe('name');
|
|
});
|
|
|
|
it('should return trimmed label if value is valid', () => {
|
|
const pipe = new DisplayNamePipe();
|
|
|
|
expect(pipe.transform({ label: ' name ' })).toBe('name');
|
|
});
|
|
|
|
it('should return fallback name if label is empty', () => {
|
|
const pipe = new DisplayNamePipe();
|
|
|
|
expect(pipe.transform({ label: ' ', name: 'fallback' })).toBe('fallback');
|
|
});
|
|
|
|
it('should return fallback name if label is undefined', () => {
|
|
const pipe = new DisplayNamePipe();
|
|
|
|
expect(pipe.transform({ name: 'fallback' })).toBe('fallback');
|
|
});
|
|
|
|
it('should return trimmed fallback name if label is undefined', () => {
|
|
const pipe = new DisplayNamePipe();
|
|
|
|
expect(pipe.transform({ name: ' fallback ' })).toBe('fallback');
|
|
});
|
|
|
|
it('should return empty string if also fallback not found', () => {
|
|
const pipe = new DisplayNamePipe();
|
|
|
|
expect(pipe.transform({})).toBe('');
|
|
});
|
|
});
|