Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions tests/memory-count.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import { getDisplayedMemoryCount } from "../web/src/lib/memory-count";

describe("getDisplayedMemoryCount", () => {
test("shows matched results while search is active", () => {
expect(getDisplayedMemoryCount(true, 3, 120)).toBe(3);
expect(getDisplayedMemoryCount(true, 0, 120)).toBe(0);
expect(getDisplayedMemoryCount(true, false, 3, 120)).toBe(3);
expect(getDisplayedMemoryCount(true, false, 0, 120)).toBe(0);
});

test("restores the store total when search is cleared", () => {
expect(getDisplayedMemoryCount(false, 3, 120)).toBe(120);
test("shows filtered results while a tag filter is active", () => {
expect(getDisplayedMemoryCount(false, true, 3, 120)).toBe(3);
expect(getDisplayedMemoryCount(false, true, 0, 120)).toBe(0);
});

test("restores the store total when search and tag filter are cleared", () => {
expect(getDisplayedMemoryCount(false, false, 3, 120)).toBe(120);
});
});
1 change: 1 addition & 0 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export default function App() {
{t("text-total", {
count: getDisplayedMemoryCount(
explorer.isSearching,
explorer.selectedTag !== "",
explorer.totalItems,
explorer.statsTotal
),
Expand Down
5 changes: 3 additions & 2 deletions web/src/lib/memory-count.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export function getDisplayedMemoryCount(
isSearching: boolean,
searchTotal: number,
tagFilterActive: boolean,
resultTotal: number,
storeTotal: number
): number {
return isSearching ? searchTotal : storeTotal;
return isSearching || tagFilterActive ? resultTotal : storeTotal;
}