mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-02 18:41:35 +08:00
chore: fix code formatting and test setup
- Format Rust code with rustfmt (misc.rs, types.rs) - Format TypeScript/React code with Prettier (4 files) - Fix ProviderList test by wrapping with QueryClientProvider
This commit is contained in:
@@ -605,8 +605,7 @@ exec bash --norc --noprofile
|
|||||||
script_file = script_file.display()
|
script_file = script_file.display()
|
||||||
);
|
);
|
||||||
|
|
||||||
std::fs::write(&script_file, &script_content)
|
std::fs::write(&script_file, &script_content).map_err(|e| format!("写入启动脚本失败: {e}"))?;
|
||||||
.map_err(|e| format!("写入启动脚本失败: {e}"))?;
|
|
||||||
|
|
||||||
// Make script executable
|
// Make script executable
|
||||||
std::fs::set_permissions(&script_file, std::fs::Permissions::from_mode(0o755))
|
std::fs::set_permissions(&script_file, std::fs::Permissions::from_mode(0o755))
|
||||||
@@ -675,8 +674,7 @@ exec bash --norc --noprofile
|
|||||||
script_file = script_file.display()
|
script_file = script_file.display()
|
||||||
);
|
);
|
||||||
|
|
||||||
std::fs::write(&script_file, &script_content)
|
std::fs::write(&script_file, &script_content).map_err(|e| format!("写入启动脚本失败: {e}"))?;
|
||||||
.map_err(|e| format!("写入启动脚本失败: {e}"))?;
|
|
||||||
|
|
||||||
std::fs::set_permissions(&script_file, std::fs::Permissions::from_mode(0o755))
|
std::fs::set_permissions(&script_file, std::fs::Permissions::from_mode(0o755))
|
||||||
.map_err(|e| format!("设置脚本权限失败: {e}"))?;
|
.map_err(|e| format!("设置脚本权限失败: {e}"))?;
|
||||||
|
|||||||
@@ -316,30 +316,48 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_log_config_to_level_filter() {
|
fn test_log_config_to_level_filter() {
|
||||||
let mut config = LogConfig::default();
|
let config = LogConfig {
|
||||||
|
level: "error".to_string(),
|
||||||
config.level = "error".to_string();
|
..Default::default()
|
||||||
|
};
|
||||||
assert_eq!(config.to_level_filter(), log::LevelFilter::Error);
|
assert_eq!(config.to_level_filter(), log::LevelFilter::Error);
|
||||||
|
|
||||||
config.level = "warn".to_string();
|
let config = LogConfig {
|
||||||
|
level: "warn".to_string(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
assert_eq!(config.to_level_filter(), log::LevelFilter::Warn);
|
assert_eq!(config.to_level_filter(), log::LevelFilter::Warn);
|
||||||
|
|
||||||
config.level = "info".to_string();
|
let config = LogConfig {
|
||||||
|
level: "info".to_string(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
assert_eq!(config.to_level_filter(), log::LevelFilter::Info);
|
assert_eq!(config.to_level_filter(), log::LevelFilter::Info);
|
||||||
|
|
||||||
config.level = "debug".to_string();
|
let config = LogConfig {
|
||||||
|
level: "debug".to_string(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
assert_eq!(config.to_level_filter(), log::LevelFilter::Debug);
|
assert_eq!(config.to_level_filter(), log::LevelFilter::Debug);
|
||||||
|
|
||||||
config.level = "trace".to_string();
|
let config = LogConfig {
|
||||||
|
level: "trace".to_string(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
assert_eq!(config.to_level_filter(), log::LevelFilter::Trace);
|
assert_eq!(config.to_level_filter(), log::LevelFilter::Trace);
|
||||||
|
|
||||||
// 无效级别回退到 info
|
// 无效级别回退到 info
|
||||||
config.level = "invalid".to_string();
|
let config = LogConfig {
|
||||||
|
level: "invalid".to_string(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
assert_eq!(config.to_level_filter(), log::LevelFilter::Info);
|
assert_eq!(config.to_level_filter(), log::LevelFilter::Info);
|
||||||
|
|
||||||
// 禁用时返回 Off
|
// 禁用时返回 Off
|
||||||
config.enabled = false;
|
let config = LogConfig {
|
||||||
config.level = "debug".to_string();
|
enabled: false,
|
||||||
|
level: "debug".to_string(),
|
||||||
|
};
|
||||||
assert_eq!(config.to_level_filter(), log::LevelFilter::Off);
|
assert_eq!(config.to_level_filter(), log::LevelFilter::Off);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -893,7 +893,10 @@ function App() {
|
|||||||
activeApp={activeApp}
|
activeApp={activeApp}
|
||||||
onSwitch={setActiveApp}
|
onSwitch={setActiveApp}
|
||||||
visibleApps={visibleApps}
|
visibleApps={visibleApps}
|
||||||
compact={isCurrentAppTakeoverActive && Object.values(visibleApps).filter(Boolean).length >= 3}
|
compact={
|
||||||
|
isCurrentAppTakeoverActive &&
|
||||||
|
Object.values(visibleApps).filter(Boolean).length >= 3
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="flex items-center gap-1 p-1 bg-muted rounded-xl">
|
<div className="flex items-center gap-1 p-1 bg-muted rounded-xl">
|
||||||
|
|||||||
@@ -11,7 +11,12 @@ interface AppSwitcherProps {
|
|||||||
|
|
||||||
const ALL_APPS: AppId[] = ["claude", "codex", "gemini", "opencode"];
|
const ALL_APPS: AppId[] = ["claude", "codex", "gemini", "opencode"];
|
||||||
|
|
||||||
export function AppSwitcher({ activeApp, onSwitch, visibleApps, compact }: AppSwitcherProps) {
|
export function AppSwitcher({
|
||||||
|
activeApp,
|
||||||
|
onSwitch,
|
||||||
|
visibleApps,
|
||||||
|
compact,
|
||||||
|
}: AppSwitcherProps) {
|
||||||
const handleSwitch = (app: AppId) => {
|
const handleSwitch = (app: AppId) => {
|
||||||
if (app === activeApp) return;
|
if (app === activeApp) return;
|
||||||
onSwitch(app);
|
onSwitch(app);
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ const APP_CONFIG: Array<{
|
|||||||
{ id: "opencode", icon: "opencode", nameKey: "apps.opencode" },
|
{ id: "opencode", icon: "opencode", nameKey: "apps.opencode" },
|
||||||
];
|
];
|
||||||
|
|
||||||
export function AppVisibilitySettings({ settings, onChange }: AppVisibilitySettingsProps) {
|
export function AppVisibilitySettings({
|
||||||
|
settings,
|
||||||
|
onChange,
|
||||||
|
}: AppVisibilitySettingsProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const visibleApps: VisibleApps = settings.visibleApps ?? {
|
const visibleApps: VisibleApps = settings.visibleApps ?? {
|
||||||
@@ -51,7 +54,9 @@ export function AppVisibilitySettings({ settings, onChange }: AppVisibilitySetti
|
|||||||
return (
|
return (
|
||||||
<section className="space-y-2">
|
<section className="space-y-2">
|
||||||
<header className="space-y-1">
|
<header className="space-y-1">
|
||||||
<h3 className="text-sm font-medium">{t("settings.appVisibility.title")}</h3>
|
<h3 className="text-sm font-medium">
|
||||||
|
{t("settings.appVisibility.title")}
|
||||||
|
</h3>
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-xs text-muted-foreground">
|
||||||
{t("settings.appVisibility.description")}
|
{t("settings.appVisibility.description")}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { render, screen, fireEvent } from "@testing-library/react";
|
import { render, screen, fireEvent } from "@testing-library/react";
|
||||||
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||||
|
import type { ReactElement } from "react";
|
||||||
import type { Provider } from "@/types";
|
import type { Provider } from "@/types";
|
||||||
import { ProviderList } from "@/components/providers/ProviderList";
|
import { ProviderList } from "@/components/providers/ProviderList";
|
||||||
|
|
||||||
@@ -108,6 +110,16 @@ function createProvider(overrides: Partial<Provider> = {}): Provider {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderWithQueryClient(ui: ReactElement) {
|
||||||
|
const queryClient = new QueryClient({
|
||||||
|
defaultOptions: { queries: { retry: false } },
|
||||||
|
});
|
||||||
|
|
||||||
|
return render(
|
||||||
|
<QueryClientProvider client={queryClient}>{ui}</QueryClientProvider>,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
useDragSortMock.mockReset();
|
useDragSortMock.mockReset();
|
||||||
useSortableMock.mockReset();
|
useSortableMock.mockReset();
|
||||||
@@ -131,7 +143,7 @@ beforeEach(() => {
|
|||||||
|
|
||||||
describe("ProviderList Component", () => {
|
describe("ProviderList Component", () => {
|
||||||
it("should render skeleton placeholders when loading", () => {
|
it("should render skeleton placeholders when loading", () => {
|
||||||
const { container } = render(
|
const { container } = renderWithQueryClient(
|
||||||
<ProviderList
|
<ProviderList
|
||||||
providers={{}}
|
providers={{}}
|
||||||
currentProviderId=""
|
currentProviderId=""
|
||||||
@@ -159,7 +171,7 @@ describe("ProviderList Component", () => {
|
|||||||
handleDragEnd: vi.fn(),
|
handleDragEnd: vi.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
render(
|
renderWithQueryClient(
|
||||||
<ProviderList
|
<ProviderList
|
||||||
providers={{}}
|
providers={{}}
|
||||||
currentProviderId=""
|
currentProviderId=""
|
||||||
@@ -198,7 +210,7 @@ describe("ProviderList Component", () => {
|
|||||||
handleDragEnd: vi.fn(),
|
handleDragEnd: vi.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
render(
|
renderWithQueryClient(
|
||||||
<ProviderList
|
<ProviderList
|
||||||
providers={{ a: providerA, b: providerB }}
|
providers={{ a: providerA, b: providerB }}
|
||||||
currentProviderId="b"
|
currentProviderId="b"
|
||||||
@@ -262,7 +274,7 @@ describe("ProviderList Component", () => {
|
|||||||
handleDragEnd: vi.fn(),
|
handleDragEnd: vi.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
render(
|
renderWithQueryClient(
|
||||||
<ProviderList
|
<ProviderList
|
||||||
providers={{ alpha: providerAlpha, beta: providerBeta }}
|
providers={{ alpha: providerAlpha, beta: providerBeta }}
|
||||||
currentProviderId=""
|
currentProviderId=""
|
||||||
|
|||||||
Reference in New Issue
Block a user