Replace batch prompt with custom dialog

This commit is contained in:
2026-04-29 17:23:04 +08:00
parent 37e29bd6b8
commit 376c7b510e
3 changed files with 366 additions and 3 deletions
+117
View File
@@ -1728,6 +1728,114 @@ describe("market-content-entry", () => {
expect(submitBatch.mock.calls[0]?.[0]).not.toHaveProperty("batchId");
});
test("opens a custom batch name dialog before submitting", async () => {
document.body.innerHTML = buildMarketFixture();
const submitBatch = vi.fn(async () => ({ ok: true }));
const { createMarketController } = await import("../src/content/market/index");
const controller = trackController(createMarketController({
document,
getAuthState: async () => ({
isAuthenticated: true,
resource: "https://talent-search.intelligrow.cn",
userInfo: { name: "王少卿", sub: "p7pdhhtde8kj" }
}),
loadAuthorMetrics: async () => ({
success: false,
reason: "request-failed"
}),
submitBatch,
window
}));
await controller.ready;
click('[data-plugin-batch-submit="button"]');
expect(submitBatch).not.toHaveBeenCalled();
expect(
document.querySelector('[data-plugin-batch-name-dialog="root"]')
).not.toBeNull();
setInputValue('[data-plugin-batch-name-input="input"]', "618达人筛选第一批");
dispatchInput('[data-plugin-batch-name-input="input"]');
click('[data-plugin-batch-name-confirm="button"]');
await waitForMockCall(submitBatch, 40, 50);
expect(submitBatch).toHaveBeenCalledWith(
expect.objectContaining({
batchName: "618达人筛选第一批"
})
);
expect(
document.querySelector('[data-plugin-batch-name-dialog="root"]')
).toBeNull();
});
test("keeps the custom batch name dialog open and shows an inline error for blank values", async () => {
document.body.innerHTML = buildMarketFixture();
const submitBatch = vi.fn(async () => ({ ok: true }));
const { createMarketController } = await import("../src/content/market/index");
const controller = trackController(createMarketController({
document,
getAuthState: async () => ({
isAuthenticated: true,
resource: "https://talent-search.intelligrow.cn",
userInfo: { name: "王少卿", sub: "p7pdhhtde8kj" }
}),
loadAuthorMetrics: async () => ({
success: false,
reason: "request-failed"
}),
submitBatch,
window
}));
await controller.ready;
click('[data-plugin-batch-submit="button"]');
click('[data-plugin-batch-name-confirm="button"]');
await flush();
expect(submitBatch).not.toHaveBeenCalled();
expect(
document.querySelector('[data-plugin-batch-name-error="text"]')?.textContent
).toContain("请输入批次名称");
expect(
document.querySelector('[data-plugin-batch-name-dialog="root"]')
).not.toBeNull();
});
test("closes the custom batch name dialog when cancelled", async () => {
document.body.innerHTML = buildMarketFixture();
const submitBatch = vi.fn(async () => ({ ok: true }));
const { createMarketController } = await import("../src/content/market/index");
const controller = trackController(createMarketController({
document,
getAuthState: async () => ({
isAuthenticated: true,
resource: "https://talent-search.intelligrow.cn",
userInfo: { name: "王少卿", sub: "p7pdhhtde8kj" }
}),
loadAuthorMetrics: async () => ({
success: false,
reason: "request-failed"
}),
submitBatch,
window
}));
await controller.ready;
click('[data-plugin-batch-submit="button"]');
click('[data-plugin-batch-name-cancel="button"]');
await flush();
expect(submitBatch).not.toHaveBeenCalled();
expect(
document.querySelector('[data-plugin-batch-name-dialog="root"]')
).toBeNull();
});
test("selected batch submit uses only creators selected in the current range", async () => {
document.body.innerHTML = buildRealMarketFixture([
{ authorId: "111", authorName: "达人 A", price21To60s: "¥11,000" },
@@ -3873,6 +3981,15 @@ function setInputValue(selector: string, value: string) {
element.value = value;
}
function dispatchInput(selector: string) {
const element = document.querySelector(selector) as HTMLElement | null;
if (!element) {
throw new Error(`Missing element: ${selector}`);
}
element.dispatchEvent(new Event("input"));
}
function setSelectValue(selector: string, value: string) {
const element = document.querySelector(selector) as HTMLSelectElement | null;
if (!element) {