added tests

This commit is contained in:
Mor Tal 2019-05-28 17:55:02 +03:00
parent f68286f39a
commit c9d3426fae

View File

@ -112,6 +112,65 @@ describe('preview.client_api', () => {
});
});
describe('addParameters', () => {
it('should add parameters', () => {
const { clientApi } = getContext();
clientApi.addParameters({ a: '1' });
// eslint-disable-next-line no-underscore-dangle
expect(clientApi._globalParameters).toEqual({ a: '1', options: {} });
});
it('should merge options', () => {
const { clientApi } = getContext();
clientApi.addParameters({ options: { a: '1' } });
clientApi.addParameters({ options: { b: '2' } });
// eslint-disable-next-line no-underscore-dangle
expect(clientApi._globalParameters).toEqual({ options: { a: '1', b: '2' } });
});
it('should override specific properties in options', () => {
const { clientApi } = getContext();
clientApi.addParameters({ backgrounds: ['value'], options: { a: '1', b: '3' } });
clientApi.addParameters({ options: { a: '2' } });
// eslint-disable-next-line no-underscore-dangle
expect(clientApi._globalParameters).toEqual({
backgrounds: ['value'],
options: { a: '2', b: '3' },
});
});
it('should replace top level properties and override specific properties in options', () => {
const { clientApi } = getContext();
clientApi.addParameters({ backgrounds: ['value'], options: { a: '1', b: '3' } });
clientApi.addParameters({ backgrounds: [], options: { a: '2' } });
// eslint-disable-next-line no-underscore-dangle
expect(clientApi._globalParameters).toEqual({
backgrounds: [],
options: { a: '2', b: '3' },
});
});
it('should deep merge in options', () => {
const { clientApi } = getContext();
clientApi.addParameters({ options: { a: '1', b: '2', theming: { c: '3' } } });
clientApi.addParameters({ options: { theming: { c: '4', d: '5' } } });
// eslint-disable-next-line no-underscore-dangle
expect(clientApi._globalParameters).toEqual({
options: { a: '1', b: '2', theming: { c: '4', d: '5' } },
});
});
});
describe('addDecorator', () => {
it('should add local decorators', () => {
const {