Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(ui): exercise shared toast handoff and sidebar selection

Steven Enamakelba07ee0234ba
diff --git a/app/src/components/intelligence/Toast.test.tsx b/app/src/components/intelligence/Toast.test.tsx
index c6928df2bc..b2d3453e15 100644
--- a/app/src/components/intelligence/Toast.test.tsx
+++ b/app/src/components/intelligence/Toast.test.tsx
@@ -1,8 +1,10 @@
-import { render, screen } from '@testing-library/react';
+import { act, render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
-import { describe, expect, it, vi } from 'vitest';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { renderWithProviders } from '../../test/test-utils';
import type { ToastNotification } from '../../types/intelligence';
+import { toast, Toaster } from '../ui/Toast';
import { ToastContainer } from './Toast';
const notification: ToastNotification = {
@@ -13,38 +15,55 @@ const notification: ToastNotification = {
};
describe('<ToastContainer />', () => {
+ afterEach(() => act(() => toast.close()));
it('renders nothing when there are no notifications', () => {
const { container } = render(<ToastContainer notifications={[]} onRemove={vi.fn()} />);
expect(container).toBeEmptyDOMElement();
});
- it('renders the notification title, message, and a dismiss button', () => {
- render(<ToastContainer notifications={[notification]} onRemove={vi.fn()} />);
- expect(screen.getByText('Saved')).toBeInTheDocument();
+ it('renders the notification through the shared toaster', async () => {
+ const user = userEvent.setup();
+ renderWithProviders(
+ <>
+ <Toaster />
+ <ToastContainer notifications={[notification]} onRemove={vi.fn()} />
+ </>
+ );
+ expect(await screen.findByText('Saved')).toBeInTheDocument();
expect(screen.getByText('Your changes were saved.')).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'Dismiss notification' })).toBeInTheDocument();
+ await user.hover(await screen.findByTestId('toast'));
+ expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();
});
it('renders the action button and invokes its handler on click', async () => {
const user = userEvent.setup();
const handler = vi.fn();
- render(
- <ToastContainer
- notifications={[{ ...notification, action: { label: 'Undo', handler } }]}
- onRemove={vi.fn()}
- />
+ renderWithProviders(
+ <>
+ <Toaster />
+ <ToastContainer
+ notifications={[{ ...notification, action: { label: 'Undo', handler } }]}
+ onRemove={vi.fn()}
+ />
+ </>
);
- await user.click(screen.getByRole('button', { name: 'Undo' }));
+ await user.click(await screen.findByRole('button', { name: 'Undo' }));
expect(handler).toHaveBeenCalledTimes(1);
});
- it('calls onRemove after the dismiss button is clicked', async () => {
- vi.useFakeTimers();
+ it('removes legacy state after handoff and lets the shared toaster dismiss it', async () => {
+ const user = userEvent.setup();
const onRemove = vi.fn();
- render(<ToastContainer notifications={[notification]} onRemove={onRemove} />);
- screen.getByRole('button', { name: 'Dismiss notification' }).click();
- vi.advanceTimersByTime(250);
+ renderWithProviders(
+ <>
+ <Toaster />
+ <ToastContainer notifications={[notification]} onRemove={onRemove} />
+ </>
+ );
expect(onRemove).toHaveBeenCalledWith('n1');
- vi.useRealTimers();
+ await user.hover(await screen.findByTestId('toast'));
+ await user.click(await screen.findByRole('button', { name: 'Close' }));
+ await waitFor(() => expect(screen.queryByTestId('toast')).not.toBeInTheDocument());
+ expect(onRemove).toHaveBeenCalledTimes(1);
});
});
diff --git a/app/src/pages/FlowsPage.test.tsx b/app/src/pages/FlowsPage.test.tsx
index 7d1870d5a2..12628e527b 100644
--- a/app/src/pages/FlowsPage.test.tsx
+++ b/app/src/pages/FlowsPage.test.tsx
@@ -13,8 +13,9 @@
* template gallery inline.
*/
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
-import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { toast, Toaster } from '../components/ui/Toast';
import { FLOW_TEMPLATES } from '../lib/flows/templates';
import type { Flow } from '../services/api/flowsApi';
import { renderWithProviders } from '../test/test-utils';
@@ -86,6 +87,7 @@ function openRowMenu(rowId = 'flow-1') {
}
describe('FlowsPage', () => {
+ afterEach(() => toast.close());
beforeEach(() => {
vi.clearAllMocks();
// SuggestedWorkflows loads persisted suggestions on mount; default to none
@@ -161,7 +163,13 @@ describe('FlowsPage', () => {
status: 'running',
detached: true,
});
- renderWithProviders(<FlowsPage />, { initialEntries: ['/?view=main'] });
+ renderWithProviders(
+ <>
+ <Toaster />
+ <FlowsPage />
+ </>,
+ { initialEntries: ['/?view=main'] }
+ );
await waitFor(() => expect(screen.getByTestId('flow-run-flow-1')).toBeInTheDocument());
fireEvent.click(screen.getByTestId('flow-run-flow-1'));
diff --git a/app/src/pages/__tests__/Conversations.render.test.tsx b/app/src/pages/__tests__/Conversations.render.test.tsx
index 2ddcd85eba..d22ab0995c 100644
--- a/app/src/pages/__tests__/Conversations.render.test.tsx
+++ b/app/src/pages/__tests__/Conversations.render.test.tsx
@@ -769,7 +769,9 @@ describe('Conversations — smoke render (#1123 welcome-lock removal)', () => {
});
expect(store?.getState().thread.selectedThreadId).toBe('t-2');
- expect(screen.getByTestId('thread-row-t-2')).toHaveClass('bg-surface/70');
+ expect(
+ screen.getByTestId('thread-row-t-2').closest('[data-slot="aui_thread-list-item"]')
+ ).toHaveAttribute('data-active');
});
// Sidebar "New thread" button was removed in the composer flattening refactor.