forked from MergeFi/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivityList.test.tsx
More file actions
53 lines (45 loc) · 1.93 KB
/
Copy pathActivityList.test.tsx
File metadata and controls
53 lines (45 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Tests for ActivityList's amount rendering (#87).
*
* `{event.amount && (...)}` renders a bare, unstyled "0" text node for a
* legitimate `amount: 0` event, since `0 && x` evaluates to `0` itself, and
* React renders a falsy-but-numeric expression result as literal text. The
* fix guards on `typeof event.amount === "number"` instead, matching the
* pattern already used correctly in StatCard's trend rendering.
*/
import { render, screen } from "@testing-library/react";
import { ActivityList } from "./ActivityList";
import type { ActivityEvent } from "@/lib/mock-data";
function makeEvent(overrides: Partial<ActivityEvent> = {}): ActivityEvent {
return {
id: "a1",
handle: "devrel_ana",
action: "was paid",
target: "core-indexer#288",
minutesAgo: 6,
...overrides,
};
}
describe("ActivityList — amount rendering", () => {
it("renders a correctly-formatted amount for a genuine zero, not a bare '0' text node", () => {
render(
<ActivityList events={[makeEvent({ amount: 0, asset: "USDC" })]} />,
);
// The formatted "0 USDC" string must be present...
expect(screen.getByText("0 USDC")).toBeInTheDocument();
// ...and it must be the *only* place a lone "0" ever appears — no
// stray, unstyled "0" sitting next to it outside that formatted string.
expect(screen.queryByText("0", { exact: true })).not.toBeInTheDocument();
});
it("renders no amount text when amount is undefined (the non-monetary event case)", () => {
render(<ActivityList events={[makeEvent({ action: "claimed" })]} />);
expect(screen.queryByText(/USDC|XLM/)).not.toBeInTheDocument();
expect(screen.queryByText("0", { exact: true })).not.toBeInTheDocument();
});
it("renders a genuine positive amount exactly as before", () => {
render(
<ActivityList events={[makeEvent({ amount: 480, asset: "USDC" })]} />,
);
expect(screen.getByText("480 USDC")).toBeInTheDocument();
});
});