141 lines
7.2 KiB
Lua
141 lines
7.2 KiB
Lua
-- Focused check of the transformed SuperDistrict screen with a stub Source snapshot.
|
|
-- Usage: luajit tests/source_realm_district_test.lua <transformed superdistrict.lua>
|
|
local path = assert(arg[1], "transformed superdistrict.lua required");
|
|
|
|
local function text() local t = {value = nil}; function t:SetText(v) self.value = v; end; function t:GetText() return self.value; end; return t; end
|
|
local function widget()
|
|
local w = {shown = true, enabled = true};
|
|
function w:SetShown(v) self.shown = v; end
|
|
function w:Hide() self.shown = false; end
|
|
function w:Show() self.shown = true; end
|
|
function w:SetEnabled(v) self.enabled = v; end
|
|
function w:SetDisabledTooltip(v) self.tooltip = v; end
|
|
function w:SetText(v) self.value = v; end
|
|
function w:GetText() return self.value; end
|
|
function w:SetWidth() end
|
|
function w:SetupMenu() end
|
|
function w:Layout() end
|
|
return w;
|
|
end
|
|
|
|
local snapshot = {abi=1, size=64, generation=7, endpoint_kind=0, state=5, error=0, auth_result=0,
|
|
discovery_result=0, server_proof_verified=1, realm_count=2, selected_index=-1, transport_prepared=0,
|
|
cancel=0, genuine_discovery=1, auth_port=3724, copied_realms=2,
|
|
r0={name="Octo", address="185.246.188.177:8085", type=1, flags=0, characters=3, category=1, wire_id=1, population_text="1.5"},
|
|
r1={name="Octo Test", address="185.246.188.177:8086", type=0, flags=2, characters=0, category=1, wire_id=2, population_text="0.2"}};
|
|
local requests = {};
|
|
local connected = false;
|
|
local subRegions = {};
|
|
cancels, disconnects = 0, 0;
|
|
C_Login = {
|
|
GetTurtleRealmSnapshot = function(q) if q == 4 then cancels = cancels + 1; return 0; end return snapshot; end,
|
|
GetState = function() return {connectedToWoW = connected}; end,
|
|
DisconnectFromServer = function() disconnects = disconnects + 1; end,
|
|
RequestTurtleRealm = function(i, g) requests[#requests + 1] = {i, g}; return 0; end,
|
|
GetSubRegions = function() return subRegions; end,
|
|
GetCurrentSubRegion = function() end, SetCurrentSubRegion = function() end,
|
|
};
|
|
C_DistrictUtils = {GetAvailableSuperDistricts = function() return {}; end};
|
|
local callbacks = {};
|
|
EventRegistry = {
|
|
RegisterCallback = function(_, event, callback, owner)
|
|
callbacks[event] = function(...) callback(owner, ...); end;
|
|
end,
|
|
TriggerEvent = function(_, event, ...)
|
|
if callbacks[event] then callbacks[event](...); end
|
|
end,
|
|
};
|
|
function SetLoginScreenModel() end
|
|
function CreateFromMixins(...) local r = {}; for _, m in ipairs({...}) do for k, v in pairs(m) do r[k] = v; end end; return r; end
|
|
SelectableButtonMixin, DisabledTooltipButtonMixin = {}, {};
|
|
local popups = {};
|
|
function StaticPopup_Show(...) popups[#popups + 1] = {...}; end
|
|
NarrationUtil = {RegionToNarrationInfo = function() end};
|
|
SOUNDKIT = {}; function PlaySound() end
|
|
|
|
local chunk = assert(loadfile(path)); chunk();
|
|
|
|
local frame = CreateFromMixins(SuperDistrictMixin);
|
|
frame.Title, frame.Description = text(), text();
|
|
frame.Title:SetText("SUPER_DISTRICT_TITLE"); frame.Description:SetText("SUPER_DISTRICT_DESCRIPTION");
|
|
frame.SelectButton, frame.SubRegionDropdown, frame.ButtonLayout = widget(), widget(), widget();
|
|
frame.SelectButton:SetText("Select");
|
|
function frame:RegisterEvent() end
|
|
local hooked; function frame:HookScript(name, fn) hooked = fn; end
|
|
local acquired = {};
|
|
frame.districtButtonPool = nil;
|
|
function CreateFramePoolCollection()
|
|
return {CreatePool = function() end, ReleaseAll = function() acquired = {}; end,
|
|
Acquire = function()
|
|
local b = CreateFromMixins(SuperDistrictButtonMixin, widget());
|
|
b.Title, b.Description = text(), text();
|
|
b.Icon = {SetTexture = function() end, GetTexture = function() end, SetDesaturated = function() end};
|
|
b.Background, b.Circle = {SetDesaturated = function() end}, {SetDesaturated = function() end};
|
|
function b:SetAlpha(v) self.alpha = v; end
|
|
function b:SetMotionScriptsWhileDisabled() end
|
|
function b:SetScript() end
|
|
function b:SetChecked(v) self.checked = v; end
|
|
acquired[#acquired + 1] = b; return b;
|
|
end};
|
|
end
|
|
|
|
frame:OnLoad();
|
|
assert(hooked, "poll hook installed");
|
|
assert(frame.Title:GetText() == "Choose Your Realm", frame.Title:GetText());
|
|
assert(frame.SelectButton:GetText() == "Enter Realm");
|
|
assert(#frame.districtButtons == 2, "two realm buttons");
|
|
local a, b = frame.districtButtons[1], frame.districtButtons[2];
|
|
assert(a.Title:GetText() == "Octo" and a.enabled, "online realm readable and enabled");
|
|
assert(a.Description:GetText():find("PvP realm") and a.Description:GetText():find("Population: High")
|
|
and a.Description:GetText():find("3 characters"), a.Description:GetText());
|
|
assert(b.Title:GetText() == "Octo Test" and not b.enabled and b.Description:GetText() == "Offline");
|
|
assert(frame.SelectButton.enabled == false, "no implicit selection");
|
|
|
|
-- Cancel while the choice is pending retires the Source login, then keeps the
|
|
-- original disconnect path back to the login screen.
|
|
frame:OnCancel();
|
|
assert(cancels == 1 and disconnects == 1, "cancel retires Source and disconnects");
|
|
|
|
frame:UpdateSelection(a.superDistrictID);
|
|
assert(frame.SelectButton.enabled == true);
|
|
frame:ConfirmSuperDistrict();
|
|
assert(#requests == 1 and requests[1][1] == 0 and requests[1][2] == 7, "request index0 generation7");
|
|
assert(frame.Description:GetText() == "Connecting to Octo...");
|
|
|
|
-- A selected realm can be prepared before the native connection is up.
|
|
snapshot.state, snapshot.selected_index, snapshot.transport_prepared = 2, 0, 1;
|
|
hooked(frame, 1.0);
|
|
assert(frame.Description:GetText() == "Connecting to Octo..." and not frame.SelectButton.enabled);
|
|
assert(#frame.districtButtons == 0);
|
|
frame:ConfirmSuperDistrict();
|
|
assert(#requests == 1);
|
|
-- Once connected the normal rulesets screen owns the controls again.
|
|
assert(not frame.SubRegionDropdown.shown, "Source owns the subregion controls while connecting");
|
|
subRegions = {"region-a", "region-b"};
|
|
connected = true;
|
|
hooked(frame, 1.0);
|
|
assert(frame.SubRegionDropdown.shown, "two native subregions must reappear on fallback without reopening the picker");
|
|
assert(frame.Title:GetText() == "SUPER_DISTRICT_TITLE", frame.Title:GetText());
|
|
assert(#frame.districtButtons == 0, "original (empty stub) districts restored");
|
|
-- Optional release-backed character-select scenario, starting with a selected,
|
|
-- connected Source generation and the original empty stock picker.
|
|
if arg[2] then
|
|
assert(loadfile(arg[2]))()(frame);
|
|
assert(#requests == 1 and cancels == 1 and disconnects == 1,
|
|
"ordinary character-select change must leave the selected Source session alone");
|
|
end
|
|
-- A singleton realm can also be selected before this screen ever draws it.
|
|
snapshot.generation = 8;
|
|
connected = false;
|
|
frame:RefreshSuperDistrictButtons();
|
|
assert(frame.Description:GetText() == "Connecting to Octo..." and not frame.SelectButton.enabled);
|
|
frame:OnCancel();
|
|
assert(#requests == 1 and cancels == 1 and disconnects == 2, "selected realm uses native Cancel");
|
|
subRegions = {"region-a"};
|
|
snapshot.state, snapshot.error = 3, 1;
|
|
hooked(frame, 1.0);
|
|
assert(frame.Title:GetText() == "SUPER_DISTRICT_TITLE");
|
|
assert(not frame.SubRegionDropdown.shown, "a lone native subregion keeps the dropdown hidden");
|
|
assert(#popups == 0);
|
|
print("PASS source_realm_district_test");
|