Files
remark42/frontend/app/utils/parse-booleans-from-dictionary.test.ts
T
Yuriy KarpovandUmputun 4e0a4e52bd add the ability to configure the 'simple_view' parameter from the client,
the parameter is not required, but if set, it will overwrite the one that came from the backend
issues-916
2021-05-06 11:08:15 -05:00

58 lines
1.5 KiB
TypeScript

import { parseBooleansFromDictionary } from './parse-booleans-from-dictionary';
const defaultProps = {
components: 'embed,counter',
host: 'http://127.0.0.1:9000',
locale: 'ru',
site_id: 'remark',
theme: 'dark',
};
describe('getConfigMerge', () => {
it('when we need to get one field and it is "true"', () => {
const params = {
...defaultProps,
simple: 'true',
simple_view: 'true',
};
expect(parseBooleansFromDictionary(params, 'simple_view')).toEqual({ simple_view: true });
});
it('when we need to get one field and it is "false"', () => {
const params = {
...defaultProps,
simple: 'true',
simple_view: 'false',
};
expect(parseBooleansFromDictionary(params, 'simple_view')).toEqual({ simple_view: false });
});
it('when we need to get one or more fields', () => {
const params = {
...defaultProps,
simple: 'false',
simple_view: 'true',
};
expect(parseBooleansFromDictionary(params, 'simple_view', 'simple')).toEqual({
simple: false,
simple_view: true,
});
});
it('when the required field does not exist', () => {
const params = {
...defaultProps,
simple: 'true',
};
expect(parseBooleansFromDictionary(params, 'simple_view')).toEqual({});
});
it('when the field has the wrong format', () => {
const params = {
...defaultProps,
simple: 'true',
simple_view: 'dark',
};
expect(parseBooleansFromDictionary(params, 'simple_view', 'simple')).toEqual({ simple: true });
});
});