@platform/cell.schema
Version:
URI and database schemas for the `cell.os`.
74 lines (73 loc) • 2.73 kB
JavaScript
import { expect } from '../test';
import { squash } from './squash';
describe('squash', () => {
it('squash.props (cell)', () => {
const test = (props, expected) => {
const res = squash.props(props);
expect(res).to.eql(expected);
};
test();
test({});
test({ style: {} });
test({ merge: {} });
test({ style: {}, merge: {} });
test({ style: { bold: true }, merge: {} }, { style: { bold: true } });
});
it('squash.props (row)', () => {
const test = (props, expected) => {
const res = squash.props(props);
expect(res).to.eql(expected);
};
test();
test({});
test({ grid: undefined });
test({ grid: {} });
test({ grid: { height: 0 } }, { grid: { height: 0 } });
test({ grid: { height: 123 } }, { grid: { height: 123 } });
test({ foo: null }, { foo: null });
});
it('squash.props (column)', () => {
const test = (props, expected) => {
const res = squash.props(props);
expect(res).to.eql(expected);
};
test();
test({});
test({ grid: undefined });
test({ grid: {} });
test({ grid: { width: 0 } }, { grid: { width: 0 } });
test({ grid: { width: 123 } }, { grid: { width: 123 } });
test({ foo: null }, { foo: null });
});
it('squash.cell', () => {
const test = (cell, expected, empty) => {
const res = squash.cell(cell, { empty });
expect(res).to.eql(expected);
};
test();
test({});
test({ value: undefined });
test({ value: 123 }, { value: 123 });
test({ value: 123, links: {} }, { value: 123 });
test({ value: 0, links: {} }, { value: 0 });
test({ hash: 'sha256...' });
test({ value: 123, hash: 'sha256...' }, { value: 123, hash: 'sha256...' });
test({ value: undefined, error: { type: 'UNKNOWN', message: 'Fail' } }, { error: { type: 'UNKNOWN', message: 'Fail' } });
test({ value: undefined }, {}, {});
test({ value: null }, { value: null });
});
it('squash.object', () => {
const test = (obj, expected, options) => {
const res = squash.object(obj, options);
expect(res).to.eql(expected);
};
test();
test({});
test({ hash: 'sha256...' });
test({ foo: undefined, hash: 'sha256...' });
test({ foo: 123, hash: 'sha256...' }, { foo: 123, hash: 'sha256...' });
test({ foo: undefined });
test({ foo: null }, { foo: null });
test({ foo: { value: null } }, { foo: { value: null } });
});
});