From bfaa168702594f3de0aacc18b613d5a37aea720c Mon Sep 17 00:00:00 2001 From: Richard Ward Date: Tue, 30 Dec 2025 14:31:48 +0000 Subject: [PATCH] config: stats,packages,grid (3 files) --- .../seed/scripts/tests/formatters.cases.json | 26 ++++++++ .../seed/scripts/tests/stats.cases.json | 59 ++++++++++++++++++ .../seed/scripts/tests/stats.test.lua | 60 +++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 packages/stats_grid/seed/scripts/tests/formatters.cases.json create mode 100644 packages/stats_grid/seed/scripts/tests/stats.cases.json create mode 100644 packages/stats_grid/seed/scripts/tests/stats.test.lua diff --git a/packages/stats_grid/seed/scripts/tests/formatters.cases.json b/packages/stats_grid/seed/scripts/tests/formatters.cases.json new file mode 100644 index 000000000..85dec3bfb --- /dev/null +++ b/packages/stats_grid/seed/scripts/tests/formatters.cases.json @@ -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" + } + ] +} diff --git a/packages/stats_grid/seed/scripts/tests/stats.cases.json b/packages/stats_grid/seed/scripts/tests/stats.cases.json new file mode 100644 index 000000000..8bb972d2c --- /dev/null +++ b/packages/stats_grid/seed/scripts/tests/stats.cases.json @@ -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 + } + ] +} diff --git a/packages/stats_grid/seed/scripts/tests/stats.test.lua b/packages/stats_grid/seed/scripts/tests/stats.test.lua new file mode 100644 index 000000000..4da4b8dac --- /dev/null +++ b/packages/stats_grid/seed/scripts/tests/stats.test.lua @@ -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)