Files
metabuilder/packages/package_validator/seed/scripts/tests/component.test.lua
JohnDoe6345789 459182b655 feat: Add comprehensive validation for package structure, metadata, and components
- Implemented component schema validation in `component_schema.lua`.
- Created metadata schema validation in `metadata_schema.lua`.
- Developed structure validation logic in `structure_validator.lua`.
- Introduced Lua file validation functions in `lua_validator.lua`.
- Added integration tests for validation logic in `validate.test.lua`.
- Created unit tests for component, metadata, and structure validation.
- Added SVG icon for package representation.
- Established a main validation orchestrator in `validate.lua` to coordinate the validation process.
2025-12-30 02:19:28 +00:00

150 lines
3.8 KiB
Lua

-- Component validation tests for schema_validator package
local component_schema = require("component_schema")
describe("Component Schema Validation", function()
it("should validate a simple component", function()
local valid_component = {
id = "test_component",
type = "TestComponent",
name = "Test Component",
description = "A test component"
}
local errors = component_schema.validate_component(valid_component)
expect(#errors).toBe(0)
end)
it("should fail when component id is missing", function()
local invalid_component = {
type = "TestComponent",
name = "Test Component"
}
local errors = component_schema.validate_component(invalid_component)
expect(#errors).toBeGreaterThan(0)
end)
it("should fail when component type is missing", function()
local invalid_component = {
id = "test_component",
name = "Test Component"
}
local errors = component_schema.validate_component(invalid_component)
expect(#errors).toBeGreaterThan(0)
end)
it("should validate component with props", function()
local valid_component = {
id = "test_component",
type = "TestComponent",
props = {
title = "Test",
count = 5
}
}
local errors = component_schema.validate_component(valid_component)
expect(#errors).toBe(0)
end)
it("should validate component with layout", function()
local valid_component = {
id = "test_component",
type = "TestComponent",
layout = {
type = "Box",
props = { className = "test" },
children = {}
}
}
local errors = component_schema.validate_component(valid_component)
expect(#errors).toBe(0)
end)
it("should validate nested layout structure", function()
local valid_component = {
id = "test_component",
type = "TestComponent",
layout = {
type = "Box",
children = {
{
type = "Card",
children = {
{
type = "CardHeader",
props = { text = "Title" }
}
}
}
}
}
}
local errors = component_schema.validate_component(valid_component)
expect(#errors).toBe(0)
end)
it("should fail when layout type is missing", function()
local invalid_component = {
id = "test_component",
type = "TestComponent",
layout = {
props = { className = "test" }
}
}
local errors = component_schema.validate_component(invalid_component)
expect(#errors).toBeGreaterThan(0)
end)
it("should validate components array", function()
local valid_components = {
{
id = "component_1",
type = "Component1"
},
{
id = "component_2",
type = "Component2"
}
}
local valid, errors = component_schema.validate_components(valid_components)
expect(valid).toBe(true)
expect(#errors).toBe(0)
end)
it("should validate empty components array", function()
local valid_components = {}
local valid, errors = component_schema.validate_components(valid_components)
expect(valid).toBe(true)
expect(#errors).toBe(0)
end)
it("should fail when components is not an array", function()
local invalid_components = "not an array"
local valid, errors = component_schema.validate_components(invalid_components)
expect(valid).toBe(false)
expect(#errors).toBeGreaterThan(0)
end)
it("should validate component with bindings", function()
local valid_component = {
id = "test_component",
type = "TestComponent",
bindings = {
dbal = true,
browser = false
}
}
local errors = component_schema.validate_component(valid_component)
expect(#errors).toBe(0)
end)
end)