@sketch-hq/sketch-assistant-utils
Version:
Utility functions and types for Sketch Assistants.
216 lines (215 loc) • 6.76 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
const test_helpers_1 = require("../../test-helpers");
describe('buildAssistantConfigSchema', () => {
test('builds configuration schema', () => {
const assistant = test_helpers_1.createAssistantDefinition({
rules: [test_helpers_1.createRule({ name: 'foo' })],
config: test_helpers_1.createAssistantConfig({
rules: {
foo: { active: true },
},
}),
});
expect(__1.buildAssistantConfigSchema(assistant)).toMatchInlineSnapshot(`
Object {
"properties": Object {
"rules": Object {
"properties": Object {
"foo": Object {
"properties": Object {
"active": Object {
"default": true,
"type": "boolean",
},
},
"required": Array [
"active",
],
"type": "object",
},
},
"type": "object",
},
},
"type": "object",
}
`);
});
test('builds configuration schema exclusing inactive rules', () => {
const assistant = test_helpers_1.createAssistantDefinition({
rules: [test_helpers_1.createRule({ name: 'foo' })],
config: test_helpers_1.createAssistantConfig({
rules: {},
}),
});
expect(__1.buildAssistantConfigSchema(assistant)).toMatchInlineSnapshot(`
Object {
"properties": Object {
"rules": Object {
"properties": Object {},
"type": "object",
},
},
"type": "object",
}
`);
});
test('use integer option config value as default', () => {
const assistant = test_helpers_1.createAssistantDefinition({
rules: [
test_helpers_1.createRule({
name: 'foo',
getOptions: (helpers) => [
helpers.integerOption({
name: 'option',
title: 'integer option',
description: 'some detail',
}),
],
}),
],
config: test_helpers_1.createAssistantConfig({
rules: {
foo: { active: true, option: 1 },
},
}),
});
expect(__1.buildAssistantConfigSchema(assistant)).toMatchInlineSnapshot(`
Object {
"properties": Object {
"rules": Object {
"properties": Object {
"foo": Object {
"properties": Object {
"active": Object {
"default": true,
"type": "boolean",
},
"option": Object {
"default": 1,
"description": "some detail",
"title": "integer option",
"type": "integer",
},
},
"required": Array [
"active",
"option",
],
"type": "object",
},
},
"type": "object",
},
},
"type": "object",
}
`);
});
test('use number option config value as default', () => {
const assistant = test_helpers_1.createAssistantDefinition({
rules: [
test_helpers_1.createRule({
name: 'foo',
getOptions: (helpers) => [
helpers.numberOption({
name: 'option',
title: 'number option',
description: 'some detail',
}),
],
}),
],
config: test_helpers_1.createAssistantConfig({
rules: {
foo: { active: true, option: 1.5 },
},
}),
});
expect(__1.buildAssistantConfigSchema(assistant)).toMatchInlineSnapshot(`
Object {
"properties": Object {
"rules": Object {
"properties": Object {
"foo": Object {
"properties": Object {
"active": Object {
"default": true,
"type": "boolean",
},
"option": Object {
"default": 1.5,
"description": "some detail",
"title": "number option",
"type": "number",
},
},
"required": Array [
"active",
"option",
],
"type": "object",
},
},
"type": "object",
},
},
"type": "object",
}
`);
});
test('use string option config value as default', () => {
const assistant = test_helpers_1.createAssistantDefinition({
rules: [
test_helpers_1.createRule({
name: 'foo',
getOptions: (helpers) => [
helpers.stringOption({
name: 'option',
title: 'string option',
description: 'some detail',
}),
],
}),
],
config: test_helpers_1.createAssistantConfig({
rules: {
foo: { active: true, option: 'hello world' },
},
}),
});
expect(__1.buildAssistantConfigSchema(assistant)).toMatchInlineSnapshot(`
Object {
"properties": Object {
"rules": Object {
"properties": Object {
"foo": Object {
"properties": Object {
"active": Object {
"default": true,
"type": "boolean",
},
"option": Object {
"default": "hello world",
"description": "some detail",
"title": "string option",
"type": "string",
},
},
"required": Array [
"active",
"option",
],
"type": "object",
},
},
"type": "object",
},
},
"type": "object",
}
`);
});
});