返回 DeepSeek-Reasonix
about-settings-updater-capability.test.tsx
根目录 / desktop / frontend / src / __tests__ / about-settings-updater-capability.test.tsx
1 import assert from "node:assert/strict";
2 import { JSDOM } from "jsdom";
3 import React, { act } from "react";
4 import { createRoot } from "react-dom/client";
5 import { SettingsPanel } from "../components/SettingsPanel";
6 import { LocaleProvider } from "../lib/i18n";
7 import { UpdaterProvider } from "../lib/useUpdater";
8 import { baseSettings, flushPromises } from "../test-support/settingsTestFixtures";
9 import { installDesktopHostStub } from "./desktopHostStub";
10
11 const dom = new JSDOM("<!doctype html><div id='root'></div>", { url: "http://localhost", pretendToBeVisual: true });
12 Object.assign(globalThis, {
13 window: dom.window,
14 document: dom.window.document,
15 HTMLElement: dom.window.HTMLElement,
16 Node: dom.window.Node,
17 Event: dom.window.Event,
18 CustomEvent: dom.window.CustomEvent,
19 localStorage: dom.window.localStorage,
20 sessionStorage: dom.window.sessionStorage,
21 IS_REACT_ACT_ENVIRONMENT: true,
22 });
23 Object.defineProperty(globalThis, "navigator", { configurable: true, value: dom.window.navigator });
24 globalThis.requestAnimationFrame = dom.window.requestAnimationFrame.bind(dom.window);
25 globalThis.cancelAnimationFrame = dom.window.cancelAnimationFrame.bind(dom.window);
26 window.matchMedia = () => ({ matches: true, addEventListener() {}, removeEventListener() {} }) as unknown as MediaQueryList;
27 window.scrollTo = () => {};
28
29 let settings = baseSettings("standard");
30 let applyCalls = 0;
31 const desktopStub = installDesktopHostStub({
32 Settings: async () => settings,
33 Version: async () => "v1.2.3",
34 CheckUpdate: async () => ({ available: false, current: "v1.2.3", latest: "v1.2.3", channel: "stable" }),
35 ApplyUpdateRequest: async () => { applyCalls += 1; },
36 FetchAllProviderModels: async () => ({}),
37 });
38
39 async function renderAbout(root: ReturnType<typeof createRoot>) {
40 await act(async () => {
41 root.render(
42 <LocaleProvider>
43 <UpdaterProvider>
44 <SettingsPanel initialTab="updates" desktopPlatform="windows" onClose={() => {}} onChanged={() => {}} />
45 </UpdaterProvider>
46 </LocaleProvider>,
47 );
48 await flushPromises();
49 });
50 await act(async () => { await flushPromises(); });
51 }
52
53 try {
54 const stableRoot = createRoot(document.getElementById("root")!);
55 await renderAbout(stableRoot);
56 assert.ok(document.querySelector('.settings-page--updates[aria-label="About"]'), "legacy updates route opens the About page");
57 assert.ok(document.body.textContent?.includes("Current version: v1.2.3"));
58 assert.ok(document.querySelector('[aria-label="Check for updates"]'), "stable build shows manual update check");
59 assert.ok(document.body.textContent?.includes("Download from official site"), "stable build shows official download entry");
60 assert.ok(document.body.textContent?.includes("Update preferences"), "stable build shows update preferences");
61 assert.equal(applyCalls, 0, "available update actions never run before a user click");
62 await act(async () => stableRoot.unmount());
63
64 settings = { ...baseSettings("standard"), updaterEnabled: false };
65 const testRoot = createRoot(document.getElementById("root")!);
66 await renderAbout(testRoot);
67 assert.ok(document.querySelector('.settings-page--updates[aria-label="About"]'), "test build keeps the legacy route functional");
68 assert.equal(document.querySelector('[aria-label="Check for updates"]'), null, "test build hides manual update check");
69 assert.equal(document.body.textContent?.includes("Download from official site"), false, "test build hides production download entry");
70 assert.equal(document.body.textContent?.includes("Update preferences"), false, "test build hides updater preferences");
71 assert.ok(document.body.textContent?.includes("Build identity"), "test build shows build identity");
72 assert.ok(document.body.textContent?.includes("Privacy & configuration"), "test build keeps privacy and configuration");
73 assert.ok(document.body.textContent?.includes("Release notes"), "test build keeps changelog access");
74 assert.ok(document.body.textContent?.includes("Help & feedback"), "test build keeps feedback access");
75 await act(async () => testRoot.unmount());
76
77 console.log("PASS About route and stable/test updater capability controls");
78 } finally {
79 desktopStub.uninstall();
80 dom.window.close();
81 }
82
82 lines Plain Text