mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-01-24 14:33:08 +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()
|
||||
);
|
||||
|
||||
std::fs::write(&script_file, &script_content)
|
||||
.map_err(|e| format!("写入启动脚本失败: {e}"))?;
|
||||
std::fs::write(&script_file, &script_content).map_err(|e| format!("写入启动脚本失败: {e}"))?;
|
||||
|
||||
// Make script executable
|
||||
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()
|
||||
);
|
||||
|
||||
std::fs::write(&script_file, &script_content)
|
||||
.map_err(|e| format!("写入启动脚本失败: {e}"))?;
|
||||
std::fs::write(&script_file, &script_content).map_err(|e| format!("写入启动脚本失败: {e}"))?;
|
||||
|
||||
std::fs::set_permissions(&script_file, std::fs::Permissions::from_mode(0o755))
|
||||
.map_err(|e| format!("设置脚本权限失败: {e}"))?;
|
||||
|
||||
@@ -316,30 +316,48 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_log_config_to_level_filter() {
|
||||
let mut config = LogConfig::default();
|
||||
|
||||
config.level = "error".to_string();
|
||||
let config = LogConfig {
|
||||
level: "error".to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
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);
|
||||
|
||||
config.level = "info".to_string();
|
||||
let config = LogConfig {
|
||||
level: "info".to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
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);
|
||||
|
||||
config.level = "trace".to_string();
|
||||
let config = LogConfig {
|
||||
level: "trace".to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(config.to_level_filter(), log::LevelFilter::Trace);
|
||||
|
||||
// 无效级别回退到 info
|
||||
config.level = "invalid".to_string();
|
||||
let config = LogConfig {
|
||||
level: "invalid".to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(config.to_level_filter(), log::LevelFilter::Info);
|
||||
|
||||
// 禁用时返回 Off
|
||||
config.enabled = false;
|
||||
config.level = "debug".to_string();
|
||||
let config = LogConfig {
|
||||
enabled: false,
|
||||
level: "debug".to_string(),
|
||||
};
|
||||
assert_eq!(config.to_level_filter(), log::LevelFilter::Off);
|
||||
}
|
||||
|
||||
|
||||
@@ -893,7 +893,10 @@ function App() {
|
||||
activeApp={activeApp}
|
||||
onSwitch={setActiveApp}
|
||||
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">
|
||||
|
||||
@@ -11,7 +11,12 @@ interface AppSwitcherProps {
|
||||
|
||||
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) => {
|
||||
if (app === activeApp) return;
|
||||
onSwitch(app);
|
||||
|
||||
@@ -31,15 +31,15 @@ export function useModelState({
|
||||
if (lastConfigRef.current === settingsConfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (isUserEditingRef.current) {
|
||||
isUserEditingRef.current = false;
|
||||
lastConfigRef.current = settingsConfig;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
lastConfigRef.current = settingsConfig;
|
||||
|
||||
|
||||
try {
|
||||
const cfg = settingsConfig ? JSON.parse(settingsConfig) : {};
|
||||
const env = cfg?.env || {};
|
||||
|
||||
@@ -22,7 +22,10 @@ const APP_CONFIG: Array<{
|
||||
{ id: "opencode", icon: "opencode", nameKey: "apps.opencode" },
|
||||
];
|
||||
|
||||
export function AppVisibilitySettings({ settings, onChange }: AppVisibilitySettingsProps) {
|
||||
export function AppVisibilitySettings({
|
||||
settings,
|
||||
onChange,
|
||||
}: AppVisibilitySettingsProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const visibleApps: VisibleApps = settings.visibleApps ?? {
|
||||
@@ -51,7 +54,9 @@ export function AppVisibilitySettings({ settings, onChange }: AppVisibilitySetti
|
||||
return (
|
||||
<section className="space-y-2">
|
||||
<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">
|
||||
{t("settings.appVisibility.description")}
|
||||
</p>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import type { ReactElement } from "react";
|
||||
import type { Provider } from "@/types";
|
||||
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(() => {
|
||||
useDragSortMock.mockReset();
|
||||
useSortableMock.mockReset();
|
||||
@@ -131,7 +143,7 @@ beforeEach(() => {
|
||||
|
||||
describe("ProviderList Component", () => {
|
||||
it("should render skeleton placeholders when loading", () => {
|
||||
const { container } = render(
|
||||
const { container } = renderWithQueryClient(
|
||||
<ProviderList
|
||||
providers={{}}
|
||||
currentProviderId=""
|
||||
@@ -159,7 +171,7 @@ describe("ProviderList Component", () => {
|
||||
handleDragEnd: vi.fn(),
|
||||
});
|
||||
|
||||
render(
|
||||
renderWithQueryClient(
|
||||
<ProviderList
|
||||
providers={{}}
|
||||
currentProviderId=""
|
||||
@@ -198,7 +210,7 @@ describe("ProviderList Component", () => {
|
||||
handleDragEnd: vi.fn(),
|
||||
});
|
||||
|
||||
render(
|
||||
renderWithQueryClient(
|
||||
<ProviderList
|
||||
providers={{ a: providerA, b: providerB }}
|
||||
currentProviderId="b"
|
||||
@@ -262,7 +274,7 @@ describe("ProviderList Component", () => {
|
||||
handleDragEnd: vi.fn(),
|
||||
});
|
||||
|
||||
render(
|
||||
renderWithQueryClient(
|
||||
<ProviderList
|
||||
providers={{ alpha: providerAlpha, beta: providerBeta }}
|
||||
currentProviderId=""
|
||||
|
||||
Reference in New Issue
Block a user