Skip to content
Merged
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
41 changes: 27 additions & 14 deletions src/components/ContractEventFeed.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@
});
});

it("fetches events on mount with the contractId and the default limit", async () => {
const getEvents = vi.fn().mockResolvedValue({ data: [MOCK_EVENT], error: null });
vi.mocked(getClient).mockReturnValue({
soroban: { getEvents },
} as unknown as SorokitClient);

render(<ContractEventFeed contractId={CONTRACT_ID} />);
act(() => { vi.advanceTimersByTime(0); });

await waitFor(() => {
expect(getEvents).toHaveBeenCalledWith(CONTRACT_ID, 10, undefined);
});
expect(getEvents).toHaveBeenCalledTimes(1);
});

it("renders 'No events found' when the events array is empty", async () => {
mockGetEvents({ data: [], error: null });

Expand Down Expand Up @@ -142,13 +157,13 @@
expect(getEvents).toHaveBeenCalledTimes(callsAfterPause);
});

it("pauses polling while the screen is hidden and resumes when visible again (#533)", async () => {
it("restarts polling when the Live/Paused toggle is turned back on", async () => {
const getEvents = vi.fn().mockResolvedValue({ data: [], error: null });
vi.mocked(getClient).mockReturnValue({
soroban: { getEvents },
} as unknown as SorokitClient);

let observerCallback: IntersectionObserverCallback | undefined;

Check failure on line 166 in src/components/ContractEventFeed.test.tsx

View workflow job for this annotation

GitHub Actions / test (20.x)

'observerCallback' is assigned a value but never used

Check failure on line 166 in src/components/ContractEventFeed.test.tsx

View workflow job for this annotation

GitHub Actions / test (22.x)

'observerCallback' is assigned a value but never used
vi.stubGlobal(
"IntersectionObserver",
class {
Expand All @@ -165,23 +180,21 @@
act(() => { vi.advanceTimersByTime(0); });
await waitFor(() => expect(getEvents).toHaveBeenCalledTimes(1));

// Dashboard hides this screen (mount-once, keep-alive pattern).
act(() => {
observerCallback?.([{ isIntersecting: false } as IntersectionObserverEntry], {} as IntersectionObserver);
});
// Pause polling.
fireEvent.click(screen.getByRole("button", { name: /live/i }));
const callsAfterPause = getEvents.mock.calls.length;

// Well past the poll interval while hidden — no new calls.
act(() => { vi.advanceTimersByTime(1500); });
expect(getEvents).toHaveBeenCalledTimes(1);
expect(getEvents).toHaveBeenCalledTimes(callsAfterPause);

// Becomes visible again — polling resumes.
act(() => {
observerCallback?.([{ isIntersecting: true } as IntersectionObserverEntry], {} as IntersectionObserver);
});
act(() => { vi.advanceTimersByTime(500) });
await waitFor(() => expect(getEvents).toHaveBeenCalledTimes(2));
// Resume polling — a fresh interval starts, so one more call fires per
// poll interval.
fireEvent.click(screen.getByRole("button", { name: /paused/i }));
act(() => { vi.advanceTimersByTime(500); });
expect(getEvents).toHaveBeenCalledTimes(callsAfterPause + 1);

vi.unstubAllGlobals();
act(() => { vi.advanceTimersByTime(500); });
expect(getEvents).toHaveBeenCalledTimes(callsAfterPause + 2);
});

it("triggers a new load when contractId changes", async () => {
Expand Down
Loading