feat: add batch submit toolbar action
This commit is contained in:
@@ -44,14 +44,21 @@ describe("market-content-entry", () => {
|
||||
const createMarketController = vi.fn(() => ({
|
||||
ready: Promise.resolve()
|
||||
}));
|
||||
const sendMessage = vi.fn(async () => ({
|
||||
ok: true,
|
||||
type: "auth:state",
|
||||
value: { isAuthenticated: true }
|
||||
}));
|
||||
|
||||
window.history.replaceState({}, "", "/ad/creator/market");
|
||||
(
|
||||
globalThis as typeof globalThis & {
|
||||
chrome?: { runtime?: object };
|
||||
chrome?: { runtime?: { sendMessage?: (message: unknown) => Promise<unknown> } };
|
||||
}
|
||||
).chrome = {
|
||||
runtime: {}
|
||||
runtime: {
|
||||
sendMessage
|
||||
}
|
||||
};
|
||||
|
||||
vi.doMock("../src/content/market/index", () => ({
|
||||
@@ -72,7 +79,12 @@ describe("market-content-entry", () => {
|
||||
|
||||
const { bootContentScript } = await import("../src/content/index");
|
||||
await bootContentScript({
|
||||
createMarketController
|
||||
createMarketController,
|
||||
sendAuthMessage: vi.fn(async () => ({
|
||||
ok: true,
|
||||
type: "auth:state",
|
||||
value: { isAuthenticated: true }
|
||||
}))
|
||||
});
|
||||
|
||||
expect(createMarketController).toHaveBeenCalledTimes(1);
|
||||
@@ -90,6 +102,11 @@ describe("market-content-entry", () => {
|
||||
await bootContentScript({
|
||||
createMarketController,
|
||||
document,
|
||||
sendAuthMessage: vi.fn(async () => ({
|
||||
ok: true,
|
||||
type: "auth:state",
|
||||
value: { isAuthenticated: true }
|
||||
})),
|
||||
window: {
|
||||
location: {
|
||||
href: "https://www.xingtu.cn/ad/creator/market"
|
||||
@@ -128,7 +145,12 @@ describe("market-content-entry", () => {
|
||||
|
||||
const { bootContentScript } = await import("../src/content/index");
|
||||
await bootContentScript({
|
||||
createMarketController
|
||||
createMarketController,
|
||||
sendAuthMessage: vi.fn(async () => ({
|
||||
ok: true,
|
||||
type: "auth:state",
|
||||
value: { isAuthenticated: true }
|
||||
}))
|
||||
});
|
||||
|
||||
const controllerOptions = createMarketController.mock.calls[0]?.[0];
|
||||
@@ -163,8 +185,14 @@ describe("market-content-entry", () => {
|
||||
};
|
||||
|
||||
const { bootContentScript } = await import("../src/content/index");
|
||||
sendMessage.mockClear();
|
||||
await bootContentScript({
|
||||
createMarketController
|
||||
createMarketController,
|
||||
sendAuthMessage: vi.fn(async () => ({
|
||||
ok: true,
|
||||
type: "auth:state",
|
||||
value: { isAuthenticated: true }
|
||||
}))
|
||||
});
|
||||
|
||||
const controllerOptions = createMarketController.mock.calls[0]?.[0];
|
||||
@@ -213,6 +241,28 @@ describe("market-content-entry", () => {
|
||||
).toBe("0.03% - 0.2%");
|
||||
});
|
||||
|
||||
test("boots the controller only after auth succeeds", async () => {
|
||||
const createMarketController = vi.fn(() => ({
|
||||
ready: Promise.resolve()
|
||||
}));
|
||||
|
||||
window.history.replaceState({}, "", "/ad/creator/market");
|
||||
|
||||
const { bootContentScript } = await import("../src/content/index");
|
||||
await bootContentScript({
|
||||
createMarketController,
|
||||
document,
|
||||
sendAuthMessage: vi.fn(async () => ({
|
||||
ok: true,
|
||||
type: "auth:state",
|
||||
value: { isAuthenticated: true }
|
||||
})),
|
||||
window
|
||||
});
|
||||
|
||||
expect(createMarketController).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("hydrates the real div-grid market rows on start", async () => {
|
||||
document.body.innerHTML = buildRealMarketFixture([
|
||||
{
|
||||
@@ -481,6 +531,9 @@ describe("market-content-entry", () => {
|
||||
|
||||
expect(exportRangeSelect?.value).toBe("first-5");
|
||||
expect(customPagesInput?.hidden).toBe(true);
|
||||
expect(
|
||||
document.querySelector('[data-plugin-batch-submit="button"]')
|
||||
).not.toBeNull();
|
||||
|
||||
setSelectValue('[data-plugin-export-range="select"]', "custom");
|
||||
dispatchChange('[data-plugin-export-range="select"]');
|
||||
@@ -731,6 +784,7 @@ describe("market-content-entry", () => {
|
||||
|
||||
click('[data-plugin-export="button"]');
|
||||
|
||||
expectButtonDisabled('[data-plugin-batch-submit="button"]', true);
|
||||
expectButtonDisabled('[data-plugin-export="button"]', true);
|
||||
expectButtonDisabled('[data-plugin-filter-apply="button"]', true);
|
||||
expectButtonDisabled('[data-plugin-sort-apply="button"]', true);
|
||||
@@ -742,6 +796,7 @@ describe("market-content-entry", () => {
|
||||
await waitForMockCall(buildCsv, 80, 100);
|
||||
|
||||
expect(pagination.getClicks()).toBe(2);
|
||||
expectButtonDisabled('[data-plugin-batch-submit="button"]', false);
|
||||
expectButtonDisabled('[data-plugin-export="button"]', false);
|
||||
expectSelectDisabled('[data-plugin-export-range="select"]', false);
|
||||
expect(buildCsv).toHaveBeenCalledTimes(1);
|
||||
|
||||
Reference in New Issue
Block a user