Skip to content

feat: show inventory item count on loot toasts (#151)#152

Merged
Xerrion merged 5 commits into
masterfrom
feat/151-item-count-on-toast
Apr 5, 2026
Merged

feat: show inventory item count on loot toasts (#151)#152
Xerrion merged 5 commits into
masterfrom
feat/151-item-count-on-toast

Conversation

@Xerrion
Copy link
Copy Markdown
Owner

@Xerrion Xerrion commented Apr 5, 2026

Description

Adds an optional display of the player's current inventory count for looted items on toast notifications. When enabled, toasts for looted items show how many of that item you already have in your bags (e.g. x3 in bags).

Type of Change

  • New feature (non-breaking change that adds functionality)

Related Issues

Closes #151

Testing

  • Luacheck passes (luacheck .)
  • Tested in-game manually
  • WoW version(s) tested on: TBC Anniversary, Retail

Screenshots

Not applicable - feature is toggled off by default.

Checklist

  • My code follows the project's code style (4-space indent, 120 char lines)
  • I have tested my changes in-game
  • Luacheck reports no warnings
  • My commits follow conventional commit format

Implementation Notes

  • New toggle in Display tab options: Show Item Count (default: off)
  • Uses C_Item.GetItemCount on Retail/MoP, falls back to legacy GetItemCount on TBC Anniversary
  • Bags-only count (bank not included by default - bank data is only accurate if the bank was opened this session)
  • Returns or 0 guard prevents Lua errors when the API returns nil (e.g. uncached items on Classic)
  • itemCount FontString is anchored below itemLevel to prevent overlap when both are enabled
  • DB schema version bumped to 8 with a SIMPLE_MIGRATIONS entry for clean upgrades
  • 5 new unit tests in spec/ToastFrame_spec.lua covering show/hide/nil/currency/Classic-nil-guard paths

Summary by CodeRabbit

  • New Features

    • Show item counts on reward toasts; new Display toggle and default setting with migration handling.
  • Localization

    • Added many enUS and deDE translations; all user-facing UI, commands and tooltips localized.
  • Tests

    • Added/updated unit tests covering item-count display behavior and locale-dependent command handling.
  • Chores

    • Added project tool config and linting/task entries; updated lint configuration to recognize a WoW API global.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 6e92bc94-9235-4aca-8d6a-fbe643e99353

📥 Commits

Reviewing files that changed from the base of the PR and between fd98ba3 and 3d6263d.

📒 Files selected for processing (1)
  • DragonToast_Options/Tabs/DisplayTab.lua
✅ Files skipped from review due to trivial changes (1)
  • DragonToast_Options/Tabs/DisplayTab.lua

📝 Walkthrough

Walkthrough

Adds an optional, togglable item-count display to toasts, UI/config changes to support it, localization for many user-facing strings, test coverage for the new behavior, and CI/tooling config updates.

Changes

Cohort / File(s) Summary
Config & CI
\.luacheckrc, \.mise.toml, DragonToast/Core/Config.lua
Recognize GetItemCount as a global for linting; add .mise.toml with lua/test/lint tasks; add profile.display.showItemCount default and migration to schema v8.
Display UI
DragonToast/Display/ToastFrame.lua, DragonToast_Options/Tabs/DisplayTab.lua
Add itemCount FontString to toast frames; cache GetItemCount (C_Item fallback) and show x%d in bags when enabled and itemID present; add Display option toggle and layout refresh.
Localization & Strings
DragonToast/Core/ConfigWindow.lua, DragonToast/Core/MinimapIcon.lua, DragonToast/Core/Presets.lua, DragonToast/Core/SlashCommands.lua, DragonToast/Display/TestToasts.lua, DragonToast/Display/ToastManager.lua
Replace hardcoded strings with LibStub("AceLocale-3.0"):GetLocale("DragonToast") lookups across UI, tooltip text, slash output, presets, and manager messages.
Locales
DragonToast/Locales/enUS.lua, DragonToast/Locales/deDE.lua
Add new translation keys for preset names, item-count text (x%d in bags), slash/help/status/minimap/test strings and related labels.
Tests
spec/SlashCommands_spec.lua, spec/ToastFrame_spec.lua
Stub LibStub in slash tests; add comprehensive ToastFrame tests exercising item-count show/hide cases, currency filtering, nil-count behavior, and pool cleanup.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.06% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title follows Conventional Commit format (feat: ...) and accurately summarizes the main feature: adding inventory item count display on loot toasts.
Linked Issues check ✅ Passed Implementation fully addresses #151: adds togglable option in Display tab, uses GetItemCount API with C_Item fallback, displays count as 'x%d in bags' format, handles nil returns, and includes comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes directly support the item count feature: configuration schema/UI, localization strings, locale files, slash command help, and comprehensive unit tests. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
spec/SlashCommands_spec.lua (1)

21-33: ⚠️ Potential issue | 🟡 Minor

Restore original LibStub in teardown to avoid cross-spec leakage.

Line 78 always nils the global, which can break neighboring specs that expect a preexisting LibStub. Preserve and restore the original value.

🧪 Suggested fix
 describe("HandleSlashCommand", function()
     local ns
     local clearCalled
     local printedMessage
     local originalPrint
+    local originalLibStub
 
     before_each(function()
         originalPrint = _G.print
+        originalLibStub = _G.LibStub
         _G.print = function() end
@@
     after_each(function()
         _G.print = originalPrint
-        _G.LibStub = nil
+        _G.LibStub = originalLibStub
     end)

Also applies to: 76-79

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@spec/SlashCommands_spec.lua` around lines 21 - 33, The test setup overwrites
the global _G.LibStub and the teardown currently nils it, causing leakage;
capture the original value before overwriting (e.g., store it in originalLibStub
alongside originalPrint inside before_each where _G.LibStub is assigned) and
restore that saved value in after_each (set _G.LibStub = originalLibStub)
instead of unconditionally niling the global so neighboring specs keep their
expected LibStub.
🧹 Nitpick comments (2)
DragonToast_Options/Tabs/DisplayTab.lua (1)

200-208: Trigger a layout refresh when toggling item count.

For immediate in-session feedback, Line 204 can mirror other layout-affecting controls and refresh active toasts after the value change.

♻️ Suggested tweak
     local itemCountToggle = W.CreateToggle(parent, {
         label = L["Show Item Count"],
         tooltip = L["Display total inventory count of the looted item on the toast"],
         get = function() return db.profile.display.showItemCount end,
-        set = function(value) db.profile.display.showItemCount = value end,
+        set = function(value)
+            db.profile.display.showItemCount = value
+            dtns.ToastManager:UpdateLayout()
+        end,
     })

As per coding guidelines DragonToast_Options/**/*.lua: “Review for correct widget lifecycle … proper config key paths matching db.profile schema in Core/Config.lua, and callback wiring.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@DragonToast_Options/Tabs/DisplayTab.lua` around lines 200 - 208, The
itemCountToggle's set currently only updates db.profile.display.showItemCount
without triggering a layout refresh; update the set handler for itemCountToggle
(created in this block) to mirror other layout-affecting controls by calling the
same "refresh active toasts" routine used elsewhere after assigning
db.profile.display.showItemCount, ensuring you follow the widget lifecycle
pattern around LC.AnchorWidget(itemCountToggle, ...) so active toasts update
immediately when toggled.
spec/ToastFrame_spec.lua (1)

246-290: Good coverage of item count display scenarios.

Tests verify:

  • Shown with correct text when enabled + itemID present
  • Hidden when showItemCount=false
  • Hidden when itemID=nil
  • Hidden for currency toasts
  • Graceful x0 in bags when GetItemCount returns nil (Classic nil-guard)

Consider adding tests for isXP, isHonor, isReputation exclusions if you want exhaustive coverage, but the currency test demonstrates the pattern works.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@spec/ToastFrame_spec.lua` around lines 246 - 290, Add tests covering the
cases where toasts should hide the item count for non-item reward types: create
new examples in spec/ToastFrame_spec.lua that mirror the existing "hides count
for currency toasts" test but set data.isXP = true, data.isHonor = true, and
data.isReputation = true respectively (use makeItemData({ isXP = true }), etc.),
call ns.ToastFrame.Populate(frame, data), and assert that frame.itemCount._shown
is false (and optionally that _text is untouched); reuse the same patterns and
mocks (e.g. _mockGetItemCount, makeItemData, ns.ToastFrame.Populate,
frame.itemCount) so the tests follow the existing style.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@spec/SlashCommands_spec.lua`:
- Around line 21-33: The test setup overwrites the global _G.LibStub and the
teardown currently nils it, causing leakage; capture the original value before
overwriting (e.g., store it in originalLibStub alongside originalPrint inside
before_each where _G.LibStub is assigned) and restore that saved value in
after_each (set _G.LibStub = originalLibStub) instead of unconditionally niling
the global so neighboring specs keep their expected LibStub.

---

Nitpick comments:
In `@DragonToast_Options/Tabs/DisplayTab.lua`:
- Around line 200-208: The itemCountToggle's set currently only updates
db.profile.display.showItemCount without triggering a layout refresh; update the
set handler for itemCountToggle (created in this block) to mirror other
layout-affecting controls by calling the same "refresh active toasts" routine
used elsewhere after assigning db.profile.display.showItemCount, ensuring you
follow the widget lifecycle pattern around LC.AnchorWidget(itemCountToggle, ...)
so active toasts update immediately when toggled.

In `@spec/ToastFrame_spec.lua`:
- Around line 246-290: Add tests covering the cases where toasts should hide the
item count for non-item reward types: create new examples in
spec/ToastFrame_spec.lua that mirror the existing "hides count for currency
toasts" test but set data.isXP = true, data.isHonor = true, and
data.isReputation = true respectively (use makeItemData({ isXP = true }), etc.),
call ns.ToastFrame.Populate(frame, data), and assert that frame.itemCount._shown
is false (and optionally that _text is untouched); reuse the same patterns and
mocks (e.g. _mockGetItemCount, makeItemData, ns.ToastFrame.Populate,
frame.itemCount) so the tests follow the existing style.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 1e8aa7f3-141e-475b-af6c-86d491409d10

📥 Commits

Reviewing files that changed from the base of the PR and between bb37aac and fd98ba3.

📒 Files selected for processing (15)
  • .luacheckrc
  • .mise.toml
  • DragonToast/Core/Config.lua
  • DragonToast/Core/ConfigWindow.lua
  • DragonToast/Core/MinimapIcon.lua
  • DragonToast/Core/Presets.lua
  • DragonToast/Core/SlashCommands.lua
  • DragonToast/Display/TestToasts.lua
  • DragonToast/Display/ToastFrame.lua
  • DragonToast/Display/ToastManager.lua
  • DragonToast/Locales/deDE.lua
  • DragonToast/Locales/enUS.lua
  • DragonToast_Options/Tabs/DisplayTab.lua
  • spec/SlashCommands_spec.lua
  • spec/ToastFrame_spec.lua

@Xerrion Xerrion merged commit d35db07 into master Apr 5, 2026
3 checks passed
@Xerrion Xerrion deleted the feat/151-item-count-on-toast branch April 5, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Show inventory item count on toast notifications

1 participant