feat: honor all-range export and batch scope

This commit is contained in:
wxs
2026-07-27 16:00:57 +08:00
parent e15bc0657a
commit e03dedd91e
5 changed files with 293 additions and 47 deletions
+50
View File
@@ -155,6 +155,56 @@ describe("silent-export-controller", () => {
expect(records?.map((record) => record.authorId)).toEqual(["2", "3"]);
});
test("starts all-result exports from page 1 even after browsing to a later page", async () => {
document.documentElement.setAttribute(
"data-sces-market-request-snapshot",
JSON.stringify({
body: JSON.stringify({
page_param: {
page: 2
}
}),
method: "POST",
url: "https://xingtu.cn/api/mock-market-search"
})
);
const requestedPages: number[] = [];
const controller = createSilentExportController({
document,
fetchImpl: async (_url, init) => {
const body = JSON.parse(String(init?.body ?? "{}")) as {
page_param?: { page?: number };
};
const pageNo = body.page_param?.page ?? 0;
requestedPages.push(pageNo);
return {
json: async () => ({
authors: [
{
attribute_datas: {
nickname: `达人${pageNo}`
},
star_id: String(pageNo)
}
],
pagination: {
page: pageNo,
totalPages: 3
}
}),
ok: true
};
}
});
const records = await controller.exportRecords({ mode: "all" });
expect(requestedPages).toEqual([1, 2, 3]);
expect(records?.map((record) => record.authorId)).toEqual(["1", "2", "3"]);
});
test("keeps attribute_datas.id as the spread author id while preserving star_id as row id", async () => {
document.documentElement.setAttribute(
"data-sces-market-request-snapshot",