Prepare internal extension distribution
This commit is contained in:
@@ -7,7 +7,7 @@ describe("auth-config", () => {
|
||||
expect(readAuthConfig()).toEqual({
|
||||
apiResource: "https://talent-search.intelligrow.cn",
|
||||
appId: "i4jkllbvih0554r4n0fd3",
|
||||
enableDevAuthPanel: true,
|
||||
enableDevAuthPanel: false,
|
||||
logtoEndpoint: "https://login-api.intelligrow.cn",
|
||||
scopes: [
|
||||
"openid",
|
||||
|
||||
@@ -164,7 +164,6 @@ describe("background-index", () => {
|
||||
{
|
||||
payload: {
|
||||
authors: [{ authorId: "111", authorName: "达人A" }],
|
||||
batchId: "批次A-2026-04-22T12:30:00.000Z",
|
||||
batchName: "批次A",
|
||||
createdAt: "2026-04-22T12:30:00.000Z",
|
||||
creatorName: "王少卿",
|
||||
@@ -182,9 +181,10 @@ describe("background-index", () => {
|
||||
|
||||
expect(submitBatch).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
batchId: "批次A-2026-04-22T12:30:00.000Z"
|
||||
batchName: "批次A"
|
||||
})
|
||||
);
|
||||
expect(submitBatch.mock.calls[0]?.[0]).not.toHaveProperty("batchId");
|
||||
expect(sendResponse).toHaveBeenCalledWith({
|
||||
ok: true,
|
||||
type: "batch:ack",
|
||||
|
||||
@@ -3,7 +3,7 @@ import { describe, expect, test } from "vitest";
|
||||
import { createBatchPayload } from "../src/content/market/batch-payload";
|
||||
|
||||
describe("batch-payload", () => {
|
||||
test("builds a batch id from the user id and timestamp", () => {
|
||||
test("builds the batch payload without a client-side batch id", () => {
|
||||
const payload = createBatchPayload({
|
||||
authState: {
|
||||
isAuthenticated: true,
|
||||
@@ -26,7 +26,6 @@ describe("batch-payload", () => {
|
||||
{ authorId: "111", authorName: "达人A" },
|
||||
{ authorId: "222", authorName: "达人B" }
|
||||
],
|
||||
batchId: "p7pdhhtde8kj-2026-04-22T12:30:00.000Z",
|
||||
batchName: "618达人筛选第一批",
|
||||
createdAt: "2026-04-22T12:30:00.000Z",
|
||||
creatorName: "王少卿",
|
||||
|
||||
@@ -36,7 +36,6 @@ describe("batch-submit-client", () => {
|
||||
|
||||
await client.submitBatch({
|
||||
authors: [{ authorId: "111", authorName: "达人A" }],
|
||||
batchId: "批次A-2026-04-22T12:30:00.000Z",
|
||||
batchName: "批次A",
|
||||
createdAt: "2026-04-22T12:30:00.000Z",
|
||||
creatorName: "王少卿",
|
||||
@@ -49,7 +48,6 @@ describe("batch-submit-client", () => {
|
||||
expect.objectContaining({
|
||||
body: JSON.stringify({
|
||||
authors: [{ authorId: "111", authorName: "达人A" }],
|
||||
batchId: "批次A-2026-04-22T12:30:00.000Z",
|
||||
batchName: "批次A",
|
||||
createdAt: "2026-04-22T12:30:00.000Z",
|
||||
creatorName: "王少卿",
|
||||
@@ -87,7 +85,6 @@ describe("batch-submit-client", () => {
|
||||
await expect(
|
||||
client.submitBatch({
|
||||
authors: [],
|
||||
batchId: "批次A-2026-04-22T12:30:00.000Z",
|
||||
batchName: "批次A",
|
||||
createdAt: "2026-04-22T12:30:00.000Z",
|
||||
creatorName: "王少卿",
|
||||
@@ -115,7 +112,6 @@ describe("batch-submit-client", () => {
|
||||
await expect(
|
||||
client.submitBatch({
|
||||
authors: [],
|
||||
batchId: "批次A-2026-04-22T12:30:00.000Z",
|
||||
batchName: "批次A",
|
||||
createdAt: "2026-04-22T12:30:00.000Z",
|
||||
creatorName: "王少卿",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import manifest from "../src/manifest.json";
|
||||
import { createManifest } from "../scripts/manifest.mjs";
|
||||
|
||||
describe("manifest", () => {
|
||||
test("injects the content script on the www Xingtu market page", () => {
|
||||
@@ -16,6 +17,9 @@ describe("manifest", () => {
|
||||
expect(manifest.permissions).toEqual(
|
||||
expect.arrayContaining(["downloads", "identity", "storage"])
|
||||
);
|
||||
expect(manifest.key).toBe(
|
||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0CaZJxcX97TbRXCR08L10t9EZFV31+wPnUgDf21j2f0qYaWdblzWXfVkeU9jGb2Hr2Etpp7F/XuBa6pcipUXkzMMBkJ42KOkciAwbuzTBoAtGB8o9aoWigtax+gGfSz+T3BjqxKBJtXqeqbIAKCDIlxRKIrY+KcY1Z+mD5BKcBHKsUDQPlHsrjc1g0wIBD5doz9LoOk1Wso6gK5cSeOp9lw5YHcu4TImR4yqxGiL6pZwnpciuX/g7qjWBZXn5gf0YBlDsBDDTt5upbP3NguUKgO2qA9M77LyeUwXl3aqbIxYi/VwsQ2t5w9PGWtnOUQQDWUcEg/9dfTb89esZXKATwIDAQAB"
|
||||
);
|
||||
expect(manifest.host_permissions).toEqual(
|
||||
expect.arrayContaining([
|
||||
"http://*/*",
|
||||
@@ -27,4 +31,38 @@ describe("manifest", () => {
|
||||
expect(manifest.background?.service_worker).toBe("background/index.js");
|
||||
expect(manifest.action?.default_popup).toBe("popup/index.html");
|
||||
});
|
||||
|
||||
test("builds a release manifest with narrowed host permissions", () => {
|
||||
const releaseManifest = createManifest({ target: "release" });
|
||||
|
||||
expect(releaseManifest.permissions).toEqual(
|
||||
expect.arrayContaining(["downloads", "identity", "storage"])
|
||||
);
|
||||
expect(releaseManifest.host_permissions).toEqual([
|
||||
"https://xingtu.cn/ad/creator/market*",
|
||||
"https://*.xingtu.cn/ad/creator/market*",
|
||||
"https://login-api.intelligrow.cn/*",
|
||||
"https://talent-search.intelligrow.cn/*",
|
||||
"http://192.168.31.21:8083/*"
|
||||
]);
|
||||
expect(releaseManifest.host_permissions).not.toEqual(
|
||||
expect.arrayContaining(["http://*/*", "https://*/*", "http://127.0.0.1:4319/*"])
|
||||
);
|
||||
});
|
||||
|
||||
test("builds a release manifest with extension icons", () => {
|
||||
const releaseManifest = createManifest({ target: "release" });
|
||||
|
||||
expect(releaseManifest.icons).toEqual({
|
||||
"16": "assets/icons/icon-16.png",
|
||||
"32": "assets/icons/icon-32.png",
|
||||
"48": "assets/icons/icon-48.png",
|
||||
"128": "assets/icons/icon-128.png"
|
||||
});
|
||||
expect(releaseManifest.key).toBe(manifest.key);
|
||||
expect(releaseManifest.action?.default_icon).toEqual({
|
||||
"16": "assets/icons/icon-16.png",
|
||||
"32": "assets/icons/icon-32.png"
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1535,6 +1535,117 @@ describe("market-content-entry", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test(
|
||||
"selected export keeps a generic loading status while exporting the default paged range",
|
||||
async () => {
|
||||
const pages = [
|
||||
[
|
||||
{ authorId: "111", authorName: "达人 A", price21To60s: "¥11,000" },
|
||||
{ authorId: "222", authorName: "达人 B", price21To60s: "¥22,000" }
|
||||
],
|
||||
[{ authorId: "333", authorName: "达人 C", price21To60s: "¥33,000" }],
|
||||
[{ authorId: "444", authorName: "达人 D", price21To60s: "¥44,000" }],
|
||||
[{ authorId: "555", authorName: "达人 E", price21To60s: "¥55,000" }],
|
||||
[{ authorId: "666", authorName: "达人 F", price21To60s: "¥66,000" }]
|
||||
];
|
||||
const secondPageDeferred = createDeferred<{
|
||||
json(): Promise<unknown>;
|
||||
ok: boolean;
|
||||
}>();
|
||||
|
||||
document.body.innerHTML = buildRealMarketFixture(pages[0]);
|
||||
const buildCsv = vi.fn(() => "csv-output");
|
||||
const fetchMock = vi.fn(async (_input: string, init?: RequestInit) => {
|
||||
const body = JSON.parse(String(init?.body ?? "{}")) as { page?: number };
|
||||
const pageNumber = body.page ?? 1;
|
||||
const response = {
|
||||
json: async () => ({
|
||||
data: {
|
||||
marketList: buildMarketListResponseRows(pages[pageNumber - 1] ?? []),
|
||||
totalPages: 5
|
||||
}
|
||||
}),
|
||||
ok: true
|
||||
};
|
||||
|
||||
if (pageNumber === 2) {
|
||||
return secondPageDeferred.promise;
|
||||
}
|
||||
|
||||
return response;
|
||||
});
|
||||
|
||||
(
|
||||
globalThis as typeof globalThis & {
|
||||
fetch?: typeof fetchMock;
|
||||
}
|
||||
).fetch = fetchMock;
|
||||
document.documentElement.setAttribute(
|
||||
"data-sces-market-request-snapshot",
|
||||
JSON.stringify({
|
||||
body: JSON.stringify({
|
||||
page: 1
|
||||
}),
|
||||
method: "POST",
|
||||
url: "https://xingtu.cn/api/mock-market-search"
|
||||
})
|
||||
);
|
||||
|
||||
const { createMarketController } = await import("../src/content/market/index");
|
||||
const controller = trackController(createMarketController({
|
||||
buildCsv,
|
||||
document,
|
||||
loadAuthorMetrics: async () => ({
|
||||
success: false,
|
||||
reason: "request-failed"
|
||||
}),
|
||||
onCsvReady: vi.fn(),
|
||||
window
|
||||
}));
|
||||
|
||||
await controller.ready;
|
||||
clickSelectionCheckboxForAuthor("111");
|
||||
|
||||
click('[data-plugin-export="button"]');
|
||||
for (let attempt = 0; attempt < 40; attempt += 1) {
|
||||
if (
|
||||
fetchMock.mock.calls.some(([, init]) => {
|
||||
const body = JSON.parse(
|
||||
String((init as RequestInit | undefined)?.body ?? "{}")
|
||||
) as { page?: number };
|
||||
return body.page === 2;
|
||||
})
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
await Promise.resolve();
|
||||
}
|
||||
|
||||
expect(
|
||||
document.querySelector('[data-plugin-export-status="text"]')?.textContent
|
||||
).toBe("导出中...");
|
||||
|
||||
secondPageDeferred.resolve({
|
||||
json: async () => ({
|
||||
data: {
|
||||
marketList: buildMarketListResponseRows(pages[1]),
|
||||
totalPages: 5
|
||||
}
|
||||
}),
|
||||
ok: true
|
||||
});
|
||||
|
||||
await waitForMockCall(buildCsv, 120, 50);
|
||||
|
||||
expect(buildCsv.mock.calls[0][0].map((record) => record.authorId)).toEqual([
|
||||
"111"
|
||||
]);
|
||||
},
|
||||
15000
|
||||
);
|
||||
|
||||
test("selected export falls back to all creators in the current range when no selection matches", async () => {
|
||||
const pages = [
|
||||
[
|
||||
@@ -1610,11 +1721,11 @@ describe("market-content-entry", () => {
|
||||
expect(promptBatchName).toHaveBeenCalledTimes(1);
|
||||
expect(submitBatch).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
batchId: expect.stringContaining("p7pdhhtde8kj-"),
|
||||
batchName: "618达人筛选第一批",
|
||||
logtoUserId: "p7pdhhtde8kj"
|
||||
})
|
||||
);
|
||||
expect(submitBatch.mock.calls[0]?.[0]).not.toHaveProperty("batchId");
|
||||
});
|
||||
|
||||
test("selected batch submit uses only creators selected in the current range", async () => {
|
||||
|
||||
@@ -53,7 +53,6 @@ describe("mock-protected-api", () => {
|
||||
const response = await fetch(`${server.baseUrl}/api/mock/batches`, {
|
||||
body: JSON.stringify({
|
||||
authors: [{ authorId: "111", authorName: "达人A" }],
|
||||
batchId: "批次A-2026-04-22T12:30:00.000Z",
|
||||
batchName: "批次A",
|
||||
createdAt: "2026-04-22T12:30:00.000Z",
|
||||
creatorName: "王少卿",
|
||||
@@ -71,7 +70,7 @@ describe("mock-protected-api", () => {
|
||||
await expect(response.json()).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
acceptedCount: 1,
|
||||
batchId: "批次A-2026-04-22T12:30:00.000Z",
|
||||
batchId: null,
|
||||
ok: true,
|
||||
source: "mock-batch-submit"
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user