diff --git a/.luacheckrc b/.luacheckrc index 8f00468..b10f64a 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -190,3 +190,11 @@ files["tests/test_updates.lua"] = { files["tests/test_events_sharing.lua"] = { globals = { "WowStub", "SideQuestDB" }, } + +files["tests/test_loot_council.lua"] = { + globals = { "WowStub", "SideQuestDB" }, +} + +files["tests/test_ui_loot_council.lua"] = { + globals = { "WowStub", "SideQuestDB" }, +} diff --git a/README.md b/README.md index 4928dee..e3c8372 100644 --- a/README.md +++ b/README.md @@ -46,15 +46,16 @@ The full rules and prices are on the [Ledger page](https://sidequest-guild.com/l | Tab | What it shows | |---|---| | You | Your PR and where it ranks, your last four weeks of points, your next event with Going, Maybe and Can't buttons, and who's online. | -| Guild | The roster, with alts under their main. Search it, filter by class, rank or online, and whisper or invite from it. Whisper opens a small SideQuest box: replies come back in chat as usual. | +| Guild | The roster, with alts under their main. Search it, filter by class, rank or online, and whisper or invite from it. Whisper opens a small SideQuest box: replies come back in chat as usual. Online guildmates show in green, offline in grey. | | Crafters | Search a recipe or profession to see who can make it, online people first; every member with a profession and their skill; and who has Transmute, Mooncloth and other craft cooldowns ready. | -| Market | What guildmates sell and want to buy, open requests for materials, and who holds an item. Mine lists and edits your own. | +| Market | What guildmates sell and want to buy, open requests for materials, and who holds an item, with the guild's lowest auction-house price next to each listing when one's known. Mine lists and edits your own. | | Events | Upcoming events, how many have signed up for each role, and your own answer, then the last 30 days' past events with how many went. | | Ledger | Everyone's EP, GP and PR, then your own points history and loot. | | News | Guild announcements and recent activity. | Click someone on the Guild tab to see their level, spec, item level, professions, Onyxia attunement, tracked -reputations and cooldowns. Hover any item to see which guildmates craft, sell, buy or hold it. +reputations and cooldowns. Hover any item to see which guildmates craft, sell, buy or hold it, and the guild's +lowest auction-house price if a sync has priced it. Your event sign-ups reach the website the next time an officer syncs. You don't need to do anything else. @@ -124,7 +125,10 @@ Then follow the steps: hasn't killed gives 10 EP, once per boss per night. 5. **Loot** opens bidding on each item in the loot window. Raiders get a popup with the item, its GP price, their PR and Main, Off and Pass buttons. The Loot tab lists the answers in the order the rules give: main spec by PR, then off - spec, alts and disenchant. Chase items, legendaries and crafted tier are left for the loot council to decide. + spec, alts and disenchant. Chase items (one per boss), legendaries/specials/rares and crafted tier are decided by + the loot council instead: pick the winner and the item in the Loot tab's **Council award** form, its kind (Chase, + Legendary or Tier -- Tier also asks which slot), and write a one-line reason, which is posted to #loot-log on the + site. The winner still pays full GP; Award stays disabled until every field is filled in. 6. **End raid** gives 5 EP to everyone still there. It unlocks once you're recording, and doesn't stop recording by itself -- click **Stop recording** (or type `/sq record`) when the night is over. @@ -136,7 +140,7 @@ The other Console tabs: |---|---| | Loot | Bidding and awards, as above. If you aren't master looter, `/sq bid ` opens bidding on any item. | | Roster | Reads the guild roster for the website and lists inactive members. | -| Recruits | Applicants and trials, with yes/no votes from officers. | +| Recruits | An Add recruit form that fills in your target, plus applicants and trials with yes/no votes from officers. | | Bank | Saves the open guild bank tab's log for the website. | | Announce | Posts a message to guild chat and every member's News tab, and to Discord if you tick the box. | | Sync | Shows what hasn't been sent to the website yet, with Export and Import buttons. **Update calendar** puts the site's upcoming events on the in-game guild calendar. | diff --git a/SideQuest/Loot.lua b/SideQuest/Loot.lua old mode 100644 new mode 100755 index 5a9e950..fe5313a --- a/SideQuest/Loot.lua +++ b/SideQuest/Loot.lua @@ -97,14 +97,33 @@ end --- Record a loot award: writes the loot row plus its GP ledger twin, per -- the contract (amount may be 0 for alt/de/bank but the row is still written). +-- Council awards (response = "council") additionally require gpOpts.councilKind +-- (chase|legendary|tier) and a trimmed, 1-200 char gpOpts.councilReason; the +-- loot row then carries council_reason/council_kind (contract: addon.md). -- @param item table { item_id, item_name, quality, inv_type } -- @param character string normalized "Name-Realm" -- @param response string ms|os|alt|council|de|bank -- @param sessionId string|nil -- @param encounterRowId string|nil --- @param gpOpts table forwarded to Rules.ComputeGP, plus optional `gpOverride` +-- @param gpOpts table forwarded to Rules.ComputeGP, plus optional `gpOverride`, +-- and for council awards `councilKind`/`councilReason` function Loot.AwardLoot(item, character, response, sessionId, encounterRowId, gpOpts) gpOpts = gpOpts or {} + + local councilReason + if response == "council" then + local kind = gpOpts.councilKind + if kind ~= "chase" and kind ~= "legendary" and kind ~= "tier" then + SideQuest.Print("A council award needs a kind: chase, legendary or tier.") + return nil + end + councilReason = (gpOpts.councilReason or ""):gsub("^%s+", ""):gsub("%s+$", "") + if councilReason == "" or #councilReason > 200 then + SideQuest.Print("A council award needs a one-line reason (1-200 characters).") + return nil + end + end + local gp if gpOpts.gpOverride ~= nil then gp = gpOpts.gpOverride @@ -127,6 +146,10 @@ function Loot.AwardLoot(item, character, response, sessionId, encounterRowId, gp officer = SideQuest.NormalizeUnit("player"), voided = false, } + if response == "council" then + lootRow.council_reason = councilReason + lootRow.council_kind = gpOpts.councilKind + end table.insert(pending().loot, lootRow) local awardRow = { diff --git a/SideQuest/UI/Main.lua b/SideQuest/UI/Main.lua index a919fd5..30aa38b 100755 --- a/SideQuest/UI/Main.lua +++ b/SideQuest/UI/Main.lua @@ -4007,6 +4007,57 @@ function UI.RefreshConsoleRaidNight() setScrollContentHeight(chamber.scroll, 330 + 18 * #whoLines + 18 * shown) end +-- Council award: officers pick the winner, item, its kind (contract: +-- chase, legendary = legendary/special/rare, tier = crafted tier) and a +-- required one-line reason, independent of the ranked bid table above +-- (council items are never auto-ranked -- Loot.GroupFor drops them). +local COUNCIL_KINDS = { { "chase", "Chase" }, { "legendary", "Legendary" }, { "tier", "Tier" } } +local COUNCIL_TIER_SLOTS = { + { "INVTYPE_HEAD", "Head" }, { "INVTYPE_SHOULDER", "Shoulder" }, { "INVTYPE_CHEST", "Chest" }, + { "INVTYPE_HAND", "Hands" }, { "INVTYPE_LEGS", "Legs" }, +} + +--- Recompute the council-award form's GP preview and the Award button's +-- enabled state from whatever is currently typed/selected. Called after +-- every edit so Award stays disabled until item, winner, kind (and slot, +-- for tier) and a 1-200 char reason are all present. +local function refreshCouncilAward(chamber) + for _, kind in ipairs(COUNCIL_KINDS) do + chamber.councilKindButtons[kind[1]]:SetSelected(chamber.councilKind == kind[1]) + end + local showSlots = chamber.councilKind == "tier" + for _, slot in ipairs(COUNCIL_TIER_SLOTS) do + local btn = chamber.councilSlotButtons[slot[1]] + btn:SetShown(showSlots) + btn:SetSelected(showSlots and chamber.councilSlot == slot[1]) + end + + local itemId = parseItemInput(chamber.councilItemBox) + local info = itemId and resolveItemInfo(tostring(itemId)) or nil + local reason = chamber.councilReasonBox:GetText():gsub("^%s+", ""):gsub("%s+$", "") + local winner = chamber.councilWinnerBox:GetText():gsub("^%s+", ""):gsub("%s+$", "") + + local gp + if info and chamber.councilKind then + if chamber.councilKind == "chase" then + gp = SideQuest.Rules.ComputeGP(info.equipLoc, "council", { isChase = true }) + elseif chamber.councilKind == "legendary" then + gp = SideQuest.Rules.ComputeGP(info.equipLoc, "council", { isLegendary = true }) + elseif chamber.councilKind == "tier" and chamber.councilSlot then + gp = SideQuest.Rules.ComputeGP(info.equipLoc, "council", + { isTierToken = true, tierSlotInvType = chamber.councilSlot }) + end + end + chamber.councilGpText:SetText(gp and ("GP " .. gp) or "") + + local valid = itemId ~= nil and winner ~= "" and chamber.councilKind ~= nil + and (chamber.councilKind ~= "tier" or chamber.councilSlot ~= nil) + and reason ~= "" and #reason <= 200 + chamber.councilAwardBtn:SetEnabled(valid, + "Pick the item, winner, kind (and slot for tier), and write a one-line reason.") + chamber.councilValid = valid +end + -- Loot sub-view: the item up for bid (icon, quality-colour name, slot, GP -- cost), each response ranked per contract order with PR/EP columns and -- a per-row Award button, plus Close bidding and the time left. @@ -4068,10 +4119,128 @@ function UI.BuildConsoleLoot(panel) epHdr:SetText(trackedCaps("EP")) local scroll, content = buildScroll(chamber.inner, -140) + -- reserve the chamber's bottom strip for the council-award form below + scroll:SetPoint("BOTTOMRIGHT", -24, 172) chamber.scroll, chamber.content, chamber.bidRows = scroll, content, {} chamber.iconSwatch, chamber.icon, chamber.itemText, chamber.slotGpText, chamber.timeLeftText = iconSwatch, icon, itemText, slotGpText, timeLeftText + + -- Council award: a self-contained form (not tied to the ranked bid + -- table, since council responses are never auto-ranked) pinned to the + -- chamber's bottom strip so it never collides with however tall the + -- bid list grows. + local councilHeading = createSubHeading(chamber.inner, "Council award") + councilHeading:SetPoint("BOTTOMLEFT", chamber.inner, "BOTTOMLEFT", 14, 148) + councilHeading:SetWidth(700) + + local councilItemBox = CreateFrame("EditBox", nil, chamber.inner, "InputBoxTemplate") + councilItemBox:SetSize(150, 20) + councilItemBox:SetPoint("TOPLEFT", councilHeading, "BOTTOMLEFT", 0, -8) + councilItemBox:SetAutoFocus(false) + skinEditBox(councilItemBox, "Item name, link or ID") + acceptItemLinks(councilItemBox) + + local councilWinnerBox = CreateFrame("EditBox", nil, chamber.inner, "InputBoxTemplate") + councilWinnerBox:SetSize(140, 20) + councilWinnerBox:SetPoint("LEFT", councilItemBox, "RIGHT", 8, 0) + councilWinnerBox:SetAutoFocus(false) + councilWinnerBox:SetMaxLetters(64) + skinEditBox(councilWinnerBox, "Winner's character name") + + local councilKindButtons = {} + local prevKindBtn + for _, kind in ipairs(COUNCIL_KINDS) do + local btn = createButton(chamber.inner, "quiet", kind[2], 70, 20) + if prevKindBtn then + btn:SetPoint("LEFT", prevKindBtn, "RIGHT", 4, 0) + else + btn:SetPoint("LEFT", councilWinnerBox, "RIGHT", 8, 0) + end + councilKindButtons[kind[1]] = btn + prevKindBtn = btn + end + + local councilSlotButtons = {} + local prevSlotBtn + for _, slot in ipairs(COUNCIL_TIER_SLOTS) do + local btn = createButton(chamber.inner, "quiet", slot[2], 62, 18) + if prevSlotBtn then + btn:SetPoint("LEFT", prevSlotBtn, "RIGHT", 4, 0) + else + btn:SetPoint("TOPLEFT", councilItemBox, "BOTTOMLEFT", 0, -8) + end + councilSlotButtons[slot[1]] = btn + prevSlotBtn = btn + end + + local councilReasonBox = CreateFrame("EditBox", nil, chamber.inner, "InputBoxTemplate") + councilReasonBox:SetSize(280, 20) + councilReasonBox:SetPoint("TOPLEFT", councilItemBox, "BOTTOMLEFT", 0, -36) + councilReasonBox:SetAutoFocus(false) + councilReasonBox:SetMaxLetters(200) + skinEditBox(councilReasonBox, "Reason (required, posted to #loot-log)") + + local councilGpText = makeFontString(chamber.inner, FONT_BODY, 11, C.mist, "LEFT") + councilGpText:SetPoint("LEFT", councilReasonBox, "RIGHT", 10, 0) + + local councilAwardBtn = createButton(chamber.inner, "primary", "Award by council", 150, 22) + councilAwardBtn:SetPoint("LEFT", councilGpText, "RIGHT", 10, 0) + + chamber.councilItemBox, chamber.councilWinnerBox, chamber.councilReasonBox = councilItemBox, councilWinnerBox, councilReasonBox + chamber.councilGpText, chamber.councilAwardBtn = councilGpText, councilAwardBtn + chamber.councilKindButtons, chamber.councilSlotButtons = councilKindButtons, councilSlotButtons + + councilItemBox:SetScript("OnTextChanged", function() refreshCouncilAward(chamber) end) + councilWinnerBox:SetScript("OnTextChanged", function() refreshCouncilAward(chamber) end) + councilReasonBox:SetScript("OnTextChanged", function() refreshCouncilAward(chamber) end) + for _, kind in ipairs(COUNCIL_KINDS) do + councilKindButtons[kind[1]]:SetScript("OnClick", function() + chamber.councilKind = kind[1] + if kind[1] ~= "tier" then + chamber.councilSlot = nil + end + refreshCouncilAward(chamber) + end) + end + for _, slot in ipairs(COUNCIL_TIER_SLOTS) do + councilSlotButtons[slot[1]]:SetScript("OnClick", function() + chamber.councilSlot = slot[1] + refreshCouncilAward(chamber) + end) + end + councilAwardBtn:SetScript("OnClick", function() + if not chamber.councilValid then + return + end + local itemId = parseItemInput(councilItemBox) + local info = resolveItemInfo(tostring(itemId)) + local trimmedWinner = councilWinnerBox:GetText():gsub("^%s+", ""):gsub("%s+$", "") + local winner = SideQuest.NormalizeName(trimmedWinner) + local reason = councilReasonBox:GetText():gsub("^%s+", ""):gsub("%s+$", "") + local gpOpts = { councilKind = chamber.councilKind, councilReason = reason } + if chamber.councilKind == "chase" then + gpOpts.isChase = true + elseif chamber.councilKind == "legendary" then + gpOpts.isLegendary = true + elseif chamber.councilKind == "tier" then + gpOpts.isTierToken = true + gpOpts.tierSlotInvType = chamber.councilSlot + end + local lootId = SideQuest.Loot.AwardLoot( + { item_id = itemId, item_name = info.name, quality = info.quality, inv_type = info.equipLoc }, + winner, "council", nil, nil, gpOpts) + if lootId then + councilItemBox:SetText("") + councilWinnerBox:SetText("") + councilReasonBox:SetText("") + chamber.councilKind = nil + chamber.councilSlot = nil + refreshCouncilAward(chamber) + end + end) + panel.lootChamber = chamber + refreshCouncilAward(chamber) end function UI.RefreshBidRanking(bid) @@ -4080,6 +4249,7 @@ function UI.RefreshBidRanking(bid) return end local chamber = panel.lootChamber + refreshCouncilAward(chamber) bid = bid or SideQuest.Loot.activeBid for _, r in ipairs(chamber.bidRows) do r:Hide() diff --git a/tests/preview/html/console-loot-064.html b/tests/preview/html/console-loot-064.html index 4803a56..a1ea10e 100644 --- a/tests/preview/html/console-loot-064.html +++ b/tests/preview/html/console-loot-064.html @@ -10,7 +10,7 @@ .footer { font: 11px sans-serif; color: #889; background: #000c; padding: 6px 10px; max-width: 640px; } - +
@@ -171,31 +171,83 @@
Demo Glory of the Defender
Chest -- GP 100
20s remaining
+
Open bidding (loot window)
Close bidding
-
+
+
+
+
+
Chase
+
Legendary
+
Tier
+
+
Award by council
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Open bidding (loot window)
Close bidding
R A N K
C H A R A C T E R     - -     R E S P O N S E
P R
E P
-
+
C O U N C I L   A W A R D
+
Item name, link or ID
+
Winner's character name
+
Chase
+
Legendary
+
Tier
+
Reason (required, posted to #loot-log)
+
Award by council
+
-
+
diff --git a/tests/preview/html/console-loot.html b/tests/preview/html/console-loot.html index af638d7..9430e82 100644 --- a/tests/preview/html/console-loot.html +++ b/tests/preview/html/console-loot.html @@ -10,7 +10,7 @@ .footer { font: 11px sans-serif; color: #889; background: #000c; padding: 6px 10px; max-width: 640px; } - +
@@ -171,31 +171,83 @@
Demo Glory of the Defender
Chest -- GP 100
20s remaining
+
Open bidding (loot window)
Close bidding
-
+
+
+
+
+
Chase
+
Legendary
+
Tier
+
+
Award by council
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Open bidding (loot window)
Close bidding
R A N K
C H A R A C T E R     - -     R E S P O N S E
P R
E P
-
+
C O U N C I L   A W A R D
+
Item name, link or ID
+
Winner's character name
+
Chase
+
Legendary
+
Tier
+
Reason (required, posted to #loot-log)
+
Award by council
+
-
+
diff --git a/tests/preview/out/console-loot-064.png b/tests/preview/out/console-loot-064.png index 2820eeb..e0d2ce2 100644 Binary files a/tests/preview/out/console-loot-064.png and b/tests/preview/out/console-loot-064.png differ diff --git a/tests/preview/out/console-loot.png b/tests/preview/out/console-loot.png index 6abcb0a..c19b8b2 100644 Binary files a/tests/preview/out/console-loot.png and b/tests/preview/out/console-loot.png differ diff --git a/tests/test_loot_council.lua b/tests/test_loot_council.lua new file mode 100644 index 0000000..0df52b2 --- /dev/null +++ b/tests/test_loot_council.lua @@ -0,0 +1,152 @@ +-- tests/test_loot_council.lua +-- Council loot awards (contract: addon council award): Loot.AwardLoot's +-- kind/reason validation and GP-by-kind, and the SQX1 export carrying +-- council_reason/council_kind only on council rows. + +return function(h) + local function setupOfficer() + h.resetAddon() + WowStub.isOfficer = true + WowStub.realm = "Whitemane" + WowStub.inCombat = false + WowStub.SetUnit("player", { name = "Officer1", realm = "Whitemane", class = "PRIEST", guid = "Player-1-COUNCIL1" }) + end + + h.test("Loot.AwardLoot council: GP follows the chase kind via Rules.ComputeGP", function() + setupOfficer() + local lootId = SideQuest.Loot.AwardLoot( + { item_id = 1001, item_name = "Chase Trinket", quality = 4, inv_type = "INVTYPE_TRINKET" }, + "Winner-Whitemane", "council", nil, nil, + { councilKind = "chase", councilReason = "Best in slot for the tank", isChase = true }) + h.assertTrue(lootId ~= nil, "award recorded") + local row = SideQuestDB.pending.loot[1] + h.assertEq(row.gp, SideQuest.Rules.ComputeGP("INVTYPE_TRINKET", "council", { isChase = true }), + "chase GP matches Rules.ComputeGP") + h.assertEq(row.response, "council", "response stored as council") + h.assertEq(row.council_kind, "chase", "kind stored") + h.assertEq(row.council_reason, "Best in slot for the tank", "reason stored") + end) + + h.test("Loot.AwardLoot council: legendary kind charges the flat legendary GP regardless of slot", function() + setupOfficer() + SideQuest.Loot.AwardLoot( + { item_id = 1002, item_name = "Legendary Cloak", quality = 5, inv_type = "INVTYPE_CLOAK" }, + "Winner-Whitemane", "council", nil, nil, + { councilKind = "legendary", councilReason = "Only drop this tier", isLegendary = true }) + local row = SideQuestDB.pending.loot[1] + h.assertEq(row.gp, SideQuest.Rules.active.legendary_gp, "legendary GP is the flat legendary_gp") + h.assertEq(row.council_kind, "legendary", "kind stored") + end) + + h.test("Loot.AwardLoot council: tier kind prices off the picked slot, not the token's own inv_type", function() + setupOfficer() + SideQuest.Loot.AwardLoot( + { item_id = 1003, item_name = "Tier Token", quality = 4, inv_type = nil }, + "Winner-Whitemane", "council", nil, nil, + { councilKind = "tier", councilReason = "Last token this tier", isTierToken = true, tierSlotInvType = "INVTYPE_CHEST" }) + local row = SideQuestDB.pending.loot[1] + h.assertEq(row.gp, SideQuest.Rules.active.gp.INVTYPE_CHEST, + "tier GP uses the chosen slot even though the token's own inv_type is nil") + h.assertEq(row.council_kind, "tier", "kind stored") + end) + + h.test("Loot.AwardLoot council: a missing or invalid kind is rejected", function() + setupOfficer() + local lootId = SideQuest.Loot.AwardLoot( + { item_id = 1004, item_name = "X", quality = 1, inv_type = "INVTYPE_HEAD" }, + "Winner-Whitemane", "council", nil, nil, { councilReason = "reason here" }) + h.assertTrue(lootId == nil, "rejected without a kind") + h.assertEq(#SideQuestDB.pending.loot, 0, "nothing recorded") + + local lootId2 = SideQuest.Loot.AwardLoot( + { item_id = 1004, item_name = "X", quality = 1, inv_type = "INVTYPE_HEAD" }, + "Winner-Whitemane", "council", nil, nil, { councilKind = "bogus", councilReason = "reason here" }) + h.assertTrue(lootId2 == nil, "rejected with an unknown kind") + h.assertEq(#SideQuestDB.pending.loot, 0, "still nothing recorded") + end) + + h.test("Loot.AwardLoot council: an empty, whitespace-only or too-long reason is rejected", function() + setupOfficer() + local lootId1 = SideQuest.Loot.AwardLoot( + { item_id = 1005, item_name = "X", quality = 1, inv_type = "INVTYPE_HEAD" }, + "Winner-Whitemane", "council", nil, nil, { councilKind = "chase", isChase = true }) + h.assertTrue(lootId1 == nil, "no reason rejected") + + local lootId2 = SideQuest.Loot.AwardLoot( + { item_id = 1005, item_name = "X", quality = 1, inv_type = "INVTYPE_HEAD" }, + "Winner-Whitemane", "council", nil, nil, { councilKind = "chase", isChase = true, councilReason = " " }) + h.assertTrue(lootId2 == nil, "whitespace-only reason rejected") + + local lootId3 = SideQuest.Loot.AwardLoot( + { item_id = 1005, item_name = "X", quality = 1, inv_type = "INVTYPE_HEAD" }, + "Winner-Whitemane", "council", nil, nil, + { councilKind = "chase", isChase = true, councilReason = string.rep("x", 201) }) + h.assertTrue(lootId3 == nil, "over-200-char reason rejected") + + h.assertEq(#SideQuestDB.pending.loot, 0, "nothing recorded across all three rejections") + end) + + h.test("Loot.AwardLoot council: the reason is trimmed before storing", function() + setupOfficer() + SideQuest.Loot.AwardLoot( + { item_id = 1006, item_name = "X", quality = 1, inv_type = "INVTYPE_HEAD" }, + "Winner-Whitemane", "council", nil, nil, + { councilKind = "chase", isChase = true, councilReason = " padded reason " }) + h.assertEq(SideQuestDB.pending.loot[1].council_reason, "padded reason", "leading/trailing space trimmed") + end) + + h.test("Codec export: council_reason/council_kind ship only on council rows, surviving encode/decode", function() + setupOfficer() + SideQuest.Loot.AwardLoot( + { item_id = 1007, item_name = "Council Item", quality = 4, inv_type = "INVTYPE_TRINKET" }, + "Winner-Whitemane", "council", nil, nil, + { councilKind = "chase", isChase = true, councilReason = "Needed for progression" }) + SideQuest.Loot.AwardLoot( + { item_id = 1008, item_name = "Normal Item", quality = 3, inv_type = "INVTYPE_HEAD" }, + "Someone-Whitemane", "ms", nil, nil, {}) + + local payload = SideQuest.Codec.BuildExportPayload("Officer1-Whitemane", "Guild", "Whitemane") + local councilRow, msRow + for _, row in ipairs(payload.loot) do + if row.response == "council" then + councilRow = row + elseif row.response == "ms" then + msRow = row + end + end + h.assertTrue(councilRow ~= nil, "council row present") + h.assertEq(councilRow.council_kind, "chase", "council row carries kind") + h.assertEq(councilRow.council_reason, "Needed for progression", "council row carries reason") + h.assertTrue(msRow ~= nil, "ms row present") + h.assertTrue(msRow.council_reason == nil, "non-council row has no council_reason") + h.assertTrue(msRow.council_kind == nil, "non-council row has no council_kind") + + -- round-trip through the actual SQX1: wire format, not just the Lua table + local decoded = SideQuest.Codec.DecodeExport(SideQuest.Codec.EncodeExport(payload)) + local decodedCouncil, decodedMs + for _, row in ipairs(decoded.loot) do + if row.response == "council" then + decodedCouncil = row + elseif row.response == "ms" then + decodedMs = row + end + end + h.assertEq(decodedCouncil.council_reason, "Needed for progression", "survives encode/decode") + h.assertTrue(decodedMs.council_reason == nil, "still absent on the ms row after encode/decode") + end) + + h.test("Loot.Undo: voiding a council award works like any other void", function() + setupOfficer() + local lootId, awardId = SideQuest.Loot.AwardLoot( + { item_id = 1009, item_name = "Council Item", quality = 4, inv_type = "INVTYPE_TRINKET" }, + "Winner-Whitemane", "council", nil, nil, + { councilKind = "chase", isChase = true, councilReason = "Needed for progression" }) + h.assertTrue(SideQuest.Loot.Undo(lootId), "undo reports voided") + h.assertTrue(SideQuestDB.pending.loot[1].voided, "loot row voided") + for _, award in ipairs(SideQuestDB.pending.awards) do + if award.id == awardId then + h.assertTrue(award.voided, "linked GP award voided too") + end + end + end) +end diff --git a/tests/test_ui_loot_council.lua b/tests/test_ui_loot_council.lua new file mode 100644 index 0000000..45af68b --- /dev/null +++ b/tests/test_ui_loot_council.lua @@ -0,0 +1,116 @@ +-- tests/test_ui_loot_council.lua +-- Console > Loot: the council-award form (contract: addon council award) +-- alongside the existing ranked-bid Award flow. + +return function(h) + local function openLoot() + h.resetAddon() + SideQuest.UI.main = nil + WowStub.isOfficer = true + WowStub.inCombat = false + WowStub.realm = "Whitemane" + WowStub.SetUnit("player", { name = "Officer1", realm = "Whitemane", class = "PRIEST", guid = "Player-1-UILOOT1" }) + WowStub.items = { + [2001] = { itemId = 2001, name = "Demo Trinket", quality = 4, equipLoc = "INVTYPE_TRINKET", + icon = "Interface\\Icons\\INV_Misc_Gem_01" }, + [2002] = { itemId = 2002, name = "Demo Chest Token", quality = 4, equipLoc = nil, + icon = "Interface\\Icons\\INV_Chest_Plate04" }, + } + SideQuest.UI.Show() + SideQuest.UI.ShowTab("Console") + SideQuest.UI.ShowConsoleSub("Loot") + return SideQuest.UI.panels.Console.lootChamber + end + + h.test("Council award: Award stays disabled until item, winner, kind and reason are all set", function() + local chamber = openLoot() + h.assertTrue(chamber.councilAwardBtn.__enabled == false, "disabled with nothing filled in") + + chamber.councilItemBox:SetText("2001") + chamber.councilWinnerBox:SetText("Winner") + chamber.councilKindButtons.chase:GetScript("OnClick")() + h.assertTrue(chamber.councilAwardBtn.__enabled == false, "still disabled without a reason") + + chamber.councilReasonBox:SetText("Best upgrade available") + SideQuest.UI.RefreshBidRanking() + h.assertTrue(chamber.councilAwardBtn.__enabled == true, "enabled once everything is filled in") + h.assertEq(chamber.councilGpText:GetText(), + "GP " .. SideQuest.Rules.ComputeGP("INVTYPE_TRINKET", "council", { isChase = true }), + "GP preview matches Rules.ComputeGP for the chase kind") + end) + + h.test("Council award: an empty winner name or no item keeps Award disabled", function() + local chamber = openLoot() + chamber.councilReasonBox:SetText("Reason") + chamber.councilKindButtons.chase:GetScript("OnClick")() + SideQuest.UI.RefreshBidRanking() + h.assertTrue(chamber.councilAwardBtn.__enabled == false, "no item, no winner: still disabled") + + chamber.councilWinnerBox:SetText("Winner") + SideQuest.UI.RefreshBidRanking() + h.assertTrue(chamber.councilAwardBtn.__enabled == false, "winner set but no item: still disabled") + end) + + h.test("Council award: picking Tier shows the slot buttons and requires one before Award enables", function() + local chamber = openLoot() + chamber.councilItemBox:SetText("2002") + chamber.councilWinnerBox:SetText("Winner") + chamber.councilReasonBox:SetText("Only token drop") + chamber.councilKindButtons.tier:GetScript("OnClick")() + + h.assertTrue(chamber.councilSlotButtons.INVTYPE_CHEST:IsShown(), "slot buttons show for the tier kind") + h.assertTrue(chamber.councilAwardBtn.__enabled == false, "disabled until a slot is picked") + + chamber.councilSlotButtons.INVTYPE_CHEST:GetScript("OnClick")() + h.assertTrue(chamber.councilAwardBtn.__enabled == true, "enabled once a slot is picked") + h.assertEq(chamber.councilGpText:GetText(), "GP " .. SideQuest.Rules.active.gp.INVTYPE_CHEST, + "GP preview uses the picked slot even though the token's own inv_type is nil") + + chamber.councilKindButtons.chase:GetScript("OnClick")() + h.assertTrue(not chamber.councilSlotButtons.INVTYPE_CHEST:IsShown(), "slot buttons hide outside the tier kind") + end) + + h.test("Council award: clicking Award records the loot row and clears the form", function() + local chamber = openLoot() + chamber.councilItemBox:SetText("2001") + chamber.councilWinnerBox:SetText("Winner") + chamber.councilKindButtons.legendary:GetScript("OnClick")() + chamber.councilReasonBox:SetText("Unique legendary drop") + SideQuest.UI.RefreshBidRanking() + + chamber.councilAwardBtn:GetScript("OnClick")() + + h.assertEq(#SideQuestDB.pending.loot, 1, "one loot row recorded") + local row = SideQuestDB.pending.loot[1] + h.assertEq(row.character, "Winner-Whitemane", "winner normalized with the player's realm") + h.assertEq(row.response, "council", "response is council") + h.assertEq(row.council_kind, "legendary", "kind stored") + h.assertEq(row.council_reason, "Unique legendary drop", "reason stored") + h.assertEq(row.gp, SideQuest.Rules.active.legendary_gp, "legendary GP") + + h.assertEq(chamber.councilItemBox:GetText(), "", "item box cleared") + h.assertEq(chamber.councilWinnerBox:GetText(), "", "winner box cleared") + h.assertEq(chamber.councilReasonBox:GetText(), "", "reason box cleared") + h.assertTrue(chamber.councilAwardBtn.__enabled == false, "disabled again after awarding") + end) + + h.test("Council award: clicking Award while invalid is a no-op (defense in depth under the disabled button)", function() + local chamber = openLoot() + chamber.councilAwardBtn:GetScript("OnClick")() + h.assertEq(#SideQuestDB.pending.loot, 0, "nothing recorded with an empty form") + end) + + h.test("Console Loot: an ordinary ranked-bid award is unaffected by the council form", function() + local chamber = openLoot() + SideQuest.Loot.OpenBid("item:2001:Demo Trinket") + SideQuest.Loot.RecordResponse("Bidder-Whitemane", "ms") + SideQuest.UI.RefreshBidRanking() + h.assertTrue(#chamber.bidRows >= 1 and chamber.bidRows[1]:IsShown(), "ranked bid row shown") + + chamber.bidRows[1].awardBtn:GetScript("OnClick")() + + h.assertEq(#SideQuestDB.pending.loot, 1, "ms award recorded as before") + h.assertTrue(SideQuestDB.pending.loot[1].council_reason == nil, "ordinary award carries no council fields") + h.assertEq(SideQuestDB.pending.loot[1].response, "ms", "response is still ms") + end) +end