mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
config: stats,packages,grid (3 files)
This commit is contained in:
26
packages/stats_grid/seed/scripts/tests/formatters.cases.json
Normal file
26
packages/stats_grid/seed/scripts/tests/formatters.cases.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"formatLabel": [
|
||||
{
|
||||
"desc": "handles simple words",
|
||||
"input": "users",
|
||||
"expected": "Users"
|
||||
},
|
||||
{
|
||||
"desc": "handles underscores",
|
||||
"input": "active_users",
|
||||
"expected": "Active users"
|
||||
}
|
||||
],
|
||||
"formatValue": [
|
||||
{
|
||||
"desc": "handles zero",
|
||||
"input": 0,
|
||||
"expected": "0"
|
||||
},
|
||||
{
|
||||
"desc": "handles negative numbers",
|
||||
"input": -100,
|
||||
"expected": "-100"
|
||||
}
|
||||
]
|
||||
}
|
||||
59
packages/stats_grid/seed/scripts/tests/stats.cases.json
Normal file
59
packages/stats_grid/seed/scripts/tests/stats.cases.json
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"formatLabel": [
|
||||
{
|
||||
"desc": "formats snake_case to Title Case",
|
||||
"input": "total_errors",
|
||||
"expected": "Total errors"
|
||||
},
|
||||
{
|
||||
"desc": "formats camelCase to Title Case",
|
||||
"input": "totalErrors",
|
||||
"expected": "Total Errors"
|
||||
},
|
||||
{
|
||||
"desc": "capitalizes first letter",
|
||||
"input": "total",
|
||||
"expected": "Total"
|
||||
}
|
||||
],
|
||||
"formatValue": [
|
||||
{
|
||||
"desc": "formats small numbers as-is",
|
||||
"input": 42,
|
||||
"expected": "42"
|
||||
},
|
||||
{
|
||||
"desc": "formats thousands with K suffix",
|
||||
"input": 5000,
|
||||
"expected": "5.0K"
|
||||
},
|
||||
{
|
||||
"desc": "formats millions with M suffix",
|
||||
"input": 2500000,
|
||||
"expected": "2.5M"
|
||||
}
|
||||
],
|
||||
"createStatItems": [
|
||||
{
|
||||
"desc": "creates items from stats without config",
|
||||
"input": {
|
||||
"total": 100,
|
||||
"errors": 5
|
||||
},
|
||||
"expected_count": 2
|
||||
},
|
||||
{
|
||||
"desc": "creates items from stats with config",
|
||||
"input": {
|
||||
"total": 100,
|
||||
"errors": 5,
|
||||
"warnings": 10
|
||||
},
|
||||
"config": [
|
||||
{"key": "total", "label": "Total", "color": "white"},
|
||||
{"key": "errors", "label": "Errors", "color": "red"}
|
||||
],
|
||||
"expected_count": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
60
packages/stats_grid/seed/scripts/tests/stats.test.lua
Normal file
60
packages/stats_grid/seed/scripts/tests/stats.test.lua
Normal file
@@ -0,0 +1,60 @@
|
||||
-- Stats module tests
|
||||
-- Uses lua_test framework with parameterized test cases
|
||||
|
||||
describe("Stats Module", function()
|
||||
local cases = load_cases("stats.cases.json")
|
||||
local stats = require("stats")
|
||||
|
||||
describe("formatLabel", function()
|
||||
it_each(cases.formatLabel, "$desc", function(tc)
|
||||
local result = stats.formatLabel(tc.input)
|
||||
expect(result).toBe(tc.expected)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("formatValue", function()
|
||||
it_each(cases.formatValue, "$desc", function(tc)
|
||||
local result = stats.formatValue(tc.input)
|
||||
expect(result).toBe(tc.expected)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("createStatItems", function()
|
||||
it("creates items from stats data without config", function()
|
||||
local result = stats.createStatItems({ total = 100, errors = 5 }, nil)
|
||||
expect(#result).toBeGreaterThan(0)
|
||||
end)
|
||||
|
||||
it("creates items from stats data with config", function()
|
||||
local config = {
|
||||
{ key = "total", label = "Total", color = "white" },
|
||||
{ key = "errors", label = "Errors", color = "red" }
|
||||
}
|
||||
local result = stats.createStatItems({ total = 100, errors = 5 }, config)
|
||||
expect(#result).toBe(2)
|
||||
expect(result[1].key).toBe("total")
|
||||
expect(result[1].label).toBe("Total")
|
||||
expect(result[1].value).toBe(100)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("getColorClass", function()
|
||||
it("returns correct color class for valid colors", function()
|
||||
local redClass = stats.getColorClass("red")
|
||||
expect(redClass).toBe("text-red-400")
|
||||
end)
|
||||
|
||||
it("returns default for invalid colors", function()
|
||||
local defaultClass = stats.getColorClass("invalid")
|
||||
expect(defaultClass).toBeDefined()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("getDefaultGridClass", function()
|
||||
it("returns default grid class", function()
|
||||
local gridClass = stats.getDefaultGridClass()
|
||||
expect(gridClass).toBeDefined()
|
||||
expect(type(gridClass)).toBe("string")
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user