mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-03-26 07:36:46 +08:00
fix: resolve test failures and clippy warnings
- tests/App.test.tsx: remove outdated SettingsPage mock, use dynamic import - database/tests.rs: remove unused field, use struct init syntax - deeplink/tests.rs: use idiomatic assert!() instead of assert_eq!(true) - support.rs: add #[allow(dead_code)] for test utilities - usage_stats.rs: code formatting
This commit is contained in:
@@ -53,7 +53,6 @@ const LEGACY_SCHEMA_SQL: &str = r#"
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ColumnInfo {
|
||||
name: String,
|
||||
r#type: String,
|
||||
notnull: i64,
|
||||
default: Option<String>,
|
||||
@@ -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<String>>(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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -49,6 +49,7 @@ pub fn test_mutex() -> &'static Mutex<()> {
|
||||
}
|
||||
|
||||
/// 创建测试用的 AppState,包含一个空的数据库
|
||||
#[allow(dead_code)]
|
||||
pub fn create_test_state() -> Result<AppState, Box<dyn std::error::Error>> {
|
||||
let db = Arc::new(Database::init()?);
|
||||
let proxy_service = ProxyService::new(db.clone());
|
||||
@@ -56,6 +57,7 @@ pub fn create_test_state() -> Result<AppState, Box<dyn std::error::Error>> {
|
||||
}
|
||||
|
||||
/// 创建测试用的 AppState,并从 MultiAppConfig 迁移数据
|
||||
#[allow(dead_code)]
|
||||
pub fn create_test_state_with_config(
|
||||
config: &MultiAppConfig,
|
||||
) -> Result<AppState, Box<dyn std::error::Error>> {
|
||||
|
||||
@@ -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 ? (
|
||||
<div data-testid="settings-dialog">
|
||||
<button onClick={() => onImportSuccess?.()}>
|
||||
trigger-import-success
|
||||
</button>
|
||||
<button onClick={() => onOpenChange(false)}>close-settings</button>
|
||||
</div>
|
||||
) : (
|
||||
<button onClick={() => onOpenChange(true)}>open-settings</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("@/components/AppSwitcher", () => ({
|
||||
AppSwitcher: ({ activeApp, onSwitch }: any) => (
|
||||
<div data-testid="app-switcher">
|
||||
@@ -150,12 +135,12 @@ vi.mock("@/components/mcp/McpPanel", () => ({
|
||||
),
|
||||
}));
|
||||
|
||||
const renderApp = () => {
|
||||
const renderApp = (AppComponent: ComponentType) => {
|
||||
const client = new QueryClient();
|
||||
return render(
|
||||
<QueryClientProvider client={client}>
|
||||
<Suspense fallback={<div data-testid="loading">loading</div>}>
|
||||
<App />
|
||||
<AppComponent />
|
||||
</Suspense>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user