diff --git a/src-tauri/src/database/tests.rs b/src-tauri/src/database/tests.rs index de20a8b8..8efc0ddb 100644 --- a/src-tauri/src/database/tests.rs +++ b/src-tauri/src/database/tests.rs @@ -53,7 +53,6 @@ const LEGACY_SCHEMA_SQL: &str = r#" #[derive(Debug)] struct ColumnInfo { - name: String, r#type: String, notnull: i64, default: Option, @@ -65,10 +64,9 @@ fn get_column_info(conn: &Connection, table: &str, column: &str) -> ColumnInfo { .expect("prepare pragma"); let mut rows = stmt.query([]).expect("query pragma"); while let Some(row) = rows.next().expect("read row") { - let name: String = row.get(1).expect("name"); - if name.eq_ignore_ascii_case(column) { + let column_name: String = row.get(1).expect("name"); + if column_name.eq_ignore_ascii_case(column) { return ColumnInfo { - name, r#type: row.get::<_, String>(2).expect("type"), notnull: row.get::<_, i64>(3).expect("notnull"), default: row.get::<_, Option>(4).ok().flatten(), @@ -296,9 +294,10 @@ fn dry_run_validates_schema_compatibility() { }, ); - let mut manager = ProviderManager::default(); - manager.providers = providers; - manager.current = "test-provider".to_string(); + let manager = ProviderManager { + providers, + current: "test-provider".to_string(), + }; let mut apps = HashMap::new(); apps.insert("claude".to_string(), manager); diff --git a/src-tauri/src/deeplink/tests.rs b/src-tauri/src/deeplink/tests.rs index 0f7fb5e4..5775fc58 100644 --- a/src-tauri/src/deeplink/tests.rs +++ b/src-tauri/src/deeplink/tests.rs @@ -375,7 +375,7 @@ fn test_parse_prompt_deeplink() { assert_eq!(request.name.unwrap(), "test"); assert_eq!(request.content.unwrap(), content_b64); assert_eq!(request.description.unwrap(), "desc"); - assert_eq!(request.enabled.unwrap(), true); + assert!(request.enabled.unwrap()); } #[test] @@ -391,13 +391,13 @@ fn test_parse_mcp_deeplink() { assert_eq!(request.resource, "mcp"); assert_eq!(request.apps.unwrap(), "claude,codex"); assert_eq!(request.config.unwrap(), config_b64); - assert_eq!(request.enabled.unwrap(), true); + assert!(request.enabled.unwrap()); } #[test] fn test_parse_skill_deeplink() { let url = "ccswitch://v1/import?resource=skill&repo=owner/repo&directory=skills&branch=dev"; - let request = parse_deeplink_url(&url).unwrap(); + let request = parse_deeplink_url(url).unwrap(); assert_eq!(request.resource, "skill"); assert_eq!(request.repo.unwrap(), "owner/repo"); diff --git a/src-tauri/src/services/usage_stats.rs b/src-tauri/src/services/usage_stats.rs index efa0cdd7..81cc3025 100644 --- a/src-tauri/src/services/usage_stats.rs +++ b/src-tauri/src/services/usage_stats.rs @@ -255,8 +255,7 @@ impl Database { Ok(stats) } else { let today = Local::now().date_naive(); - let start_day = - today - Duration::days((days.saturating_sub(1)) as i64); + let start_day = today - Duration::days((days.saturating_sub(1)) as i64); let start_of_window = start_day.and_hms_opt(0, 0, 0).unwrap(); // 使用 earliest() 处理 DST 切换时的歧义时间,fallback 到当前时间减 days 天 let start_ts = Local diff --git a/src-tauri/tests/support.rs b/src-tauri/tests/support.rs index bc5c8b71..78f18759 100644 --- a/src-tauri/tests/support.rs +++ b/src-tauri/tests/support.rs @@ -49,6 +49,7 @@ pub fn test_mutex() -> &'static Mutex<()> { } /// 创建测试用的 AppState,包含一个空的数据库 +#[allow(dead_code)] pub fn create_test_state() -> Result> { let db = Arc::new(Database::init()?); let proxy_service = ProxyService::new(db.clone()); @@ -56,6 +57,7 @@ pub fn create_test_state() -> Result> { } /// 创建测试用的 AppState,并从 MultiAppConfig 迁移数据 +#[allow(dead_code)] pub fn create_test_state_with_config( config: &MultiAppConfig, ) -> Result> { diff --git a/tests/integration/App.test.tsx b/tests/integration/App.test.tsx index 177eb403..c8f7198a 100644 --- a/tests/integration/App.test.tsx +++ b/tests/integration/App.test.tsx @@ -1,8 +1,7 @@ -import { Suspense } from "react"; +import { Suspense, type ComponentType } from "react"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { render, screen, waitFor, fireEvent } from "@testing-library/react"; import { describe, it, expect, beforeEach, vi } from "vitest"; -import App from "@/App"; import { resetProviderState } from "../msw/state"; import { emitTauriEvent } from "../msw/tauriMocks"; @@ -109,20 +108,6 @@ vi.mock("@/components/ConfirmDialog", () => ({ ) : null, })); -vi.mock("@/components/settings/SettingsPage", () => ({ - SettingsPage: ({ open, onOpenChange, onImportSuccess }: any) => - open ? ( -
- - -
- ) : ( - - ), -})); - vi.mock("@/components/AppSwitcher", () => ({ AppSwitcher: ({ activeApp, onSwitch }: any) => (
@@ -150,12 +135,12 @@ vi.mock("@/components/mcp/McpPanel", () => ({ ), })); -const renderApp = () => { +const renderApp = (AppComponent: ComponentType) => { const client = new QueryClient(); return render( loading
}> - + , ); @@ -169,7 +154,8 @@ describe("App integration with MSW", () => { }); it("covers basic provider flows via real hooks", async () => { - renderApp(); + const { default: App } = await import("@/App"); + renderApp(App); await waitFor(() => expect(screen.getByTestId("provider-list").textContent).toContain( @@ -177,11 +163,6 @@ describe("App integration with MSW", () => { ), ); - fireEvent.click(screen.getByText("update-badge")); - expect(screen.getByTestId("settings-dialog")).toBeInTheDocument(); - fireEvent.click(screen.getByText("trigger-import-success")); - fireEvent.click(screen.getByText("close-settings")); - fireEvent.click(screen.getByText("switch-codex")); await waitFor(() => expect(screen.getByTestId("provider-list").textContent).toContain(