@eeacms/volto-block-style
Version:
volto-block-style: Volto add-on
90 lines (79 loc) • 2.16 kB
JavaScript
import { getFieldURL } from './helpers';
describe('getFieldURL', () => {
it('handles a URL type object with type and value', () => {
const data = {
'@type': 'URL',
value: 'value_url',
url: 'url_url',
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('value_url');
});
it('handles an object with type and url', () => {
const data = {
'@type': 'URL',
url: 'url_url',
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('url_url');
});
it('handles an object with type and href', () => {
const data = {
'@type': 'URL',
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('href_url');
});
it('handles an object with type and no value, url and href', () => {
const data = {
'@type': 'URL',
};
expect(getFieldURL(data)).toEqual({ '@type': 'URL' });
});
it('handles an object without a specific type and url', () => {
const data = {
url: 'url_url',
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('url_url');
});
it('handles an object without a specific type and href', () => {
const data = {
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('href_url');
});
it('handles an object without a specific type and no id, url, href', () => {
const data = {
test: 'test_url',
};
expect(getFieldURL(data)).toEqual({
test: 'test_url',
});
});
it('handles an array', () => {
const data = [
{
'@type': 'URL',
value: 'value_url',
url: 'url_url',
href: 'href_url',
},
{
'@id': 'id_url',
url: 'url_url',
href: 'href_url',
},
];
expect(getFieldURL(data)).toEqual(['value_url', 'id_url']);
});
it('handles a string', () => {
const data = '/some/url';
expect(getFieldURL(data)).toEqual('/some/url');
});
it('returns the data unchanged for non-object/non-array/non-string inputs', () => {
expect(getFieldURL(42)).toEqual(42);
expect(getFieldURL(undefined)).toEqual(undefined);
expect(getFieldURL(null)).toEqual(null);
});
});