mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-10-25 17:22:27 +08:00
fix(settings): move the data-dir baseline after a successful save
The settings page no longer unmounts after saving, but the saved app-config-dir baseline was only captured on mount. After saving a new data directory and choosing "restart later" the save button stayed, resetting to the old value could not be saved, and every later save reported "restart required" again. Keep the baseline in state and commit it to the just-saved value once the override is persisted.
This commit is contained in:
1 parent
485a3b69de
commit
92e6f3b975
4 files changed
+44
-2
No files matched your search
@@ -170,6 +170,27 @@ describe("useDirectorySettings", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("moves the saved baseline when a new app config dir is committed", async () => {
|
||||
getAppConfigDirOverrideMock.mockResolvedValue("/override/app");
|
||||
const { result } = renderHook(() =>
|
||||
useDirectorySettings({
|
||||
settings: createSettings(),
|
||||
onUpdateSettings: vi.fn(),
|
||||
}),
|
||||
);
|
||||
await waitFor(() =>
|
||||
expect(result.current.initialAppConfigDir).toBe("/override/app"),
|
||||
);
|
||||
|
||||
act(() => result.current.commitAppConfigDir("/saved/app"));
|
||||
expect(result.current.initialAppConfigDir).toBe("/saved/app");
|
||||
|
||||
// 重置回的也是新基准
|
||||
act(() => result.current.updateAppConfigDir("/typed/app"));
|
||||
act(() => result.current.resetAllDirectories());
|
||||
expect(result.current.appConfigDir).toBe("/saved/app");
|
||||
});
|
||||
|
||||
it("updates app config directory via browseAppConfigDir", async () => {
|
||||
selectConfigDirectoryMock.mockResolvedValue(" /new/app ");
|
||||
|
||||
|
||||
@@ -123,6 +123,7 @@ const createDirectorySettingsMock = (
|
||||
},
|
||||
isLoading: false,
|
||||
initialAppConfigDir: undefined,
|
||||
commitAppConfigDir: vi.fn(),
|
||||
updateDirectory: vi.fn(),
|
||||
updateAppConfigDir: vi.fn(),
|
||||
browseDirectory: vi.fn(),
|
||||
@@ -297,6 +298,10 @@ describe("useSettings hook", () => {
|
||||
});
|
||||
|
||||
expect(saveResult).toEqual({ requiresRestart: true });
|
||||
// 存完把基准值换成刚存的,保存按钮和下一次「需要重启」只跟新改动走
|
||||
expect(directorySettingsMock.commitAppConfigDir).toHaveBeenCalledWith(
|
||||
"/override/app",
|
||||
);
|
||||
expect(mutateAsyncMock).toHaveBeenCalledTimes(1);
|
||||
const payload = mutateAsyncMock.mock.calls[0][0] as Settings;
|
||||
expect(payload.claudeConfigDir).toBe("/custom/claude");
|
||||
|
||||
Reference in new issue
Block a user