Skip to content
Merged
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
10 changes: 6 additions & 4 deletions __tests__/components/brain/BrainMobile.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ jest.mock(
() => ({
__esModule: true,
default: ({
leftThisRoundCount,
onOpenQuickVote,
unratedCount,
}: {
readonly leftThisRoundCount: number;
readonly onOpenQuickVote: () => void;
readonly unratedCount: number;
}) => (
<button
type="button"
data-testid="quick-vote-trigger"
onClick={onOpenQuickVote}
>
{unratedCount}
{leftThisRoundCount}
</button>
),
})
Expand Down Expand Up @@ -254,9 +254,11 @@ describe("BrainMobile", () => {
isDm: incomingWave?.chat?.scope?.group?.is_direct_message ?? false,
}));
mockUseMemesWaveFooterStats.mockReturnValue({
isAvailable: true,
isReady: true,
leftThisRoundCount: 3,
uncastPower: 5000,
unratedCount: 3,
unratedCount: 9,
votingLabel: "TDH",
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ describe("MemesWaveFooter", () => {
beforeEach(() => {
jest.clearAllMocks();
useMemesWaveFooterStatsMock.mockReturnValue({
isAvailable: false,
leftThisRoundCount: 0,
uncastPower: null,
unratedCount: 0,
votingLabel: null,
Expand All @@ -34,8 +36,10 @@ describe("MemesWaveFooter", () => {

it("renders the expanded footer card", () => {
useMemesWaveFooterStatsMock.mockReturnValue({
isAvailable: true,
leftThisRoundCount: 3,
uncastPower: 5000,
unratedCount: 3,
unratedCount: 12,
votingLabel: "TDH",
isReady: true,
});
Expand All @@ -44,13 +48,16 @@ describe("MemesWaveFooter", () => {

expect(screen.getByText("Uncast Power")).toBeInTheDocument();
expect(screen.getByText("5,000 TDH")).toBeInTheDocument();
expect(screen.getByText("3 left")).toBeInTheDocument();
expect(screen.getByText("3 left this round")).toBeInTheDocument();
expect(screen.getByText("12 unrated")).toBeInTheDocument();
});

it("calls onOpenQuickVote from the expanded card", () => {
useMemesWaveFooterStatsMock.mockReturnValue({
isAvailable: true,
leftThisRoundCount: 3,
uncastPower: 5000,
unratedCount: 3,
unratedCount: 12,
votingLabel: "TDH",
isReady: true,
});
Expand All @@ -64,7 +71,7 @@ describe("MemesWaveFooter", () => {

fireEvent.click(
screen.getByRole("button", {
name: "Uncast Power, 5,000 TDH, 3 left",
name: "Uncast Power, 5,000 TDH left, 3 left this round, 12 unrated",
})
);

Expand All @@ -73,8 +80,10 @@ describe("MemesWaveFooter", () => {

it("prefetches quick vote from the expanded card on hover and focus", () => {
useMemesWaveFooterStatsMock.mockReturnValue({
isAvailable: true,
leftThisRoundCount: 3,
uncastPower: 5000,
unratedCount: 3,
unratedCount: 12,
votingLabel: "TDH",
isReady: true,
});
Expand All @@ -87,7 +96,7 @@ describe("MemesWaveFooter", () => {
);

const button = screen.getByRole("button", {
name: "Uncast Power, 5,000 TDH, 3 left",
name: "Uncast Power, 5,000 TDH left, 3 left this round, 12 unrated",
});

fireEvent.mouseEnter(button);
Expand All @@ -98,8 +107,10 @@ describe("MemesWaveFooter", () => {

it("renders the compact collapsed pill", () => {
useMemesWaveFooterStatsMock.mockReturnValue({
isAvailable: true,
leftThisRoundCount: 4,
uncastPower: 5000,
unratedCount: 4,
unratedCount: 9,
votingLabel: "TDH",
isReady: true,
});
Expand All @@ -115,15 +126,17 @@ describe("MemesWaveFooter", () => {
expect(screen.queryByText("Uncast Power")).not.toBeInTheDocument();
expect(
screen.getByRole("button", {
name: "4 submissions left unrated in memes wave",
name: "4 left this round, 9 unrated in the memes wave",
})
).toBeInTheDocument();
});

it("calls onOpenQuickVote from the collapsed pill", () => {
useMemesWaveFooterStatsMock.mockReturnValue({
isAvailable: true,
leftThisRoundCount: 4,
uncastPower: 5000,
unratedCount: 4,
unratedCount: 9,
votingLabel: "TDH",
isReady: true,
});
Expand All @@ -132,7 +145,7 @@ describe("MemesWaveFooter", () => {

fireEvent.click(
screen.getByRole("button", {
name: "4 submissions left unrated in memes wave",
name: "4 left this round, 9 unrated in the memes wave",
})
);

Expand All @@ -141,8 +154,10 @@ describe("MemesWaveFooter", () => {

it("prefetches quick vote from the collapsed pill on hover and focus", () => {
useMemesWaveFooterStatsMock.mockReturnValue({
isAvailable: true,
leftThisRoundCount: 4,
uncastPower: 5000,
unratedCount: 4,
unratedCount: 9,
votingLabel: "TDH",
isReady: true,
});
Expand All @@ -156,7 +171,7 @@ describe("MemesWaveFooter", () => {
);

const button = screen.getByRole("button", {
name: "4 submissions left unrated in memes wave",
name: "4 left this round, 9 unrated in the memes wave",
});

fireEvent.mouseEnter(button);
Expand All @@ -167,6 +182,8 @@ describe("MemesWaveFooter", () => {

it("ignores expanded-card clicks when no submissions remain", () => {
useMemesWaveFooterStatsMock.mockReturnValue({
isAvailable: false,
leftThisRoundCount: 0,
uncastPower: 5000,
unratedCount: 0,
votingLabel: "TDH",
Expand All @@ -180,14 +197,6 @@ describe("MemesWaveFooter", () => {
/>
);

const button = screen.getByRole("button", {
name: "Uncast Power, 5,000 TDH, 0 left",
});

fireEvent.mouseEnter(button);
fireEvent.click(button);

expect(onOpenQuickVote).not.toHaveBeenCalled();
expect(onPrefetchQuickVote).not.toHaveBeenCalled();
expect(screen.queryByRole("button")).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ jest.mock(
() => ({
__esModule: true,
default: ({
leftThisRoundCount,
onOpenQuickVote,
onPrefetchQuickVote,
unratedCount,
unratedCount: _unratedCount,
}: {
readonly leftThisRoundCount: number;
readonly onOpenQuickVote: () => void;
readonly onPrefetchQuickVote?: (() => void) | undefined;
readonly unratedCount: number;
Expand All @@ -26,7 +28,7 @@ jest.mock(
onFocus={onPrefetchQuickVote}
onMouseEnter={onPrefetchQuickVote}
>
{unratedCount}
{leftThisRoundCount}
</button>
),
})
Expand All @@ -44,7 +46,9 @@ describe("FloatingMemesQuickVoteTrigger", () => {
beforeEach(() => {
jest.clearAllMocks();
useMemesWaveFooterStatsMock.mockReturnValue({
isAvailable: false,
isReady: false,
leftThisRoundCount: 0,
uncastPower: null,
unratedCount: 0,
votingLabel: null,
Expand All @@ -64,9 +68,11 @@ describe("FloatingMemesQuickVoteTrigger", () => {

it("passes hover and focus prefetch intent through to the floating trigger", () => {
useMemesWaveFooterStatsMock.mockReturnValue({
isAvailable: true,
isReady: true,
leftThisRoundCount: 3,
uncastPower: 5000,
unratedCount: 3,
unratedCount: 9,
votingLabel: "TDH",
});

Expand Down
71 changes: 23 additions & 48 deletions __tests__/hooks/useMemesWaveFooterStats.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,14 @@ describe("useMemesWaveFooterStats", () => {

it("fetches the first unvoted leaderboard item and derives footer stats from it", async () => {
commonApiFetchMock.mockResolvedValue({
count: 2,
page: 1,
next: true,
wave: {
id: "memes-wave",
name: "The Memes",
voting_credit_type: ApiWaveCreditType.Tdh,
authenticated_user_eligible_to_vote: true,
voting_period_start: null,
voting_period_end: null,
},
drops: [
createDrop({
id: "drop-40",
serialNo: 40,
rating: 0,
maxRating: 5_000,
}),
],
drop: createDrop({
id: "drop-40",
serialNo: 40,
rating: 0,
maxRating: 5_000,
}),
left_to_vote_in_current_round: 2,
total_count: 7,
} as any);

const { result } = renderHook(() => useMemesWaveFooterStats(), {
Expand All @@ -172,45 +161,30 @@ describe("useMemesWaveFooterStats", () => {

await waitFor(() => expect(result.current.isReady).toBe(true));

expect(result.current.leftThisRoundCount).toBe(2);
expect(result.current.uncastPower).toBe(5_000);
expect(result.current.unratedCount).toBe(2);
expect(result.current.unratedCount).toBe(7);
expect(result.current.votingLabel).toBe("TDH");
expect(commonApiFetchMock).toHaveBeenCalledTimes(1);
expect(commonApiFetchMock).toHaveBeenCalledWith({
endpoint: "waves/memes-wave/leaderboard",
params: {
page: "1",
page_size: "1",
sort: "CREATED_AT",
sort_direction: "DESC",
unvoted_by_me: "true",
},
endpoint: "waves/memes-wave/undiscovered-drop",
params: undefined,
signal: expect.any(AbortSignal),
});
});

it("stays hidden when the summary response does not include usable vote context", async () => {
commonApiFetchMock.mockResolvedValue({
count: 1,
page: 1,
next: false,
wave: {
id: "memes-wave",
name: "The Memes",
voting_credit_type: ApiWaveCreditType.Tdh,
authenticated_user_eligible_to_vote: true,
voting_period_start: null,
voting_period_end: null,
drop: {
...createDrop({
id: "drop-40",
serialNo: 40,
rating: 0,
}),
context_profile_context: null,
},
drops: [
{
...createDrop({
id: "drop-40",
serialNo: 40,
rating: 0,
}),
context_profile_context: null,
},
],
left_to_vote_in_current_round: 1,
total_count: 1,
} as any);

const { result } = renderHook(() => useMemesWaveFooterStats(), {
Expand All @@ -220,6 +194,7 @@ describe("useMemesWaveFooterStats", () => {
await waitFor(() => expect(commonApiFetchMock).toHaveBeenCalledTimes(1));

expect(result.current.isReady).toBe(false);
expect(result.current.leftThisRoundCount).toBe(0);
expect(result.current.uncastPower).toBeNull();
expect(result.current.unratedCount).toBe(0);
expect(result.current.votingLabel).toBeNull();
Expand Down
Loading
Loading