Skip to content

Commit 58aedae

Browse files
author
root
committed
Expand settings test coverage
Made-with: Cursor
1 parent c113eab commit 58aedae

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

test/unit/pages/Setting/GeneralProxy.test.tsx

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,50 @@ describe('SettingGeneral Network Proxy', () => {
179179

180180
expect((window as any).electronAPI.restartApp).toHaveBeenCalled();
181181
});
182-
}
182+
it('removes proxy when input cleared', async () => {
183+
// Start with existing value
184+
render(<SettingGeneral />);
185+
186+
const input = await screen.findByPlaceholderText(
187+
'setting.proxy-placeholder'
188+
);
189+
190+
await userEvent.clear(input);
191+
192+
const button = screen.getByRole('button', { name: 'setting.save' });
193+
await userEvent.click(button);
194+
195+
await waitFor(() => {
196+
expect((window as any).electronAPI.envRemove).toHaveBeenCalledWith(
197+
'test@example.com',
198+
'HTTP_PROXY'
199+
);
200+
expect(toastSuccessMock).toHaveBeenCalledWith(
201+
'setting.proxy-saved-restart-required'
202+
);
203+
});
204+
});
205+
206+
it('shows error when electron env APIs are missing', async () => {
207+
(window as any).electronAPI = {
208+
getPlatform: () => 'linux',
209+
readGlobalEnv: vi.fn().mockResolvedValue({ value: '' }),
210+
// envWrite/envRemove intentionally omitted
211+
};
212+
213+
render(<SettingGeneral />);
214+
215+
const input = await screen.findByPlaceholderText(
216+
'setting.proxy-placeholder'
217+
);
218+
await userEvent.type(input, 'http://proxy:8080');
219+
220+
const button = screen.getByRole('button', { name: 'setting.save' });
221+
await userEvent.click(button);
222+
223+
await waitFor(() => {
224+
expect(toastErrorMock).toHaveBeenCalledWith('setting.proxy-save-failed');
225+
});
226+
});
227+
});
183228

test/unit/pages/Setting/Privacy.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,28 @@ describe('SettingPrivacy', () => {
106106
expect(toastErrorMock).toHaveBeenCalledWith('setting.save-failed');
107107
});
108108
});
109+
110+
it('disables switch while loading and enables after load', async () => {
111+
proxyFetchGetMock.mockResolvedValueOnce({ help_improve: false });
112+
113+
render(<SettingPrivacy />);
114+
115+
const switchEl = await screen.findByRole('switch');
116+
117+
// After initial load completes, loading should be false and switch enabled
118+
expect(switchEl).not.toBeDisabled();
119+
});
120+
121+
it('shows disabled status text when help improve is off', async () => {
122+
proxyFetchGetMock.mockResolvedValueOnce({ help_improve: false });
123+
124+
render(<SettingPrivacy />);
125+
126+
await screen.findByRole('switch');
127+
128+
expect(
129+
screen.getByText('setting.disabled', { exact: false })
130+
).toBeInTheDocument();
131+
});
109132
});
110133

0 commit comments

Comments
 (0)