@blinkk/selective-edit
Version:
Selective structured text editor.
105 lines • 3.14 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const autoFields_1 = require("./autoFields");
const ava_1 = __importDefault(require("ava"));
(0, ava_1.default)('auto fields guess null', t => {
const autoFields = new autoFields_1.AutoFields({});
const expected = {
key: 'test',
label: 'Test',
type: 'text',
};
t.deepEqual(autoFields.guessField('test', null), expected);
});
(0, ava_1.default)('auto fields guess undefined', t => {
const autoFields = new autoFields_1.AutoFields();
const expected = {
key: 'test',
label: 'Test',
type: 'text',
};
t.deepEqual(autoFields.guessField('test', undefined), expected);
});
(0, ava_1.default)('auto fields guess string', t => {
const autoFields = new autoFields_1.AutoFields();
const expected = {
key: 'test',
label: 'Test',
type: 'text',
};
t.deepEqual(autoFields.guessField('test', 'foobar'), expected);
});
(0, ava_1.default)('auto fields guess list', t => {
const autoFields = new autoFields_1.AutoFields();
const expected = {
key: 'test',
label: 'Test',
type: 'list',
fields: [
{
key: '',
type: 'text',
},
],
};
t.deepEqual(autoFields.guessField('test', ['foobar']), expected);
});
(0, ava_1.default)('auto fields guess textarea', t => {
const autoFields = new autoFields_1.AutoFields();
const expected = {
key: 'test',
label: 'Test',
type: 'textarea',
};
t.deepEqual(autoFields.guessField('test', `${'fobar'.repeat(15)}a`), expected);
});
(0, ava_1.default)('auto fields guess full object', t => {
const autoFields = new autoFields_1.AutoFields();
const data = {
test: 'testing',
foo: `${'fobar'.repeat(15)}a`,
bar: ['test'],
};
// Sort the expected since there is no guarantee of the key order.
const expected = [
{
key: 'bar',
label: 'Bar',
type: 'list',
fields: [
{
key: '',
type: 'text',
},
],
},
{
key: 'foo',
label: 'Foo',
type: 'textarea',
},
{
key: 'test',
label: 'Test',
type: 'text',
},
];
// Sort the results since there is no guarantee of the key order.
const actual = autoFields
.guessFields(data)
.sort((a, b) => (a.key < b.key ? -1 : 1));
t.deepEqual(actual, expected);
});
(0, ava_1.default)('auto fields guess multi-part label', t => {
const autoFields = new autoFields_1.AutoFields();
const expected = {
key: 'foo.bar',
label: 'Foo Bar',
type: 'text',
};
t.deepEqual(autoFields.guessField('foo.bar', 'foobar'), expected);
});
//# sourceMappingURL=autoFields.test.js.map