feat: add logto auth and backend metrics integration
This commit is contained in:
@@ -241,6 +241,48 @@ describe("market-content-entry", () => {
|
||||
).toBe("0.03% - 0.2%");
|
||||
});
|
||||
|
||||
test("batch loads backend metrics for the visible page and renders the metrics panel", async () => {
|
||||
document.body.innerHTML = buildMarketFixture();
|
||||
const searchBackendMetrics = vi.fn(async (starIds: string[]) =>
|
||||
starIds
|
||||
.filter((starId) => starId === "a")
|
||||
.map((starId) => ({
|
||||
a3IncreaseCount: "78,366.22",
|
||||
afterViewSearchCount: "9,689.96",
|
||||
afterViewSearchRate: "0.36%",
|
||||
cpSearch: "14.46",
|
||||
cpa3: "1.79",
|
||||
newA3Rate: "3.44%",
|
||||
starId
|
||||
}))
|
||||
);
|
||||
|
||||
const { createMarketController } = await import("../src/content/market/index");
|
||||
const controller = trackController(createMarketController({
|
||||
document,
|
||||
loadAuthorMetrics: async () => ({
|
||||
success: false,
|
||||
reason: "request-failed"
|
||||
}),
|
||||
searchBackendMetrics,
|
||||
window
|
||||
}));
|
||||
|
||||
await controller.ready;
|
||||
|
||||
expect(searchBackendMetrics).toHaveBeenCalledTimes(1);
|
||||
expect(searchBackendMetrics).toHaveBeenCalledWith(["a", "b"]);
|
||||
expect(
|
||||
document.querySelector('[data-market-row-cell="backendMetrics"]')?.textContent
|
||||
).toContain("看后搜率");
|
||||
expect(
|
||||
document.querySelector('[data-market-row-cell="backendMetrics"]')?.textContent
|
||||
).toContain("0.36%");
|
||||
expect(
|
||||
document.querySelectorAll('[data-market-row-cell="backendMetrics"]')[1]?.textContent
|
||||
).toBe("暂无数据");
|
||||
});
|
||||
|
||||
test("boots the controller only after auth succeeds", async () => {
|
||||
const createMarketController = vi.fn(() => ({
|
||||
ready: Promise.resolve()
|
||||
@@ -302,12 +344,14 @@ describe("market-content-entry", () => {
|
||||
"¥450,000",
|
||||
"0.02% - 0.1%",
|
||||
"0.03% - 0.2%",
|
||||
"",
|
||||
"下单"
|
||||
]);
|
||||
expect(readDivRightRowTexts(1)).toEqual([
|
||||
"¥20,000",
|
||||
"0.5% - 1%",
|
||||
"0.01% - 0.1%",
|
||||
"",
|
||||
"下单"
|
||||
]);
|
||||
});
|
||||
@@ -368,12 +412,14 @@ describe("market-content-entry", () => {
|
||||
"¥450,000",
|
||||
"0.02%",
|
||||
"0.03% - 0.2%",
|
||||
"",
|
||||
"下单"
|
||||
]);
|
||||
expect(readDivRightRowTexts(1)).toEqual([
|
||||
"¥20,000",
|
||||
"0.5% - 1%",
|
||||
"0.01% - 0.1%",
|
||||
"",
|
||||
"下单"
|
||||
]);
|
||||
});
|
||||
@@ -429,12 +475,14 @@ describe("market-content-entry", () => {
|
||||
"¥450,000",
|
||||
"0.02%",
|
||||
"0.03% - 0.2%",
|
||||
"",
|
||||
"下单"
|
||||
]);
|
||||
expect(readDivRightRowTexts(1)).toEqual([
|
||||
"¥20,000",
|
||||
"0.5% - 1%",
|
||||
"0.01% - 0.1%",
|
||||
"",
|
||||
"下单"
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user