import { JSDOM } from 'jsdom' import React from 'react' import {render, fireEvent, within, screen} from '@testing-library/react' import { ThemeSettingsPage } from "../pages_theme_settings.tsx" import { ThemeProvider } from "../hooks_sys.tsx" import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { assertEquals, assertExists, assertNotEquals, assertRejects, } from "https://deno.land/std@0.217.0/assert/mod.ts"; const queryClient = new QueryClient() const dom = new JSDOM(`
`, { runScripts: "dangerously", pretendToBeVisual: true, url: "http://localhost" }); // 模拟浏览器环境 globalThis.window = dom.window; globalThis.document = dom.window.document; // 定义浏览器环境所需的类 globalThis.Element = dom.window.Element; globalThis.HTMLElement = dom.window.HTMLElement; globalThis.ShadowRoot = dom.window.ShadowRoot; globalThis.SVGElement = dom.window.SVGElement; // 模拟 getComputedStyle globalThis.getComputedStyle = (elt) => { const style = new dom.window.CSSStyleDeclaration(); style.getPropertyValue = () => ''; return style; }; // 模拟matchMedia函数 globalThis.matchMedia = (query) => ({ matches: query.includes('max-width'), media: query, onchange: null, addListener: () => {}, removeListener: () => {}, addEventListener: () => {}, removeEventListener: () => {}, dispatchEvent: () => false, }); // 模拟动画相关API globalThis.AnimationEvent = globalThis.AnimationEvent || dom.window.Event; globalThis.TransitionEvent = globalThis.TransitionEvent || dom.window.Event; // 模拟requestAnimationFrame globalThis.requestAnimationFrame = globalThis.requestAnimationFrame || ((cb) => setTimeout(cb, 0)); globalThis.cancelAnimationFrame = globalThis.cancelAnimationFrame || clearTimeout; // 设置浏览器尺寸相关方法 window.resizeTo = (width, height) => { window.innerWidth = width || window.innerWidth; window.innerHeight = height || window.innerHeight; window.dispatchEvent(new Event('resize')); }; window.scrollTo = () => {}; const customScreen = within(document.body); // 使用异步测试处理真实API调用 Deno.test('主题设置页面测试', async (t) => { // 渲染组件 const {findByRole, debug} = render(