mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Add a docked desktop tool panel with an icon rail, driven by the shared panel URL param, and keep the mobile dialogs and drawers. Extract dialog bodies into reusable content components, rename the walkthrough dialog to a sheet, and make walkthrough generation asynchronous with client polling.
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { FetchError, fetchWrapper } from './fetchWrapper'
|
|
|
|
function respondWith(body: string, status: number) {
|
|
vi.stubGlobal('fetch', vi.fn(async () => new Response(body, { status })))
|
|
}
|
|
|
|
describe('fetchWrapper error bodies', () => {
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals()
|
|
})
|
|
|
|
it('uses the JSON error message', async () => {
|
|
respondWith(JSON.stringify({ error: 'Session not found', code: 'NOT_FOUND' }), 404)
|
|
|
|
await expect(fetchWrapper('/api/x')).rejects.toMatchObject({ message: 'Session not found', statusCode: 404, code: 'NOT_FOUND' })
|
|
})
|
|
|
|
it('keeps a plain-text error body', async () => {
|
|
respondWith('upstream unavailable', 502)
|
|
|
|
await expect(fetchWrapper('/api/x')).rejects.toMatchObject({ message: 'upstream unavailable' })
|
|
})
|
|
|
|
it('replaces an HTML error page with a status message', async () => {
|
|
respondWith('<!DOCTYPE html><html><body>A timeout occurred</body></html>', 524)
|
|
|
|
const error = await fetchWrapper('/api/x').catch((caught: unknown) => caught)
|
|
expect(error).toBeInstanceOf(FetchError)
|
|
expect((error as FetchError).message).toBe('Request failed with status 524')
|
|
})
|
|
})
|