Skip to content

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

test(core-notification-card): replace Meet-specific tests with generic display contract

Steven Enamakel7aa5c5a8c84e
diff --git a/app/src/components/notifications/CoreNotificationCard.test.tsx b/app/src/components/notifications/CoreNotificationCard.test.tsx
index 8bbb448b5c..13ccbf633a 100644
--- a/app/src/components/notifications/CoreNotificationCard.test.tsx
+++ b/app/src/components/notifications/CoreNotificationCard.test.tsx
@@ -1,36 +1,33 @@
/**
- * Action-button contract for core notification cards (issue #3507).
- * Asserts that the calendar auto-join prompt renders its buttons, dispatches
- * the `openhuman.agent_meetings_notification_action` RPC with the right
- * params on click, and surfaces an error when the RPC rejects.
+ * Display-only contract for the generic core notification card.
+ *
+ * The card used to render the meeting auto-join prompt's buttons and dispatch
+ * `openhuman.agent_meetings_notification_action`. Both went with the Meet
+ * domain, so the card is now a catch-all that must still *show* an
+ * action-carrying notification (`NotificationCenter` routes core items only
+ * through this branch) while rendering no buttons and calling no RPC.
*/
-import { fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
import { Provider } from 'react-redux';
-import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { describe, expect, it, vi } from 'vitest';
import { store } from '../../store';
import { type NotificationItem } from '../../store/notificationSlice';
import CoreNotificationCard from './CoreNotificationCard';
-const callCoreRpc = vi.hoisted(() => vi.fn());
-vi.mock('../../services/coreRpcClient', () => ({ callCoreRpc }));
+vi.mock('../../lib/i18n/I18nContext', () => ({ useT: () => ({ t: (k: string) => k }) }));
function makeItem(overrides: Partial<NotificationItem> = {}): NotificationItem {
return {
- id: 'meet-auto-join:m1',
- category: 'meetings',
- title: 'Meeting starting: Standup',
- body: 'Add Tiny to this meeting?',
+ id: 'core:1',
+ category: 'system',
+ title: 'Something happened',
+ body: 'Details about the thing.',
timestamp: Date.now(),
read: false,
- actions: [
- { actionId: 'join_listen', label: 'Join (listen only)', payload: { meetingId: 'm1' } },
- { actionId: 'join_active', label: 'Join & reply', payload: { meetingId: 'm1' } },
- { actionId: 'skip', label: 'Not this one', payload: { meetingId: 'm1' } },
- { actionId: 'always_join', label: 'Always join', payload: { meetingId: 'm1' } },
- ],
+ actions: [{ actionId: 'do_thing', label: 'Do the thing', payload: {} }],
...overrides,
- };
+ } as NotificationItem;
}
function renderCard(item: NotificationItem) {
@@ -42,119 +39,20 @@ function renderCard(item: NotificationItem) {
}
describe('CoreNotificationCard', () => {
- beforeEach(() => {
- vi.clearAllMocks();
- store.dispatch({ type: 'notifications/clearAll' });
- });
-
- it('renders a localized button per action', () => {
- renderCard(makeItem());
- expect(screen.getByRole('button', { name: 'Join (listen only)' })).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'Join & reply' })).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'Not this one' })).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'Always join' })).toBeInTheDocument();
- });
-
- it('dispatches the notification-action RPC with action_id + payload on click', async () => {
- callCoreRpc.mockResolvedValue({ ok: true });
- renderCard(makeItem());
-
- fireEvent.click(screen.getByRole('button', { name: 'Join (listen only)' }));
-
- await waitFor(() => expect(callCoreRpc).toHaveBeenCalledTimes(1));
- expect(callCoreRpc).toHaveBeenCalledWith({
- method: 'openhuman.agent_meetings_notification_action',
- params: { action_id: 'join_listen', payload: { meetingId: 'm1' } },
- });
- });
-
- it('marks the notification read in the store after a successful action', async () => {
- callCoreRpc.mockResolvedValue({ ok: true });
- store.dispatch({ type: 'notifications/notificationReceived', payload: makeItem() });
- renderCard(makeItem());
-
- fireEvent.click(screen.getByRole('button', { name: 'Not this one' }));
-
- await waitFor(() => {
- const item = store.getState().notifications.items.find(i => i.id === 'meet-auto-join:m1');
- expect(item?.read).toBe(true);
- });
- });
-
- it('clears the action buttons after a successful action so it cannot be re-clicked', async () => {
- callCoreRpc.mockResolvedValue({ ok: true });
- store.dispatch({ type: 'notifications/notificationReceived', payload: makeItem() });
- renderCard(makeItem());
-
- fireEvent.click(screen.getByRole('button', { name: 'Not this one' }));
-
- await waitFor(() => {
- const item = store.getState().notifications.items.find(i => i.id === 'meet-auto-join:m1');
- expect(item?.actions ?? []).toHaveLength(0);
- });
- });
-
- it('keeps the action buttons when the RPC rejects', async () => {
- callCoreRpc.mockRejectedValue(new Error('boom'));
- store.dispatch({ type: 'notifications/notificationReceived', payload: makeItem() });
+ it('renders the title and body of an action-carrying notification', () => {
renderCard(makeItem());
-
- fireEvent.click(screen.getByRole('button', { name: 'Not this one' }));
-
- await waitFor(() =>
- expect(
- screen.getByText('Could not complete that action. Please try again.')
- ).toBeInTheDocument()
+ expect(screen.getByTestId('core-notification-card')).toBeInTheDocument();
+ expect(screen.getByText('Something happened')).toBeInTheDocument();
+ expect(screen.getByTestId('core-notification-body')).toHaveTextContent(
+ 'Details about the thing.'
);
- const item = store.getState().notifications.items.find(i => i.id === 'meet-auto-join:m1');
- expect(item?.actions).toHaveLength(4);
});
- it('surfaces an error message when the RPC rejects', async () => {
- callCoreRpc.mockRejectedValue(new Error('boom'));
+ it('renders no action buttons even when the notification carries actions', () => {
renderCard(makeItem());
-
- fireEvent.click(screen.getByRole('button', { name: 'Always join' }));
-
- await waitFor(() =>
- expect(
- screen.getByText('Could not complete that action. Please try again.')
- ).toBeInTheDocument()
- );
- });
-
- it('renders nothing actionable when there are no actions', () => {
- renderCard(makeItem({ actions: [] }));
- expect(screen.queryByRole('button')).toBeNull();
- });
-
- it('disables all buttons while an action RPC is in flight', async () => {
- let resolve!: (v: unknown) => void;
- callCoreRpc.mockImplementation(
- () =>
- new Promise(r => {
- resolve = r;
- })
- );
- renderCard(makeItem());
-
- fireEvent.click(screen.getByRole('button', { name: 'Join (listen only)' }));
-
- // All buttons should be disabled while the call is pending.
- const buttons = screen.getAllByRole('button');
- buttons.forEach(btn => expect(btn).toBeDisabled());
-
- resolve({ ok: true });
- await waitFor(() => buttons.forEach(btn => expect(btn).not.toBeDisabled()));
- });
-
- it('shows no unread dot when notification is already read', () => {
- renderCard(makeItem({ read: true }));
- expect(document.querySelector('[aria-hidden="true"]')).toBeNull();
- });
-
- it('shows unread dot when notification is unread', () => {
- renderCard(makeItem({ read: false }));
- expect(document.querySelector('[aria-hidden="true"]')).toBeInTheDocument();
+ // Regression guard: re-adding buttons here would dispatch an RPC that the
+ // core no longer serves, so the click would fail with "unknown method".
+ expect(screen.queryByRole('button')).not.toBeInTheDocument();
+ expect(screen.queryByText('Do the thing')).not.toBeInTheDocument();
});
});