mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
code: packages,lua,ui (6 files)
This commit is contained in:
@@ -143,6 +143,7 @@ export { Cloud } from './Cloud'
|
||||
export { Terminal } from './Terminal'
|
||||
export { Archive } from './Archive'
|
||||
export { Bug } from './Bug'
|
||||
export { Gavel } from './Gavel'
|
||||
export { Clipboard } from './Clipboard'
|
||||
export { Package } from './Package'
|
||||
export { Layers } from './Layers'
|
||||
|
||||
@@ -119,7 +119,6 @@ function M.defineTests(framework, assertions, mocks)
|
||||
local beforeEach = framework.beforeEach
|
||||
local expect = assertions.expect
|
||||
local cases = load_cases("filters.cases.json")
|
||||
local cases = load_cases("filters.cases.json")
|
||||
|
||||
-- Import filter modules
|
||||
local filterByOperation = require("filters.filter_by_operation")
|
||||
@@ -145,20 +144,10 @@ function M.defineTests(framework, assertions, mocks)
|
||||
expect(#result).toBe(tc.expected)
|
||||
end)
|
||||
|
||||
it("should return all logs when operation is nil", function()
|
||||
local result = filterByOperation.filterByOperation(logs, nil)
|
||||
expect(#result).toBe(5)
|
||||
end)
|
||||
|
||||
it("should return all logs when operation is empty string", function()
|
||||
local result = filterByOperation.filterByOperation(logs, "")
|
||||
expect(#result).toBe(5)
|
||||
end)
|
||||
|
||||
it("should return empty array when logs is nil", function()
|
||||
local result = filterByOperation.filterByOperation(nil, "create")
|
||||
expect(#result).toBe(0)
|
||||
end)
|
||||
it("should return empty array when logs is nil", function()
|
||||
local result = filterByOperation.filterByOperation(nil, "create")
|
||||
expect(#result).toBe(0)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("filterByResource", function()
|
||||
@@ -174,11 +163,7 @@ function M.defineTests(framework, assertions, mocks)
|
||||
expect(#result).toBe(tc.expected)
|
||||
end)
|
||||
|
||||
it("should return all logs when resource is nil", function()
|
||||
local result = filterByResource.filterByResource(logs, nil)
|
||||
expect(#result).toBe(5)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("filterBySuccess", function()
|
||||
---@type AuditLogEntry[]
|
||||
@@ -196,11 +181,7 @@ function M.defineTests(framework, assertions, mocks)
|
||||
end
|
||||
end)
|
||||
|
||||
it("should return all logs when success is nil", function()
|
||||
local result = filterBySuccess.filterBySuccess(logs, nil)
|
||||
expect(#result).toBe(5)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("filterByUsername", function()
|
||||
---@type AuditLogEntry[]
|
||||
@@ -215,95 +196,51 @@ function M.defineTests(framework, assertions, mocks)
|
||||
expect(#result).toBe(tc.expected)
|
||||
end)
|
||||
|
||||
it("should return all logs when username is nil", function()
|
||||
local result = filterByUsername.filterByUsername(logs, nil)
|
||||
expect(#result).toBe(5)
|
||||
end)
|
||||
|
||||
it("should return all logs when username is empty string", function()
|
||||
local result = filterByUsername.filterByUsername(logs, "")
|
||||
expect(#result).toBe(5)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("filterByDateRange", function()
|
||||
local logs
|
||||
describe("filterByDateRange", function()
|
||||
---@type AuditLogEntry[]
|
||||
local logs
|
||||
|
||||
beforeEach(function()
|
||||
logs = createSampleLogs()
|
||||
end)
|
||||
|
||||
it_each({
|
||||
{ startTime = 1000000, endTime = 1200000, expected = 3 },
|
||||
{ startTime = 1200000, endTime = 1400000, expected = 3 },
|
||||
{ startTime = 1500000, endTime = 2000000, expected = 0 },
|
||||
{ startTime = nil, endTime = 1200000, expected = 3 },
|
||||
{ startTime = 1200000, endTime = nil, expected = 3 },
|
||||
{ startTime = nil, endTime = nil, expected = 5 }
|
||||
})("should filter correctly with startTime=$startTime, endTime=$endTime -> $expected", function(tc)
|
||||
local result = filterByDateRange.filterByDateRange(logs, tc.startTime, tc.endTime)
|
||||
expect(#result).toBe(tc.expected)
|
||||
end)
|
||||
it_each(cases.filter_by_date_range, "$desc", function(tc)
|
||||
local result = filterByDateRange.filterByDateRange(logs, tc.startTime, tc.endTime)
|
||||
expect(#result).toBe(tc.expected)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("applyFilters", function()
|
||||
local logs
|
||||
describe("applyFilters", function()
|
||||
---@type AuditLogEntry[]
|
||||
local logs
|
||||
|
||||
beforeEach(function()
|
||||
logs = createSampleLogs()
|
||||
end)
|
||||
|
||||
it("should apply operation filter only", function()
|
||||
local result = applyFilters.applyFilters(logs, { operation = "create" })
|
||||
expect(#result).toBe(2)
|
||||
end)
|
||||
it_each(cases.apply_filters, "$desc", function(tc)
|
||||
local result = applyFilters.applyFilters(logs, tc.filters)
|
||||
expect(#result).toBe(tc.expected)
|
||||
if tc.expectedFirstId then
|
||||
expect(result[1].id).toBe(tc.expectedFirstId)
|
||||
end
|
||||
end)
|
||||
|
||||
it("should apply multiple filters", function()
|
||||
local result = applyFilters.applyFilters(logs, {
|
||||
operation = "create",
|
||||
resource = "user"
|
||||
})
|
||||
expect(#result).toBe(1)
|
||||
expect(result[1].id).toBe("log1")
|
||||
end)
|
||||
|
||||
it("should apply success and username filters", function()
|
||||
local result = applyFilters.applyFilters(logs, {
|
||||
success = true,
|
||||
username = "admin"
|
||||
})
|
||||
expect(#result).toBe(2)
|
||||
end)
|
||||
|
||||
it("should apply date range with other filters", function()
|
||||
local result = applyFilters.applyFilters(logs, {
|
||||
startTime = 1000000,
|
||||
endTime = 1100000,
|
||||
success = true
|
||||
})
|
||||
expect(#result).toBe(2)
|
||||
end)
|
||||
|
||||
it("should return all logs with empty filters", function()
|
||||
local result = applyFilters.applyFilters(logs, {})
|
||||
expect(#result).toBe(5)
|
||||
end)
|
||||
|
||||
it("should handle nil filters", function()
|
||||
local result = applyFilters.applyFilters(logs, nil)
|
||||
expect(#result).toBe(5)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("getFilterOptions", function()
|
||||
local logs
|
||||
describe("getFilterOptions", function()
|
||||
---@type AuditLogEntry[]
|
||||
local logs
|
||||
|
||||
beforeEach(function()
|
||||
logs = createSampleLogs()
|
||||
end)
|
||||
|
||||
it("should extract unique operations", function()
|
||||
local options = getFilterOptions.getFilterOptions(logs)
|
||||
it("should extract unique operations", function()
|
||||
---@type FilterOptions
|
||||
local options = getFilterOptions.getFilterOptions(logs)
|
||||
expect(#options.operations).toBe(4)
|
||||
-- Should be sorted alphabetically
|
||||
expect(options.operations[1]).toBe("create")
|
||||
@@ -312,31 +249,35 @@ function M.defineTests(framework, assertions, mocks)
|
||||
expect(options.operations[4]).toBe("update")
|
||||
end)
|
||||
|
||||
it("should extract unique resources", function()
|
||||
local options = getFilterOptions.getFilterOptions(logs)
|
||||
it("should extract unique resources", function()
|
||||
---@type FilterOptions
|
||||
local options = getFilterOptions.getFilterOptions(logs)
|
||||
expect(#options.resources).toBe(3)
|
||||
expect(options.resources[1]).toBe("post")
|
||||
expect(options.resources[2]).toBe("settings")
|
||||
expect(options.resources[3]).toBe("user")
|
||||
end)
|
||||
|
||||
it("should extract unique usernames", function()
|
||||
local options = getFilterOptions.getFilterOptions(logs)
|
||||
it("should extract unique usernames", function()
|
||||
---@type FilterOptions
|
||||
local options = getFilterOptions.getFilterOptions(logs)
|
||||
expect(#options.usernames).toBe(4)
|
||||
-- Sorted: Admin_User, admin, editor, viewer
|
||||
expect(options.usernames[1]).toBe("Admin_User")
|
||||
expect(options.usernames[2]).toBe("admin")
|
||||
end)
|
||||
|
||||
it("should return empty arrays for nil logs", function()
|
||||
local options = getFilterOptions.getFilterOptions(nil)
|
||||
it("should return empty arrays for nil logs", function()
|
||||
---@type FilterOptions
|
||||
local options = getFilterOptions.getFilterOptions(nil)
|
||||
expect(#options.operations).toBe(0)
|
||||
expect(#options.resources).toBe(0)
|
||||
expect(#options.usernames).toBe(0)
|
||||
end)
|
||||
|
||||
it("should return empty arrays for empty logs", function()
|
||||
local options = getFilterOptions.getFilterOptions({})
|
||||
it("should return empty arrays for empty logs", function()
|
||||
---@type FilterOptions
|
||||
local options = getFilterOptions.getFilterOptions({})
|
||||
expect(#options.operations).toBe(0)
|
||||
expect(#options.resources).toBe(0)
|
||||
expect(#options.usernames).toBe(0)
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
-- Menu tests for nav_menu package
|
||||
-- Tests menu rendering and permission filtering
|
||||
|
||||
---@class MenuUser
|
||||
---@field level? number
|
||||
|
||||
---@class MenuItem
|
||||
---@field label string
|
||||
---@field path? string
|
||||
---@field minLevel? number
|
||||
---@field children? MenuItem[]
|
||||
|
||||
---@class MenuRenderProps
|
||||
---@field user MenuUser
|
||||
---@field items MenuItem[]
|
||||
|
||||
---@class MenuShowTestCase
|
||||
---@field user MenuUser
|
||||
---@field item MenuItem
|
||||
---@field expected boolean
|
||||
---@field desc string
|
||||
|
||||
describe("Menu", function()
|
||||
-- Mock check module
|
||||
local original_can_access
|
||||
|
||||
before(function()
|
||||
-- Menu tests for nav_menu package
|
||||
-- Tests menu rendering and permission filtering
|
||||
|
||||
---@class MenuUser
|
||||
---@field level? number
|
||||
|
||||
---@class MenuItem
|
||||
---@field label string
|
||||
---@field path? string
|
||||
---@field minLevel? number
|
||||
---@field children? MenuItem[]
|
||||
|
||||
---@class MenuRenderProps
|
||||
---@field user MenuUser
|
||||
---@field items MenuItem[]
|
||||
|
||||
---@class MenuShowTestCase
|
||||
---@field user MenuUser
|
||||
---@field item MenuItem
|
||||
---@field expected boolean
|
||||
---@field desc string
|
||||
|
||||
describe("Menu", function()
|
||||
-- Mock check module
|
||||
local original_can_access
|
||||
|
||||
before(function()
|
||||
-- Create mock for check.can_access
|
||||
package.loaded["check"] = {
|
||||
can_access = function(user, minLevel)
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
-- Render user profile card
|
||||
|
||||
---@class UIComponent
|
||||
---@field type string
|
||||
---@field props? table
|
||||
---@field children? UIComponent[]
|
||||
|
||||
---@class UserInfo
|
||||
---@field username string
|
||||
---@field email? string
|
||||
---@class UIComponent
|
||||
---@field type string
|
||||
---@field props? table
|
||||
---@field children? UIComponent[]
|
||||
|
||||
---@class InputProps
|
||||
---@field label string
|
||||
---@field value string
|
||||
---@field name? string
|
||||
---@field disabled? boolean
|
||||
|
||||
---@class ButtonProps
|
||||
---@field text string
|
||||
---@field onClick string
|
||||
|
||||
---@class UserInfo
|
||||
---@field username string
|
||||
---@field email? string
|
||||
|
||||
---@class RenderContext
|
||||
---@field user UserInfo
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
-- Re-exports all moderation functions for backward compatibility
|
||||
-- Each function is defined in its own file following 1-function-per-file pattern
|
||||
|
||||
---@class Moderation
|
||||
local M = {}
|
||||
---@class Moderation
|
||||
---@field deleteUser fun(userId: string): boolean
|
||||
---@field editUser fun(userId: string, updates: table): boolean
|
||||
---@field banUser fun(userId: string, reason: string): boolean
|
||||
local M = {}
|
||||
|
||||
-- Import all single-function modules
|
||||
local deleteUser = require("moderation.delete_user")
|
||||
|
||||
@@ -1,13 +1,31 @@
|
||||
-- Render function for schemas tab
|
||||
|
||||
---@class UIComponent
|
||||
---@field type string
|
||||
---@field props? table
|
||||
---@field children? UIComponent[]
|
||||
|
||||
---@class SchemaField
|
||||
---@field name string
|
||||
---@field type string
|
||||
---@class UIComponent
|
||||
---@field type string
|
||||
---@field props? table
|
||||
---@field children? UIComponent[]
|
||||
|
||||
---@class ButtonProps
|
||||
---@field text string
|
||||
---@field onClick string
|
||||
---@field data? string
|
||||
|
||||
---@class BadgeProps
|
||||
---@field text string
|
||||
|
||||
---@class TypographyProps
|
||||
---@field text string
|
||||
|
||||
---@class GridProps
|
||||
---@field cols number
|
||||
---@field gap number
|
||||
|
||||
---@class StackProps
|
||||
---@field spacing number
|
||||
|
||||
---@class SchemaField
|
||||
---@field name string
|
||||
---@field type string
|
||||
|
||||
---@class Schema
|
||||
---@field id string
|
||||
|
||||
Reference in New Issue
Block a user