diff --git a/tests/memory-count.test.ts b/tests/memory-count.test.ts index 67e8a953..622dcfbf 100644 --- a/tests/memory-count.test.ts +++ b/tests/memory-count.test.ts @@ -10,4 +10,17 @@ describe("getDisplayedMemoryCount", () => { test("restores the store total when search is cleared", () => { expect(getDisplayedMemoryCount(false, 3, 120)).toBe(120); }); + + test("shows the filtered total when a tag filter is active", () => { + expect(getDisplayedMemoryCount(false, 3, 120, true)).toBe(3); + expect(getDisplayedMemoryCount(false, 0, 120, true)).toBe(0); + }); + + test("prefers search total when both search and tag filter are active", () => { + expect(getDisplayedMemoryCount(true, 2, 120, true)).toBe(2); + }); + + test("keeps the store total when no search and no tag filter", () => { + expect(getDisplayedMemoryCount(false, 3, 120, false)).toBe(120); + }); }); diff --git a/web/src/App.tsx b/web/src/App.tsx index 0cf37a3b..908e4189 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -148,7 +148,8 @@ export default function App() { count: getDisplayedMemoryCount( explorer.isSearching, explorer.totalItems, - explorer.statsTotal + explorer.statsTotal, + Boolean(explorer.selectedTag) ), })} diff --git a/web/src/lib/memory-count.ts b/web/src/lib/memory-count.ts index 0cd15f2a..b3dad2d3 100644 --- a/web/src/lib/memory-count.ts +++ b/web/src/lib/memory-count.ts @@ -1,7 +1,8 @@ export function getDisplayedMemoryCount( isSearching: boolean, searchTotal: number, - storeTotal: number + storeTotal: number, + tagFilterActive = false ): number { - return isSearching ? searchTotal : storeTotal; + return isSearching || tagFilterActive ? searchTotal : storeTotal; }