UNPKG

@jungvonmatt/sb-migrate

Version:

CLI tool for managing Storyblok schema and content migrations

600 lines 21.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const schemaComponentHelpers_1 = require("../../utils/schemaComponentHelpers"); (0, vitest_1.describe)("Schema Component Helpers", () => { (0, vitest_1.describe)("textField", () => { (0, vitest_1.it)("should create a text field with basic properties", () => { // Arrange const props = { display_name: "Title", required: true, translatable: true, }; // Act const result = (0, schemaComponentHelpers_1.textField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "text", display_name: "Title", required: true, translatable: true, }); }); (0, vitest_1.it)("should create a text field with all optional properties", () => { // Arrange const props = { display_name: "Title", required: true, translatable: true, description: "Enter the title", tooltip: true, rtl: true, default_value: "Default Title", max_length: 50, regex: "^[A-Za-z0-9 ]+$", pos: 0, }; // Act const result = (0, schemaComponentHelpers_1.textField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "text", ...props, }); }); }); (0, vitest_1.describe)("textareaField", () => { (0, vitest_1.it)("should create a textarea field with basic properties", () => { // Arrange const props = { display_name: "Description", required: false, translatable: true, }; // Act const result = (0, schemaComponentHelpers_1.textareaField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "textarea", display_name: "Description", required: false, translatable: true, }); }); (0, vitest_1.it)("should create a textarea field with all optional properties", () => { // Arrange const props = { display_name: "Description", required: false, translatable: true, description: "Enter the description", tooltip: true, rtl: true, default_value: "Default Description", max_length: 255, pos: 1, }; // Act const result = (0, schemaComponentHelpers_1.textareaField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "textarea", ...props, }); }); }); (0, vitest_1.describe)("bloksField", () => { (0, vitest_1.it)("should create a blocks field with basic properties", () => { // Arrange const props = { display_name: "Content", required: true, translatable: true, }; // Act const result = (0, schemaComponentHelpers_1.bloksField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "bloks", display_name: "Content", required: true, translatable: true, }); }); (0, vitest_1.it)("should create a blocks field with component restrictions", () => { // Arrange const props = { display_name: "Content", required: true, translatable: true, restrict_components: true, component_whitelist: ["text", "image"], minimum: 1, maximum: 5, }; // Act const result = (0, schemaComponentHelpers_1.bloksField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "bloks", ...props, }); }); }); (0, vitest_1.describe)("richtextField", () => { (0, vitest_1.it)("should create a richtext field with basic properties", () => { // Arrange const props = { display_name: "Content", required: true, translatable: true, }; // Act const result = (0, schemaComponentHelpers_1.richtextField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "richtext", display_name: "Content", required: true, translatable: true, }); }); (0, vitest_1.it)("should create a richtext field with toolbar customization", () => { // Arrange const props = { display_name: "Content", required: true, translatable: true, customize_toolbar: true, toolbar: ["bold", "italic", "link"], allow_target_blank: true, allow_custom_attributes: true, }; // Act const result = (0, schemaComponentHelpers_1.richtextField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "richtext", ...props, }); }); }); (0, vitest_1.describe)("markdownField", () => { (0, vitest_1.it)("should create a markdown field with basic properties", () => { // Arrange const props = { display_name: "Content", required: true, translatable: true, }; // Act const result = (0, schemaComponentHelpers_1.markdownField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "markdown", display_name: "Content", required: true, translatable: true, }); }); (0, vitest_1.it)("should create a markdown field with rich markdown options", () => { // Arrange const props = { display_name: "Content", required: true, translatable: true, rich_markdown: true, allow_multiline: true, customize_toolbar: true, toolbar: ["bold", "italic", "link"], }; // Act const result = (0, schemaComponentHelpers_1.markdownField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "markdown", ...props, }); }); }); (0, vitest_1.describe)("numberField", () => { (0, vitest_1.it)("should create a number field with basic properties", () => { // Arrange const props = { display_name: "Quantity", required: true, translatable: false, }; // Act const result = (0, schemaComponentHelpers_1.numberField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "number", display_name: "Quantity", required: true, translatable: false, }); }); (0, vitest_1.it)("should create a number field with validation constraints", () => { // Arrange const props = { display_name: "Quantity", required: true, translatable: false, min_value: 0, max_value: 1, decimals: 2, steps: 10, default_value: "0", }; // Act const result = (0, schemaComponentHelpers_1.numberField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "number", ...props, }); }); }); (0, vitest_1.describe)("datetimeField", () => { (0, vitest_1.it)("should create a datetime field with basic properties", () => { // Arrange const props = { display_name: "Date and Time", required: true, translatable: false, }; // Act const result = (0, schemaComponentHelpers_1.datetimeField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "datetime", display_name: "Date and Time", required: true, translatable: false, }); }); (0, vitest_1.it)("should create a datetime field with time disabled", () => { // Arrange const props = { display_name: "Date", required: true, translatable: false, disable_time: true, default_value: "2024-01-01", }; // Act const result = (0, schemaComponentHelpers_1.datetimeField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "datetime", ...props, }); }); }); (0, vitest_1.describe)("booleanField", () => { (0, vitest_1.it)("should create a boolean field with basic properties", () => { // Arrange const props = { display_name: "Active", required: true, translatable: false, }; // Act const result = (0, schemaComponentHelpers_1.booleanField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "boolean", display_name: "Active", required: true, translatable: false, }); }); (0, vitest_1.it)("should create a boolean field with inline label", () => { // Arrange const props = { display_name: "Active", required: true, translatable: false, inline_label: true, default_value: true, }; // Act const result = (0, schemaComponentHelpers_1.booleanField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "boolean", ...props, }); }); }); (0, vitest_1.describe)("optionsField", () => { (0, vitest_1.it)("should create an options field with self-defined options", () => { // Arrange const props = { display_name: "Size", source: "self", options: [ { name: "Small", value: "small" }, { name: "Medium", value: "medium" }, { name: "Large", value: "large" }, ], default_value: "medium", }; // Act const result = (0, schemaComponentHelpers_1.optionsField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "options", ...props, }); }); (0, vitest_1.it)("should create an options field with datasource", () => { // Arrange const props = { display_name: "Category", source: "internal", datasource_slug: "categories", default_value: "electronics", }; // Act const result = (0, schemaComponentHelpers_1.optionsField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "options", ...props, }); }); }); (0, vitest_1.describe)("optionField", () => { (0, vitest_1.it)("should create an option field with self-defined options", () => { // Arrange const props = { display_name: "Alignment", source: "self", options: [ { name: "Left", value: "left" }, { name: "Center", value: "center" }, { name: "Right", value: "right" }, ], default_value: "left", }; // Act const result = (0, schemaComponentHelpers_1.optionField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "option", ...props, }); }); (0, vitest_1.it)("should create an option field with UUID support", () => { // Arrange const props = { display_name: "Category", source: "internal", datasource_slug: "categories", use_uuid: true, }; // Act const result = (0, schemaComponentHelpers_1.optionField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "option", ...props, }); }); }); (0, vitest_1.describe)("assetField", () => { (0, vitest_1.it)("should create an asset field with basic properties", () => { // Arrange const props = { display_name: "Image", required: true, translatable: false, }; // Act const result = (0, schemaComponentHelpers_1.assetField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "asset", display_name: "Image", required: true, translatable: false, }); }); (0, vitest_1.it)("should create an asset field with file type restrictions", () => { // Arrange const props = { display_name: "Image", required: true, translatable: false, filetypes: ["images"], allow_external_url: true, }; // Act const result = (0, schemaComponentHelpers_1.assetField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "asset", ...props, }); }); }); (0, vitest_1.describe)("multiassetField", () => { (0, vitest_1.it)("should create a multiasset field with basic properties", () => { // Arrange const props = { display_name: "Gallery", required: true, translatable: false, }; // Act const result = (0, schemaComponentHelpers_1.multiassetField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "multiasset", display_name: "Gallery", required: true, translatable: false, }); }); (0, vitest_1.it)("should create a multiasset field with file type restrictions", () => { // Arrange const props = { display_name: "Gallery", required: true, translatable: false, filetypes: ["images", "videos"], allow_external_url: true, }; // Act const result = (0, schemaComponentHelpers_1.multiassetField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "multiasset", ...props, }); }); }); (0, vitest_1.describe)("multilinkField", () => { (0, vitest_1.it)("should create a multilink field with basic properties", () => { // Arrange const props = { display_name: "Link", required: true, translatable: false, }; // Act const result = (0, schemaComponentHelpers_1.multilinkField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "multilink", display_name: "Link", required: true, translatable: false, }); }); (0, vitest_1.it)("should create a multilink field with advanced options", () => { // Arrange const props = { display_name: "Link", required: true, translatable: false, show_anchor: true, allow_target_blank: true, allow_custom_attributes: true, restrict_content_types: true, component_whitelist: ["page", "post"], }; // Act const result = (0, schemaComponentHelpers_1.multilinkField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "multilink", ...props, }); }); }); (0, vitest_1.describe)("tableField", () => { (0, vitest_1.it)("should create a table field with basic properties", () => { // Arrange const props = { display_name: "Table", required: true, translatable: false, }; // Act const result = (0, schemaComponentHelpers_1.tableField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "table", display_name: "Table", required: true, translatable: false, }); }); }); (0, vitest_1.describe)("sectionField", () => { (0, vitest_1.it)("should create a section field with keys", () => { // Arrange const props = { display_name: "Section", required: true, translatable: false, keys: ["title", "description", "image"], }; // Act const result = (0, schemaComponentHelpers_1.sectionField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "section", display_name: "Section", required: true, translatable: false, keys: ["title", "description", "image"], }); }); }); (0, vitest_1.describe)("customField", () => { (0, vitest_1.it)("should create a custom field with basic properties", () => { // Arrange const props = { display_name: "Custom", required: true, translatable: false, field_type: "custom_type", }; // Act const result = (0, schemaComponentHelpers_1.customField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "custom", display_name: "Custom", required: true, translatable: false, field_type: "custom_type", }); }); (0, vitest_1.it)("should create a custom field with options and required fields", () => { // Arrange const props = { display_name: "Custom", required: true, translatable: false, field_type: "custom_type", options: [{ name: "Option 1", value: "opt1" }], required_fields: "field1,field2", }; // Act const result = (0, schemaComponentHelpers_1.customField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "custom", ...props, }); }); }); (0, vitest_1.describe)("tabField", () => { (0, vitest_1.it)("should create a tab field with keys", () => { // Arrange const props = { display_name: "Tab", required: true, translatable: false, keys: ["tab1", "tab2", "tab3"], }; // Act const result = (0, schemaComponentHelpers_1.tabField)(props); // Assert (0, vitest_1.expect)(result).toEqual({ type: "tab", display_name: "Tab", required: true, translatable: false, keys: ["tab1", "tab2", "tab3"], }); }); }); }); //# sourceMappingURL=schemaComponentHelpers.test.js.map