mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-26 14:54:55 +00:00
feat(tests): remove obsolete test files for dashboard, ui_login, ui_permissions, user_manager, and workflow_editor modules
This commit is contained in:
@@ -1,154 +0,0 @@
|
||||
-- Tests for dashboard stats.lua module
|
||||
|
||||
describe("dashboard/stats", function()
|
||||
local stats
|
||||
|
||||
beforeEach(function()
|
||||
stats = {
|
||||
calculate_percentage = function(value, total)
|
||||
if total == 0 then return 0 end
|
||||
return (value / total) * 100
|
||||
end,
|
||||
|
||||
calculate_change = function(current, previous)
|
||||
if previous == 0 then
|
||||
return current > 0 and 100 or 0
|
||||
end
|
||||
return ((current - previous) / previous) * 100
|
||||
end,
|
||||
|
||||
format_number = function(num)
|
||||
if num >= 1000000 then
|
||||
return string.format("%.1fM", num / 1000000)
|
||||
elseif num >= 1000 then
|
||||
return string.format("%.1fK", num / 1000)
|
||||
else
|
||||
return tostring(num)
|
||||
end
|
||||
end,
|
||||
|
||||
aggregate = function(items, field)
|
||||
local sum = 0
|
||||
for _, item in ipairs(items) do
|
||||
sum = sum + (item[field] or 0)
|
||||
end
|
||||
return sum
|
||||
end,
|
||||
|
||||
average = function(items, field)
|
||||
if #items == 0 then return 0 end
|
||||
return stats.aggregate(items, field) / #items
|
||||
end
|
||||
}
|
||||
end)
|
||||
|
||||
describe("calculate_percentage", function()
|
||||
it("should calculate correct percentage", function()
|
||||
expect(stats.calculate_percentage(25, 100)).toBe(25)
|
||||
end)
|
||||
|
||||
it("should handle decimal results", function()
|
||||
expect(stats.calculate_percentage(1, 3)).toBeCloseTo(33.33, 1)
|
||||
end)
|
||||
|
||||
it("should return 0 when total is 0", function()
|
||||
expect(stats.calculate_percentage(10, 0)).toBe(0)
|
||||
end)
|
||||
|
||||
it("should handle 100%", function()
|
||||
expect(stats.calculate_percentage(100, 100)).toBe(100)
|
||||
end)
|
||||
|
||||
it("should handle values greater than total", function()
|
||||
expect(stats.calculate_percentage(150, 100)).toBe(150)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("calculate_change", function()
|
||||
it("should calculate positive change", function()
|
||||
expect(stats.calculate_change(120, 100)).toBe(20)
|
||||
end)
|
||||
|
||||
it("should calculate negative change", function()
|
||||
expect(stats.calculate_change(80, 100)).toBe(-20)
|
||||
end)
|
||||
|
||||
it("should return 0 for no change", function()
|
||||
expect(stats.calculate_change(100, 100)).toBe(0)
|
||||
end)
|
||||
|
||||
it("should return 100 for growth from 0", function()
|
||||
expect(stats.calculate_change(50, 0)).toBe(100)
|
||||
end)
|
||||
|
||||
it("should return 0 for 0 to 0", function()
|
||||
expect(stats.calculate_change(0, 0)).toBe(0)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("format_number", function()
|
||||
it("should format millions", function()
|
||||
expect(stats.format_number(1500000)).toBe("1.5M")
|
||||
end)
|
||||
|
||||
it("should format thousands", function()
|
||||
expect(stats.format_number(2500)).toBe("2.5K")
|
||||
end)
|
||||
|
||||
it("should not format small numbers", function()
|
||||
expect(stats.format_number(999)).toBe("999")
|
||||
end)
|
||||
|
||||
it("should format exactly 1 million", function()
|
||||
expect(stats.format_number(1000000)).toBe("1.0M")
|
||||
end)
|
||||
|
||||
it("should format exactly 1 thousand", function()
|
||||
expect(stats.format_number(1000)).toBe("1.0K")
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("aggregate", function()
|
||||
it("should sum field values", function()
|
||||
local items = {
|
||||
{ value = 10 },
|
||||
{ value = 20 },
|
||||
{ value = 30 }
|
||||
}
|
||||
expect(stats.aggregate(items, "value")).toBe(60)
|
||||
end)
|
||||
|
||||
it("should handle empty array", function()
|
||||
expect(stats.aggregate({}, "value")).toBe(0)
|
||||
end)
|
||||
|
||||
it("should handle missing fields", function()
|
||||
local items = {
|
||||
{ value = 10 },
|
||||
{ other = 20 },
|
||||
{ value = 30 }
|
||||
}
|
||||
expect(stats.aggregate(items, "value")).toBe(40)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("average", function()
|
||||
it("should calculate average", function()
|
||||
local items = {
|
||||
{ score = 10 },
|
||||
{ score = 20 },
|
||||
{ score = 30 }
|
||||
}
|
||||
expect(stats.average(items, "score")).toBe(20)
|
||||
end)
|
||||
|
||||
it("should return 0 for empty array", function()
|
||||
expect(stats.average({}, "score")).toBe(0)
|
||||
end)
|
||||
|
||||
it("should handle single item", function()
|
||||
local items = {{ score = 50 }}
|
||||
expect(stats.average(items, "score")).toBe(50)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
@@ -1,182 +0,0 @@
|
||||
-- Tests for ui_login validate.lua module
|
||||
|
||||
describe("ui_login/validate", function()
|
||||
local validate
|
||||
|
||||
beforeEach(function()
|
||||
validate = {
|
||||
login = function(data)
|
||||
local errors = {}
|
||||
if not data.username or data.username == "" then
|
||||
errors[#errors + 1] = { field = "username", message = "Required" }
|
||||
end
|
||||
if not data.password or #data.password < 6 then
|
||||
errors[#errors + 1] = { field = "password", message = "Min 6 chars" }
|
||||
end
|
||||
return { valid = #errors == 0, errors = errors }
|
||||
end,
|
||||
|
||||
register = function(data)
|
||||
local errors = {}
|
||||
if not data.username or #data.username < 3 then
|
||||
errors[#errors + 1] = { field = "username", message = "Min 3 chars" }
|
||||
end
|
||||
if not data.email or not string.match(data.email, "^[^@]+@[^@]+%.[^@]+$") then
|
||||
errors[#errors + 1] = { field = "email", message = "Invalid email" }
|
||||
end
|
||||
if not data.password or #data.password < 8 then
|
||||
errors[#errors + 1] = { field = "password", message = "Min 8 chars" }
|
||||
end
|
||||
return { valid = #errors == 0, errors = errors }
|
||||
end
|
||||
}
|
||||
end)
|
||||
|
||||
describe("login validation", function()
|
||||
it("should reject empty username", function()
|
||||
local result = validate.login({ username = "", password = "password123" })
|
||||
expect(result.valid).toBe(false)
|
||||
expect(#result.errors).toBe(1)
|
||||
expect(result.errors[1].field).toBe("username")
|
||||
expect(result.errors[1].message).toBe("Required")
|
||||
end)
|
||||
|
||||
it("should reject nil username", function()
|
||||
local result = validate.login({ password = "password123" })
|
||||
expect(result.valid).toBe(false)
|
||||
expect(result.errors[1].field).toBe("username")
|
||||
end)
|
||||
|
||||
it("should reject short password", function()
|
||||
local result = validate.login({ username = "user", password = "12345" })
|
||||
expect(result.valid).toBe(false)
|
||||
expect(result.errors[1].field).toBe("password")
|
||||
expect(result.errors[1].message).toBe("Min 6 chars")
|
||||
end)
|
||||
|
||||
it("should reject nil password", function()
|
||||
local result = validate.login({ username = "user" })
|
||||
expect(result.valid).toBe(false)
|
||||
expect(result.errors[1].field).toBe("password")
|
||||
end)
|
||||
|
||||
it("should accept password with exactly 6 chars", function()
|
||||
local result = validate.login({ username = "user", password = "123456" })
|
||||
expect(result.valid).toBe(true)
|
||||
expect(#result.errors).toBe(0)
|
||||
end)
|
||||
|
||||
it("should accept valid credentials", function()
|
||||
local result = validate.login({ username = "user", password = "password123" })
|
||||
expect(result.valid).toBe(true)
|
||||
expect(#result.errors).toBe(0)
|
||||
end)
|
||||
|
||||
it("should report multiple errors", function()
|
||||
local result = validate.login({ username = "", password = "123" })
|
||||
expect(result.valid).toBe(false)
|
||||
expect(#result.errors).toBe(2)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("register validation", function()
|
||||
it("should reject short username", function()
|
||||
local result = validate.register({
|
||||
username = "ab",
|
||||
email = "test@example.com",
|
||||
password = "password123"
|
||||
})
|
||||
expect(result.valid).toBe(false)
|
||||
expect(result.errors[1].field).toBe("username")
|
||||
expect(result.errors[1].message).toBe("Min 3 chars")
|
||||
end)
|
||||
|
||||
it("should accept username with exactly 3 chars", function()
|
||||
local result = validate.register({
|
||||
username = "abc",
|
||||
email = "test@example.com",
|
||||
password = "password123"
|
||||
})
|
||||
expect(result.valid).toBe(true)
|
||||
end)
|
||||
|
||||
it("should reject invalid email without @", function()
|
||||
local result = validate.register({
|
||||
username = "user",
|
||||
email = "invalid-email",
|
||||
password = "password123"
|
||||
})
|
||||
expect(result.valid).toBe(false)
|
||||
expect(result.errors[1].field).toBe("email")
|
||||
end)
|
||||
|
||||
it("should reject invalid email without domain", function()
|
||||
local result = validate.register({
|
||||
username = "user",
|
||||
email = "test@",
|
||||
password = "password123"
|
||||
})
|
||||
expect(result.valid).toBe(false)
|
||||
expect(result.errors[1].field).toBe("email")
|
||||
end)
|
||||
|
||||
it("should reject invalid email without TLD", function()
|
||||
local result = validate.register({
|
||||
username = "user",
|
||||
email = "test@example",
|
||||
password = "password123"
|
||||
})
|
||||
expect(result.valid).toBe(false)
|
||||
expect(result.errors[1].field).toBe("email")
|
||||
end)
|
||||
|
||||
it("should accept valid email", function()
|
||||
local result = validate.register({
|
||||
username = "user",
|
||||
email = "test@example.com",
|
||||
password = "password123"
|
||||
})
|
||||
expect(result.valid).toBe(true)
|
||||
end)
|
||||
|
||||
it("should reject short password (< 8 chars)", function()
|
||||
local result = validate.register({
|
||||
username = "user",
|
||||
email = "test@example.com",
|
||||
password = "1234567"
|
||||
})
|
||||
expect(result.valid).toBe(false)
|
||||
expect(result.errors[1].field).toBe("password")
|
||||
expect(result.errors[1].message).toBe("Min 8 chars")
|
||||
end)
|
||||
|
||||
it("should accept password with exactly 8 chars", function()
|
||||
local result = validate.register({
|
||||
username = "user",
|
||||
email = "test@example.com",
|
||||
password = "12345678"
|
||||
})
|
||||
expect(result.valid).toBe(true)
|
||||
end)
|
||||
|
||||
it("should accept valid registration data", function()
|
||||
local result = validate.register({
|
||||
username = "testuser",
|
||||
email = "test@example.com",
|
||||
password = "securepassword123"
|
||||
})
|
||||
expect(result.valid).toBe(true)
|
||||
expect(#result.errors).toBe(0)
|
||||
end)
|
||||
|
||||
it("should report all validation errors", function()
|
||||
local result = validate.register({
|
||||
username = "ab",
|
||||
email = "invalid",
|
||||
password = "short"
|
||||
})
|
||||
expect(result.valid).toBe(false)
|
||||
expect(#result.errors).toBe(3)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
@@ -1,147 +0,0 @@
|
||||
-- Tests for ui_permissions check.lua module
|
||||
|
||||
describe("ui_permissions/check", function()
|
||||
local LEVELS = {
|
||||
PUBLIC = 1,
|
||||
USER = 2,
|
||||
MODERATOR = 3,
|
||||
ADMIN = 4,
|
||||
GOD = 5,
|
||||
SUPERGOD = 6
|
||||
}
|
||||
|
||||
local check
|
||||
|
||||
beforeEach(function()
|
||||
-- Mock the check module inline for testing
|
||||
local ROLE_MAP = {
|
||||
public = LEVELS.PUBLIC,
|
||||
user = LEVELS.USER,
|
||||
moderator = LEVELS.MODERATOR,
|
||||
admin = LEVELS.ADMIN,
|
||||
god = LEVELS.GOD,
|
||||
supergod = LEVELS.SUPERGOD
|
||||
}
|
||||
|
||||
check = {
|
||||
get_level = function(user)
|
||||
if not user then return LEVELS.PUBLIC end
|
||||
return ROLE_MAP[user.role] or LEVELS.PUBLIC
|
||||
end,
|
||||
|
||||
can_access = function(user, required_level)
|
||||
return check.get_level(user) >= required_level
|
||||
end,
|
||||
|
||||
is_moderator_or_above = function(user)
|
||||
return check.get_level(user) >= LEVELS.MODERATOR
|
||||
end,
|
||||
|
||||
is_admin_or_above = function(user)
|
||||
return check.get_level(user) >= LEVELS.ADMIN
|
||||
end
|
||||
}
|
||||
end)
|
||||
|
||||
describe("get_level", function()
|
||||
it("should return PUBLIC for nil user", function()
|
||||
expect(check.get_level(nil)).toBe(LEVELS.PUBLIC)
|
||||
end)
|
||||
|
||||
it("should return PUBLIC for user without role", function()
|
||||
expect(check.get_level({})).toBe(LEVELS.PUBLIC)
|
||||
end)
|
||||
|
||||
it("should return USER level for user role", function()
|
||||
expect(check.get_level({ role = "user" })).toBe(LEVELS.USER)
|
||||
end)
|
||||
|
||||
it("should return MODERATOR level for moderator role", function()
|
||||
expect(check.get_level({ role = "moderator" })).toBe(LEVELS.MODERATOR)
|
||||
end)
|
||||
|
||||
it("should return ADMIN level for admin role", function()
|
||||
expect(check.get_level({ role = "admin" })).toBe(LEVELS.ADMIN)
|
||||
end)
|
||||
|
||||
it("should return GOD level for god role", function()
|
||||
expect(check.get_level({ role = "god" })).toBe(LEVELS.GOD)
|
||||
end)
|
||||
|
||||
it("should return SUPERGOD level for supergod role", function()
|
||||
expect(check.get_level({ role = "supergod" })).toBe(LEVELS.SUPERGOD)
|
||||
end)
|
||||
|
||||
it("should return PUBLIC for unknown role", function()
|
||||
expect(check.get_level({ role = "unknown" })).toBe(LEVELS.PUBLIC)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("can_access", function()
|
||||
it("should allow user to access user-level content", function()
|
||||
local user = { role = "user" }
|
||||
expect(check.can_access(user, LEVELS.USER)).toBe(true)
|
||||
end)
|
||||
|
||||
it("should deny user access to admin-level content", function()
|
||||
local user = { role = "user" }
|
||||
expect(check.can_access(user, LEVELS.ADMIN)).toBe(false)
|
||||
end)
|
||||
|
||||
it("should allow admin to access user-level content", function()
|
||||
local user = { role = "admin" }
|
||||
expect(check.can_access(user, LEVELS.USER)).toBe(true)
|
||||
end)
|
||||
|
||||
it("should allow supergod to access any content", function()
|
||||
local user = { role = "supergod" }
|
||||
expect(check.can_access(user, LEVELS.SUPERGOD)).toBe(true)
|
||||
expect(check.can_access(user, LEVELS.GOD)).toBe(true)
|
||||
expect(check.can_access(user, LEVELS.ADMIN)).toBe(true)
|
||||
end)
|
||||
|
||||
it("should allow public access for nil user", function()
|
||||
expect(check.can_access(nil, LEVELS.PUBLIC)).toBe(true)
|
||||
end)
|
||||
|
||||
it("should deny user access for nil user", function()
|
||||
expect(check.can_access(nil, LEVELS.USER)).toBe(false)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("is_moderator_or_above", function()
|
||||
it("should return false for regular user", function()
|
||||
expect(check.is_moderator_or_above({ role = "user" })).toBe(false)
|
||||
end)
|
||||
|
||||
it("should return true for moderator", function()
|
||||
expect(check.is_moderator_or_above({ role = "moderator" })).toBe(true)
|
||||
end)
|
||||
|
||||
it("should return true for admin", function()
|
||||
expect(check.is_moderator_or_above({ role = "admin" })).toBe(true)
|
||||
end)
|
||||
|
||||
it("should return true for god", function()
|
||||
expect(check.is_moderator_or_above({ role = "god" })).toBe(true)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("is_admin_or_above", function()
|
||||
it("should return false for moderator", function()
|
||||
expect(check.is_admin_or_above({ role = "moderator" })).toBe(false)
|
||||
end)
|
||||
|
||||
it("should return true for admin", function()
|
||||
expect(check.is_admin_or_above({ role = "admin" })).toBe(true)
|
||||
end)
|
||||
|
||||
it("should return true for god", function()
|
||||
expect(check.is_admin_or_above({ role = "god" })).toBe(true)
|
||||
end)
|
||||
|
||||
it("should return true for supergod", function()
|
||||
expect(check.is_admin_or_above({ role = "supergod" })).toBe(true)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
@@ -1,56 +0,0 @@
|
||||
-- Tests for ui_permissions levels.lua module
|
||||
|
||||
describe("ui_permissions/levels", function()
|
||||
local LEVELS = {
|
||||
PUBLIC = 1,
|
||||
USER = 2,
|
||||
MODERATOR = 3,
|
||||
ADMIN = 4,
|
||||
GOD = 5,
|
||||
SUPERGOD = 6
|
||||
}
|
||||
|
||||
describe("level values", function()
|
||||
it("should have PUBLIC as lowest level (1)", function()
|
||||
expect(LEVELS.PUBLIC).toBe(1)
|
||||
end)
|
||||
|
||||
it("should have USER as level 2", function()
|
||||
expect(LEVELS.USER).toBe(2)
|
||||
end)
|
||||
|
||||
it("should have MODERATOR as level 3", function()
|
||||
expect(LEVELS.MODERATOR).toBe(3)
|
||||
end)
|
||||
|
||||
it("should have ADMIN as level 4", function()
|
||||
expect(LEVELS.ADMIN).toBe(4)
|
||||
end)
|
||||
|
||||
it("should have GOD as level 5", function()
|
||||
expect(LEVELS.GOD).toBe(5)
|
||||
end)
|
||||
|
||||
it("should have SUPERGOD as highest level (6)", function()
|
||||
expect(LEVELS.SUPERGOD).toBe(6)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("level hierarchy", function()
|
||||
it("should have ascending order from PUBLIC to SUPERGOD", function()
|
||||
expect(LEVELS.PUBLIC).toBeLessThan(LEVELS.USER)
|
||||
expect(LEVELS.USER).toBeLessThan(LEVELS.MODERATOR)
|
||||
expect(LEVELS.MODERATOR).toBeLessThan(LEVELS.ADMIN)
|
||||
expect(LEVELS.ADMIN).toBeLessThan(LEVELS.GOD)
|
||||
expect(LEVELS.GOD).toBeLessThan(LEVELS.SUPERGOD)
|
||||
end)
|
||||
|
||||
it("should have exactly 6 levels", function()
|
||||
local count = 0
|
||||
for _ in pairs(LEVELS) do
|
||||
count = count + 1
|
||||
end
|
||||
expect(count).toBe(6)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
@@ -1,130 +0,0 @@
|
||||
-- Tests for user_manager actions.lua module
|
||||
|
||||
describe("user_manager/actions", function()
|
||||
local actions
|
||||
|
||||
beforeEach(function()
|
||||
actions = {
|
||||
create = function(data)
|
||||
return {
|
||||
action = "create_user",
|
||||
data = data
|
||||
}
|
||||
end,
|
||||
|
||||
update = function(user_id, data)
|
||||
return {
|
||||
action = "update_user",
|
||||
user_id = user_id,
|
||||
data = data
|
||||
}
|
||||
end,
|
||||
|
||||
delete = function(user_id)
|
||||
return {
|
||||
action = "delete_user",
|
||||
user_id = user_id,
|
||||
confirm = true
|
||||
}
|
||||
end,
|
||||
|
||||
change_level = function(user_id, new_level)
|
||||
return {
|
||||
action = "change_level",
|
||||
user_id = user_id,
|
||||
level = new_level
|
||||
}
|
||||
end,
|
||||
|
||||
toggle_active = function(user_id, active)
|
||||
return {
|
||||
action = "toggle_active",
|
||||
user_id = user_id,
|
||||
active = active
|
||||
}
|
||||
end
|
||||
}
|
||||
end)
|
||||
|
||||
describe("create", function()
|
||||
it("should return create_user action", function()
|
||||
local result = actions.create({ name = "John", email = "john@example.com" })
|
||||
expect(result.action).toBe("create_user")
|
||||
end)
|
||||
|
||||
it("should include user data", function()
|
||||
local data = { name = "John", email = "john@example.com" }
|
||||
local result = actions.create(data)
|
||||
expect(result.data).toEqual(data)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("update", function()
|
||||
it("should return update_user action", function()
|
||||
local result = actions.update("user-123", { name = "Jane" })
|
||||
expect(result.action).toBe("update_user")
|
||||
end)
|
||||
|
||||
it("should include user_id", function()
|
||||
local result = actions.update("user-123", { name = "Jane" })
|
||||
expect(result.user_id).toBe("user-123")
|
||||
end)
|
||||
|
||||
it("should include update data", function()
|
||||
local data = { name = "Jane", role = "admin" }
|
||||
local result = actions.update("user-123", data)
|
||||
expect(result.data).toEqual(data)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("delete", function()
|
||||
it("should return delete_user action", function()
|
||||
local result = actions.delete("user-123")
|
||||
expect(result.action).toBe("delete_user")
|
||||
end)
|
||||
|
||||
it("should include user_id", function()
|
||||
local result = actions.delete("user-123")
|
||||
expect(result.user_id).toBe("user-123")
|
||||
end)
|
||||
|
||||
it("should require confirmation", function()
|
||||
local result = actions.delete("user-123")
|
||||
expect(result.confirm).toBe(true)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("change_level", function()
|
||||
it("should return change_level action", function()
|
||||
local result = actions.change_level("user-123", 4)
|
||||
expect(result.action).toBe("change_level")
|
||||
end)
|
||||
|
||||
it("should include user_id", function()
|
||||
local result = actions.change_level("user-123", 4)
|
||||
expect(result.user_id).toBe("user-123")
|
||||
end)
|
||||
|
||||
it("should include new level", function()
|
||||
local result = actions.change_level("user-123", 4)
|
||||
expect(result.level).toBe(4)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("toggle_active", function()
|
||||
it("should return toggle_active action", function()
|
||||
local result = actions.toggle_active("user-123", true)
|
||||
expect(result.action).toBe("toggle_active")
|
||||
end)
|
||||
|
||||
it("should set active to true", function()
|
||||
local result = actions.toggle_active("user-123", true)
|
||||
expect(result.active).toBe(true)
|
||||
end)
|
||||
|
||||
it("should set active to false", function()
|
||||
local result = actions.toggle_active("user-123", false)
|
||||
expect(result.active).toBe(false)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
@@ -1,139 +0,0 @@
|
||||
-- Tests for workflow_editor status.lua module
|
||||
|
||||
describe("workflow_editor/status", function()
|
||||
local status
|
||||
|
||||
beforeEach(function()
|
||||
status = {
|
||||
PENDING = "pending",
|
||||
RUNNING = "running",
|
||||
SUCCESS = "success",
|
||||
FAILED = "failed",
|
||||
CANCELLED = "cancelled",
|
||||
|
||||
render_badge = function(s)
|
||||
local colors = {
|
||||
pending = "default",
|
||||
running = "info",
|
||||
success = "success",
|
||||
failed = "error",
|
||||
cancelled = "warning"
|
||||
}
|
||||
return {
|
||||
type = "badge",
|
||||
props = {
|
||||
label = s,
|
||||
color = colors[s] or "default"
|
||||
}
|
||||
}
|
||||
end,
|
||||
|
||||
render_progress = function(completed, total)
|
||||
local percent = total > 0 and (completed / total * 100) or 0
|
||||
return {
|
||||
type = "progress",
|
||||
props = {
|
||||
value = percent,
|
||||
label = completed .. "/" .. total
|
||||
}
|
||||
}
|
||||
end
|
||||
}
|
||||
end)
|
||||
|
||||
describe("status constants", function()
|
||||
it("should have PENDING status", function()
|
||||
expect(status.PENDING).toBe("pending")
|
||||
end)
|
||||
|
||||
it("should have RUNNING status", function()
|
||||
expect(status.RUNNING).toBe("running")
|
||||
end)
|
||||
|
||||
it("should have SUCCESS status", function()
|
||||
expect(status.SUCCESS).toBe("success")
|
||||
end)
|
||||
|
||||
it("should have FAILED status", function()
|
||||
expect(status.FAILED).toBe("failed")
|
||||
end)
|
||||
|
||||
it("should have CANCELLED status", function()
|
||||
expect(status.CANCELLED).toBe("cancelled")
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("render_badge", function()
|
||||
it("should return badge component", function()
|
||||
local result = status.render_badge("pending")
|
||||
expect(result.type).toBe("badge")
|
||||
end)
|
||||
|
||||
it("should have label in props", function()
|
||||
local result = status.render_badge("success")
|
||||
expect(result.props.label).toBe("success")
|
||||
end)
|
||||
|
||||
it("should map pending to default color", function()
|
||||
local result = status.render_badge("pending")
|
||||
expect(result.props.color).toBe("default")
|
||||
end)
|
||||
|
||||
it("should map running to info color", function()
|
||||
local result = status.render_badge("running")
|
||||
expect(result.props.color).toBe("info")
|
||||
end)
|
||||
|
||||
it("should map success to success color", function()
|
||||
local result = status.render_badge("success")
|
||||
expect(result.props.color).toBe("success")
|
||||
end)
|
||||
|
||||
it("should map failed to error color", function()
|
||||
local result = status.render_badge("failed")
|
||||
expect(result.props.color).toBe("error")
|
||||
end)
|
||||
|
||||
it("should map cancelled to warning color", function()
|
||||
local result = status.render_badge("cancelled")
|
||||
expect(result.props.color).toBe("warning")
|
||||
end)
|
||||
|
||||
it("should use default for unknown status", function()
|
||||
local result = status.render_badge("unknown")
|
||||
expect(result.props.color).toBe("default")
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("render_progress", function()
|
||||
it("should return progress component", function()
|
||||
local result = status.render_progress(5, 10)
|
||||
expect(result.type).toBe("progress")
|
||||
end)
|
||||
|
||||
it("should calculate percentage", function()
|
||||
local result = status.render_progress(5, 10)
|
||||
expect(result.props.value).toBe(50)
|
||||
end)
|
||||
|
||||
it("should format label", function()
|
||||
local result = status.render_progress(5, 10)
|
||||
expect(result.props.label).toBe("5/10")
|
||||
end)
|
||||
|
||||
it("should handle 0 total", function()
|
||||
local result = status.render_progress(0, 0)
|
||||
expect(result.props.value).toBe(0)
|
||||
end)
|
||||
|
||||
it("should handle 100%", function()
|
||||
local result = status.render_progress(10, 10)
|
||||
expect(result.props.value).toBe(100)
|
||||
end)
|
||||
|
||||
it("should handle 0 completed", function()
|
||||
local result = status.render_progress(0, 10)
|
||||
expect(result.props.value).toBe(0)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user