Rabbit fixes

This commit is contained in:
Pavel committed 2026-09-26 23:02:30 +04:00
1 parent 8390c1f275
commit eb95304315
2 files changed
+62 -3

No files matched your search

@@ -179,4 +179,54 @@ describe('MobileTopBar', () => {
expect(menuItem('navigation.editAgent')).toBeDefined();
expect(menuItem('convTile.share')).toBeUndefined();
});
it('keeps the menu on a chat or owned agent with an empty name', () => {
render({
title: '',
conversationId: 'c1',
editAgentPath: '/agents/edit/a1',
onRename: () => {},
onDelete: () => {},
});
const title = container.querySelector('[data-testid="mobile-title"]')!;
expect(title.tagName).toBe('BUTTON');
expect(title.textContent).toContain('newChat');
openMenu(title);
expect(menuItem('navigation.editAgent')).toBeDefined();
expect(menuItem('convTile.rename')).toBeDefined();
});
it('drops a rename in progress when the conversation changes', () => {
const onRename = vi.fn();
const props = { title: 'Router drops', onRename, onDelete: () => {} };
render({ ...props, conversationId: 'c1' });
openMenu(container.querySelector('[data-testid="mobile-title"]')!);
act(() => menuItem('convTile.rename')!.click());
expect(container.querySelector('input')).not.toBeNull();
render({ ...props, title: 'Other chat', conversationId: 'c2' });
expect(container.querySelector('input')).toBeNull();
expect(button('convTile.save')).toBeNull();
expect(onRename).not.toHaveBeenCalled();
});
it('closes an open share when the conversation changes', () => {
const props = {
title: 'Router drops',
onRename: () => {},
onDelete: () => {},
};
render({ ...props, conversationId: 'c1' });
openMenu(container.querySelector('[data-testid="mobile-title"]')!);
act(() => menuItem('convTile.share')!.click());
expect(
document.querySelector('[data-testid="share-modal"]'),
).not.toBeNull();
render({ ...props, conversationId: 'c2' });
expect(document.querySelector('[data-testid="share-modal"]')).toBeNull();
});
});
+12 -3
View File
@@ -87,6 +87,15 @@ export default function MobileTopBar({
const [isShareOpen, setIsShareOpen] = useState(false);
const [deleteModalState, setDeleteModalState] =
useState<ActiveState>('INACTIVE');
// A rename, share or delete belongs to the chat it started on. The bar
// stays mounted across chats, so drop any that is open when the chat changes.
const [actionsFor, setActionsFor] = useState(conversationId);
if (actionsFor !== conversationId) {
setActionsFor(conversationId);
setIsEditing(false);
setIsShareOpen(false);
setDeleteModalState('INACTIVE');
}
const actions: TitleAction[] = [];
if (editAgentPath) {
@@ -176,8 +185,8 @@ export default function MobileTopBar({
</div>
);
}
if (!title) return null;
if (actions.length === 0) {
if (!title) return null;
return (
<span
data-testid="mobile-title"
@@ -203,8 +212,8 @@ export default function MobileTopBar({
className="min-w-0 shrink"
>
{agentMark}
<span className="truncate" title={title}>
{title}
<span className="truncate" title={title || undefined}>
{title || t('newChat')}
</span>
<ChevronDown className="text-muted-foreground" aria-hidden />
</Button>