/* eslint-env jest */ import { act } from 'react'; import { createRoot, type Root } from 'react-dom/client'; import { ConnectionNotice } from '../connection-notice'; import { reportConnection } from '../../../lib/connection'; ( globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean } ).IS_REACT_ACT_ENVIRONMENT = true; let root: Root; let host: HTMLDivElement; beforeEach(() => { host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host); }); afterEach(() => { act(() => root.unmount()); host.remove(); }); it('says a service is down and goes once it answers again', async () => { await act(async () => { root.render(); }); expect(host.textContent).toBe(''); await act(async () => { reportConnection({ host: 'agent.recomaze.ai', up: false }); }); expect(host.textContent).toContain( 'Recomaze is not answering right now (agent.recomaze.ai)' ); await act(async () => { reportConnection({ host: 'agent.recomaze.ai', up: true }); }); expect(host.textContent).toBe(''); });