mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 22:34:56 +00:00
163 lines
7.0 KiB
Lua
163 lines
7.0 KiB
Lua
-- Tests for blueprint.lua functions
|
|
-- Tests build_blueprint function with various inputs
|
|
|
|
local M = {}
|
|
|
|
---@param framework TestFramework
|
|
---@param assertions AssertionsModule
|
|
---@param mocks MocksModule
|
|
function M.defineTests(framework, assertions, mocks)
|
|
local describe = framework.describe
|
|
local it = framework.it
|
|
local it_each = framework.it_each
|
|
local beforeEach = framework.beforeEach
|
|
local expect = assertions.expect
|
|
|
|
local blueprint = require("blueprint")
|
|
|
|
describe("blueprint", function()
|
|
|
|
describe("build_blueprint", function()
|
|
|
|
describe("project naming", function()
|
|
it_each({
|
|
{ project_name = "my-app", expected_name = "my-app", desc = "custom name" },
|
|
{ project_name = "test-project", expected_name = "test-project", desc = "hyphenated name" },
|
|
{ project_name = "App123", expected_name = "App123", desc = "alphanumeric name" },
|
|
{ project_name = nil, expected_name = "starter-app", desc = "nil defaults to starter-app" },
|
|
{ project_name = "", expected_name = "starter-app", desc = "empty string defaults to starter-app" }
|
|
})("should use $expected_name for $desc", function(tc)
|
|
local result = blueprint.build_blueprint({ project_name = tc.project_name })
|
|
expect(result.name).toBe(tc.expected_name)
|
|
end)
|
|
end)
|
|
|
|
describe("runtime selection", function()
|
|
it_each({
|
|
{ runtime = "web", expected = "web", desc = "web runtime" },
|
|
{ runtime = "node", expected = "node", desc = "node runtime" },
|
|
{ runtime = "desktop", expected = "desktop", desc = "desktop runtime" },
|
|
{ runtime = nil, expected = "web", desc = "nil defaults to web" },
|
|
{ runtime = "", expected = "web", desc = "empty string defaults to web" }
|
|
})("should use $expected runtime for $desc", function(tc)
|
|
local result = blueprint.build_blueprint({ runtime = tc.runtime })
|
|
expect(result.runtime).toBe(tc.expected)
|
|
end)
|
|
end)
|
|
|
|
describe("description handling", function()
|
|
it_each({
|
|
{ description = "My awesome app", expected = "My awesome app", desc = "custom description" },
|
|
{ description = "Test description", expected = "Test description", desc = "simple description" },
|
|
{ description = nil, expected = "Generated by Codegen Studio", desc = "nil defaults to standard desc" },
|
|
{ description = "", expected = "Generated by Codegen Studio", desc = "empty defaults to standard desc" }
|
|
})("should use '$expected' for $desc", function(tc)
|
|
local result = blueprint.build_blueprint({ description = tc.description })
|
|
expect(result.description).toBe(tc.expected)
|
|
end)
|
|
end)
|
|
|
|
describe("generated files", function()
|
|
it("should generate 3 files by default", function()
|
|
local result = blueprint.build_blueprint({})
|
|
expect(#result.files).toBe(3)
|
|
end)
|
|
|
|
it("should generate README.md as first file", function()
|
|
local result = blueprint.build_blueprint({ project_name = "test-app" })
|
|
expect(result.files[1].path).toBe("test-app/README.md")
|
|
end)
|
|
|
|
it("should generate package.json as second file", function()
|
|
local result = blueprint.build_blueprint({ project_name = "test-app" })
|
|
expect(result.files[2].path).toBe("test-app/package.json")
|
|
end)
|
|
|
|
it("should generate page.tsx as third file", function()
|
|
local result = blueprint.build_blueprint({ project_name = "test-app" })
|
|
expect(result.files[3].path).toBe("test-app/src/app/page.tsx")
|
|
end)
|
|
|
|
it_each({
|
|
{ project_name = "my-app", desc = "custom project" },
|
|
{ project_name = "another-project", desc = "another project" },
|
|
{ project_name = nil, desc = "default project" }
|
|
})("should include project name in all file paths for $desc", function(tc)
|
|
local result = blueprint.build_blueprint({ project_name = tc.project_name })
|
|
local expected_prefix = tc.project_name or "starter-app"
|
|
|
|
for _, file in ipairs(result.files) do
|
|
expect(string.find(file.path, expected_prefix, 1, true)).toBeTruthy()
|
|
end
|
|
end)
|
|
end)
|
|
|
|
describe("README.md content", function()
|
|
it("should contain project name as heading", function()
|
|
local result = blueprint.build_blueprint({ project_name = "my-app" })
|
|
expect(string.find(result.files[1].content, "# my-app", 1, true)).toBeTruthy()
|
|
end)
|
|
|
|
it("should contain description in README", function()
|
|
local result = blueprint.build_blueprint({
|
|
project_name = "my-app",
|
|
description = "A cool project"
|
|
})
|
|
expect(string.find(result.files[1].content, "A cool project", 1, true)).toBeTruthy()
|
|
end)
|
|
end)
|
|
|
|
describe("package.json content", function()
|
|
it("should contain project name", function()
|
|
local result = blueprint.build_blueprint({ project_name = "my-app" })
|
|
expect(string.find(result.files[2].content, '"name": "my-app"', 1, true)).toBeTruthy()
|
|
end)
|
|
|
|
it("should be marked as private", function()
|
|
local result = blueprint.build_blueprint({ project_name = "my-app" })
|
|
expect(string.find(result.files[2].content, '"private": true', 1, true)).toBeTruthy()
|
|
end)
|
|
end)
|
|
|
|
describe("page.tsx content", function()
|
|
it("should contain project name in component", function()
|
|
local result = blueprint.build_blueprint({ project_name = "my-app" })
|
|
expect(string.find(result.files[3].content, "my-app", 1, true)).toBeTruthy()
|
|
end)
|
|
|
|
it("should export default function Home", function()
|
|
local result = blueprint.build_blueprint({ project_name = "my-app" })
|
|
expect(string.find(result.files[3].content, "export default function Home", 1, true)).toBeTruthy()
|
|
end)
|
|
end)
|
|
|
|
describe("complete input handling", function()
|
|
it("should handle all inputs provided", function()
|
|
local result = blueprint.build_blueprint({
|
|
project_name = "full-app",
|
|
runtime = "node",
|
|
description = "A complete application"
|
|
})
|
|
|
|
expect(result.name).toBe("full-app")
|
|
expect(result.runtime).toBe("node")
|
|
expect(result.description).toBe("A complete application")
|
|
expect(#result.files).toBe(3)
|
|
end)
|
|
|
|
it("should handle empty input table", function()
|
|
local result = blueprint.build_blueprint({})
|
|
|
|
expect(result.name).toBe("starter-app")
|
|
expect(result.runtime).toBe("web")
|
|
expect(result.description).toBe("Generated by Codegen Studio")
|
|
end)
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
end
|
|
|
|
return M
|