mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-12 22:14:05 +00:00
Treat a refused tool update as a failed save
This commit is contained in:
1 parent
9cd8c6c45c
commit
526b7a9fb3
2 files changed
+26
-6
No files matched your search
@@ -185,6 +185,28 @@ describe('ToolConfig', () => {
|
||||
expect(alert?.className).toContain('text-destructive');
|
||||
});
|
||||
|
||||
it('shows a save the server refused as failed', async () => {
|
||||
updateTool.mockResolvedValue({ ok: false, status: 400 });
|
||||
await render({ ...userTool, customName: '' });
|
||||
const name = container.querySelector<HTMLInputElement>(
|
||||
'input[placeholder="settings.tools.customNamePlaceholder"]',
|
||||
);
|
||||
await act(async () => {
|
||||
const setter = Object.getOwnPropertyDescriptor(
|
||||
HTMLInputElement.prototype,
|
||||
'value',
|
||||
)?.set;
|
||||
setter?.call(name, 'Renamed');
|
||||
name?.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
});
|
||||
await act(async () => {
|
||||
buttonByText('settings.tools.save')?.click();
|
||||
});
|
||||
expect(
|
||||
container.querySelector<HTMLElement>('[role="alert"]')?.textContent,
|
||||
).toBe('settings.tools.saveFailed');
|
||||
});
|
||||
|
||||
it('renders the API tool header actions as outline-primary pills', async () => {
|
||||
await render(apiTool);
|
||||
for (const label of [
|
||||
|
||||
@@ -257,12 +257,10 @@ export default function ToolConfig({
|
||||
actions: 'actions' in tool ? tool.actions : [],
|
||||
status: tool.status,
|
||||
};
|
||||
if (tool.id) {
|
||||
await userService.updateTool({ id: tool.id, ...payload }, token);
|
||||
return;
|
||||
}
|
||||
const response = await userService.createTool(payload, token);
|
||||
if (!response.ok) throw new Error('create failed');
|
||||
const response = tool.id
|
||||
? await userService.updateTool({ id: tool.id, ...payload }, token)
|
||||
: await userService.createTool(payload, token);
|
||||
if (!response.ok) throw new Error('save failed');
|
||||
};
|
||||
|
||||
const handleSaveChanges = async () => {
|
||||
|
||||
Reference in new issue
Block a user