feat: redesign popup update panel
This commit is contained in:
@@ -3,6 +3,10 @@ import { beforeEach, describe, expect, test, vi } from "vitest";
|
||||
|
||||
import { bootPopup } from "../src/popup/index";
|
||||
|
||||
function flushTasks(): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, 0));
|
||||
}
|
||||
|
||||
describe("popup-entry", () => {
|
||||
let dom: JSDOM;
|
||||
|
||||
@@ -22,6 +26,12 @@ describe("popup-entry", () => {
|
||||
}))
|
||||
});
|
||||
|
||||
expect(
|
||||
dom.window.document.querySelector('[data-popup-shell="root"]')
|
||||
).not.toBeNull();
|
||||
expect(
|
||||
dom.window.document.querySelector('[data-popup-account="card"]')
|
||||
).not.toBeNull();
|
||||
expect(dom.window.document.querySelector("button")?.textContent).toContain(
|
||||
"登录"
|
||||
);
|
||||
@@ -47,6 +57,12 @@ describe("popup-entry", () => {
|
||||
}))
|
||||
});
|
||||
|
||||
expect(
|
||||
dom.window.document.querySelector('[data-popup-header="root"]')
|
||||
).not.toBeNull();
|
||||
expect(
|
||||
dom.window.document.querySelector('[data-popup-account="card"]')
|
||||
).not.toBeNull();
|
||||
expect(dom.window.document.body.textContent).toContain("resource");
|
||||
expect(dom.window.document.body.textContent).toContain("token");
|
||||
});
|
||||
@@ -76,12 +92,16 @@ describe("popup-entry", () => {
|
||||
}
|
||||
}))
|
||||
});
|
||||
await Promise.resolve();
|
||||
await flushTasks();
|
||||
await flushTasks();
|
||||
|
||||
expect(fetchUpdateManifest).toHaveBeenCalledTimes(1);
|
||||
expect(dom.window.document.body.textContent).toContain("当前版本:0.2.0421.2");
|
||||
expect(dom.window.document.body.textContent).toContain("发现新版本:0.2.0421.3");
|
||||
expect(dom.window.document.body.textContent).toContain("支持检查更新");
|
||||
expect(
|
||||
dom.window.document.querySelector('[data-popup-update="card"]')
|
||||
).not.toBeNull();
|
||||
expect(
|
||||
dom.window.document.querySelector('[data-popup-download-update="button"]')
|
||||
).not.toBeNull();
|
||||
@@ -118,7 +138,8 @@ describe("popup-entry", () => {
|
||||
})),
|
||||
sendMessage
|
||||
});
|
||||
await Promise.resolve();
|
||||
await flushTasks();
|
||||
await flushTasks();
|
||||
|
||||
(
|
||||
dom.window.document.querySelector(
|
||||
@@ -245,6 +266,63 @@ describe("popup-entry", () => {
|
||||
expect(sendMessage).toHaveBeenCalledWith({ type: "auth:sign-out" });
|
||||
});
|
||||
|
||||
test("shows the latest state without update actions", async () => {
|
||||
dom.window.document.body.innerHTML = "<main id='app'></main>";
|
||||
|
||||
await bootPopup({
|
||||
currentVersion: "0.0525.5",
|
||||
document: dom.window.document,
|
||||
fetchUpdateManifest: vi.fn(async () => ({
|
||||
guideUrl: "https://cos.example.com/guide.pdf",
|
||||
latestVersion: "0.0525.5",
|
||||
minSupportedVersion: "0.0525.5",
|
||||
publishedAt: "2026-05-19",
|
||||
releaseNotes: ["支持检查更新"],
|
||||
zipUrl: "https://cos.example.com/plugin.zip"
|
||||
})),
|
||||
sendMessage: vi.fn(async () => ({
|
||||
ok: true,
|
||||
type: "auth:state",
|
||||
value: {
|
||||
isAuthenticated: true,
|
||||
userInfo: { name: "Dev" }
|
||||
}
|
||||
}))
|
||||
});
|
||||
await flushTasks();
|
||||
await flushTasks();
|
||||
|
||||
expect(dom.window.document.body.textContent).toContain("当前已是最新版本");
|
||||
expect(
|
||||
dom.window.document.querySelector('[data-popup-download-update="button"]')
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
test("shows a readable error state when the manifest fetch fails", async () => {
|
||||
dom.window.document.body.innerHTML = "<main id='app'></main>";
|
||||
|
||||
await bootPopup({
|
||||
currentVersion: "0.0525.5",
|
||||
document: dom.window.document,
|
||||
fetchUpdateManifest: vi.fn(async () => {
|
||||
throw new Error("network down");
|
||||
}),
|
||||
sendMessage: vi.fn(async () => ({
|
||||
ok: true,
|
||||
type: "auth:state",
|
||||
value: {
|
||||
isAuthenticated: true,
|
||||
userInfo: { name: "Dev" }
|
||||
}
|
||||
}))
|
||||
});
|
||||
await flushTasks();
|
||||
await flushTasks();
|
||||
|
||||
expect(dom.window.document.body.textContent).toContain("暂时无法检查更新");
|
||||
expect(dom.window.document.body.textContent).toContain("network down");
|
||||
});
|
||||
|
||||
test("shows the auth error when sign-in fails", async () => {
|
||||
const sendMessage = vi
|
||||
.fn()
|
||||
|
||||
Reference in New Issue
Block a user