From b08e4c42682f1ab36723b3c20832533f669de2b0 Mon Sep 17 00:00:00 2001 From: archipelago Date: Tue, 16 Jun 2026 03:46:18 -0400 Subject: [PATCH] test(filebrowser): align listDirectory tests with B4 content-type guard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The B4 fix made listDirectory require a JSON content-type (to detect the SPA-fallback HTML / 502 cases) and changed the non-OK error string, but its tests still mocked headerless responses + the old message, so they failed — which also polluted the run and tripped AppIconGrid's teardown. Give the JSON mock a content-type, update the non-OK expectation, and add a test for the guard's friendly-error path. Full suite now 667/667 green. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../api/__tests__/filebrowser-client.test.ts | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/neode-ui/src/api/__tests__/filebrowser-client.test.ts b/neode-ui/src/api/__tests__/filebrowser-client.test.ts index c220fa51..f7d6a318 100644 --- a/neode-ui/src/api/__tests__/filebrowser-client.test.ts +++ b/neode-ui/src/api/__tests__/filebrowser-client.test.ts @@ -21,7 +21,9 @@ function jsonResponse(body: unknown, status = 200): Response { json: () => Promise.resolve(body), text: () => Promise.resolve(typeof body === 'string' ? body : JSON.stringify(body)), blob: () => Promise.resolve(new Blob([JSON.stringify(body)])), - headers: new Headers(), + // A real File Browser JSON response carries this; listDirectory now guards + // on it (B4) to detect the SPA-fallback HTML / 502 cases. + headers: new Headers({ 'content-type': 'application/json' }), redirected: false, type: 'basic' as ResponseType, url: '', @@ -119,7 +121,21 @@ describe('FileBrowserClient', () => { mockFetch.mockResolvedValueOnce(jsonResponse(null, 404)) - await expect(fileBrowserClient.listDirectory('/missing')).rejects.toThrow('Failed to list directory: 404') + await expect(fileBrowserClient.listDirectory('/missing')).rejects.toThrow('File Browser is not available (HTTP 404)') + }) + + it('throws a friendly error when File Browser is absent and nginx serves the SPA (B4)', async () => { + setAuthenticated() + + // 200 but text/html (SPA index.html fallback) — res.json() would throw the + // opaque "Unexpected token '<'"; the guard must surface a friendly message. + const htmlResponse = { + ...jsonResponse(''), + headers: new Headers({ 'content-type': 'text/html' }), + } as Response + mockFetch.mockResolvedValueOnce(htmlResponse) + + await expect(fileBrowserClient.listDirectory('/')).rejects.toThrow('File Browser is not available') }) })