Testing Link Header Pagination Extraction in OpenHands
This test suite validates the extractNextPageFromLink utility function which parses GitHub API pagination links to extract the next page number. The tests verify correct handling of link headers with various pagination scenarios and edge cases.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
all-hands-ai/openhands
frontend/__tests__/utils/extract-next-page-from-link.test.ts
import { expect, test } from "vitest";
import { extractNextPageFromLink } from "#/utils/extract-next-page-from-link";
test("extractNextPageFromLink", () => {
const link = `<https://api.github.com/repositories/1300192/issues?page=2>; rel="prev", <https://api.github.com/repositories/1300192/issues?page=4>; rel="next", <https://api.github.com/repositories/1300192/issues?page=515>; rel="last", <https://api.github.com/repositories/1300192/issues?page=1>; rel="first"`;
expect(extractNextPageFromLink(link)).toBe(4);
const noNextLink = `<https://api.github.com/repositories/1300192/issues?page=2>; rel="prev", <https://api.github.com/repositories/1300192/issues?page=1>; rel="first"`;
expect(extractNextPageFromLink(noNextLink)).toBeNull();
const extra = `<https://api.github.com/user/repos?sort=pushed&page=2&per_page=3>; rel="next", <https://api.github.com/user/repos?sort=pushed&page=22&per_page=3>; rel="last"`;
expect(extractNextPageFromLink(extra)).toBe(2);
});