mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-16 16:30:42 +09:00
Address review on exp_server_list
The controller and instance plugins are init functions with closures. The controller batches refreshes with setMany and deleteMany, and the instance gates updates on its status instead of a started flag. short_name is now display_name. New always_on_top field sorts servers first in get_servers. The record carries has_password from the game password in factorio.settings, never the password itself, and the description falls back to the one in factorio.settings. A controller welcome is used when the instance has none, and the readme falls back to a default welcome from the locale. Lua gets is_synced for connect.lua. The readme passes an empty detail instead of nil to the join tooltip so the player count stays in __2__, restores the Password status, shows the welcome title as a centered label and shortens long descriptions with the full text as a tooltip. The Lua tests assert the lookups they index, which fixes the lint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4d136853c9
commit
c0289ed8a7
15 files changed
+528
-418
No files matched your search
@@ -1,19 +1,27 @@
|
||||
local Suite = ... --- @type Suite<ExpServerList.TestEnv>
|
||||
|
||||
Suite.test("nothing is known before the first update", function(env)
|
||||
Suite.eq(env.ServerList.is_synced(), false, "not synced")
|
||||
Suite.eq(env.ServerList.get_current(), nil, "no current server")
|
||||
Suite.empty(env.ServerList.get_servers(), "no servers")
|
||||
end)
|
||||
|
||||
Suite.test("is_synced() is true once the list arrives, even without this server in it", function(env)
|
||||
local List = env.ServerList
|
||||
List.receive_update{ current_id = 5, replace = true, servers = { env.server(1) } }
|
||||
Suite.eq(List.is_synced(), true, "synced")
|
||||
Suite.eq(List.get_current(), nil, "this server is not in the list")
|
||||
end)
|
||||
|
||||
Suite.test("receive_update() with replace swaps the whole list", function(env)
|
||||
local List = env.ServerList
|
||||
List.receive_update{ current_id = 1, replace = true, servers = { env.server(1), env.server(2) } }
|
||||
List.receive_update{ current_id = 1, replace = true, servers = { env.server(1), env.server(3) } }
|
||||
|
||||
Suite.eq(List.get_current().id, 1, "the current server is set")
|
||||
Suite.eq(assert(List.get_current()).id, 1, "the current server is set")
|
||||
Suite.eq(List.get_server(2), nil, "servers missing from the new list are removed")
|
||||
Suite.eq(List.get_server(3).name, "Server 3", "new servers are added")
|
||||
local ids = env.events[2].server_ids
|
||||
Suite.eq(assert(List.get_server(3)).name, "Server 3", "new servers are added")
|
||||
local ids = assert(env.events[2]).server_ids
|
||||
table.sort(ids)
|
||||
Suite.eq(ids, { 1, 2, 3 }, "the event lists removed and added servers")
|
||||
end)
|
||||
@@ -26,13 +34,13 @@ Suite.test("receive_update() without replace changes only the given servers", fu
|
||||
{ id = 3, is_deleted = true },
|
||||
} }
|
||||
|
||||
Suite.eq(List.get_server(1).name, "Server 1", "untouched servers stay")
|
||||
Suite.eq(List.get_server(2).player_count, 4, "changed servers are replaced")
|
||||
Suite.eq(assert(List.get_server(1)).name, "Server 1", "untouched servers stay")
|
||||
Suite.eq(assert(List.get_server(2)).player_count, 4, "changed servers are replaced")
|
||||
Suite.eq(List.get_server(3), nil, "deleted servers are removed")
|
||||
local ids = env.events[2].server_ids
|
||||
local ids = assert(env.events[2]).server_ids
|
||||
table.sort(ids)
|
||||
Suite.eq(ids, { 2, 3 }, "the event lists only the given servers")
|
||||
Suite.eq(env.events[2].name, List.on_servers_updated, "on_servers_updated is raised")
|
||||
Suite.eq(assert(env.events[2]).name, List.on_servers_updated, "on_servers_updated is raised")
|
||||
end)
|
||||
|
||||
Suite.test("get_servers() leaves out hidden servers and sorts by name", function(env)
|
||||
@@ -48,15 +56,31 @@ Suite.test("get_servers() leaves out hidden servers and sorts by name", function
|
||||
names[index] = server.name
|
||||
end
|
||||
Suite.eq(names, { "Alpha", "Charlie" }, "hidden servers are not listed")
|
||||
Suite.eq(List.get_server(3).name, "Bravo", "but can still be looked up by id")
|
||||
Suite.eq(assert(List.get_server(3)).name, "Bravo", "but can still be looked up by id")
|
||||
end)
|
||||
|
||||
Suite.test("find_servers() matches name, short name and id ignoring case", function(env)
|
||||
Suite.test("get_servers() puts servers always on top first", function(env)
|
||||
local List = env.ServerList
|
||||
List.receive_update{ current_id = 1, replace = true, servers = {
|
||||
env.server(1, { name = "Public Weekly", short_name = "S1" }),
|
||||
env.server(2, { name = "Modded", short_name = "S2" }),
|
||||
env.server(37, { name = "Event", short_name = "Event" }),
|
||||
env.server(1, { name = "Alpha" }),
|
||||
env.server(2, { name = "Delta", always_on_top = true }),
|
||||
env.server(3, { name = "Bravo" }),
|
||||
env.server(4, { name = "Charlie", always_on_top = true }),
|
||||
} }
|
||||
|
||||
local names = {}
|
||||
for index, server in ipairs(List.get_servers()) do
|
||||
names[index] = server.name
|
||||
end
|
||||
Suite.eq(names, { "Charlie", "Delta", "Alpha", "Bravo" }, "on top by name, then the rest by name")
|
||||
end)
|
||||
|
||||
Suite.test("find_servers() matches name, display name and id ignoring case", function(env)
|
||||
local List = env.ServerList
|
||||
List.receive_update{ current_id = 1, replace = true, servers = {
|
||||
env.server(1, { name = "Public Weekly", display_name = "S1" }),
|
||||
env.server(2, { name = "Modded", display_name = "S2" }),
|
||||
env.server(37, { name = "Event", display_name = "Event" }),
|
||||
} }
|
||||
|
||||
local function ids(search)
|
||||
@@ -68,7 +92,7 @@ Suite.test("find_servers() matches name, short name and id ignoring case", funct
|
||||
end
|
||||
|
||||
Suite.eq(ids("weekly"), { 1 }, "by name")
|
||||
Suite.eq(ids("s2"), { 2 }, "by short name")
|
||||
Suite.eq(ids("s2"), { 2 }, "by display name")
|
||||
Suite.eq(ids("37"), { 37 }, "by id")
|
||||
Suite.eq(ids("nothing"), {}, "no match")
|
||||
end)
|
||||
|
||||
Reference in new issue
Block a user