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.
41 lines
1.3 KiB
41 lines
1.3 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Sebastian Stehle. All rights reserved
|
|
*/
|
|
|
|
import { StringHelper } from './../';
|
|
|
|
describe('StringHelper', () => {
|
|
it('should return empty text if value is null or undefined', () => {
|
|
|
|
expect(StringHelper.firstNonEmpty(null!)).toBe('');
|
|
expect(StringHelper.firstNonEmpty(undefined!)).toBe('');
|
|
});
|
|
|
|
it('should return fallback name if label is undefined or null', () => {
|
|
expect(StringHelper.firstNonEmpty(null!, 'fallback')).toBe('fallback');
|
|
expect(StringHelper.firstNonEmpty(undefined!, 'fallback')).toBe('fallback');
|
|
});
|
|
|
|
it('should return label if value is valid', () => {
|
|
expect(StringHelper.firstNonEmpty('name')).toBe('name');
|
|
});
|
|
|
|
it('should return trimmed label if value is valid', () => {
|
|
expect(StringHelper.firstNonEmpty(' name ')).toBe('name');
|
|
});
|
|
|
|
it('should return fallback name if label is empty', () => {
|
|
expect(StringHelper.firstNonEmpty('', 'fallback')).toBe('fallback');
|
|
});
|
|
|
|
it('should return trimmed fallback name if label is undefined', () => {
|
|
expect(StringHelper.firstNonEmpty('', ' fallback ')).toBe('fallback');
|
|
});
|
|
|
|
it('should return empty string if also fallback not found', () => {
|
|
expect(StringHelper.firstNonEmpty(null!, undefined!, '')).toBe('');
|
|
});
|
|
});
|