|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * objectstack#37788 (ui ADR-0057 Amendment A4) — on an app's AI inquiry page |
| 5 | + * (`ai:chat`) the drawer is closed and the assistant's standing entry is not |
| 6 | + * drawn; on every other page both are as the user left them. |
| 7 | + * |
| 8 | + * The dock hook's own cases (`useConsoleChatDock.phoneCollapseOnNavigate-37556`) |
| 9 | + * tell the hook the route themselves; this file pins the one place the console |
| 10 | + * tells it: `ConsoleLayout` reading the address. |
| 11 | + * |
| 12 | + * ## Real subjects |
| 13 | + * |
| 14 | + * `ConsoleLayout` with its real `AppShell`, the real `useConsoleChatDock` |
| 15 | + * host, the real `useChatDockState` and the real `AssistantTopBarButton`, |
| 16 | + * drawn in the page as the page header's button group draws it from 768 px up. |
| 17 | + * The rail body is a stand-in: which chrome mounts is the subject here. |
| 18 | + */ |
| 19 | + |
| 20 | +import '@testing-library/jest-dom/vitest'; |
| 21 | +// The layout reaches `import('@objectstack/lint')` (the draft bar's publish |
| 22 | +// preflight); pay its first load at collection, never inside a clocked case. |
| 23 | +import '@objectstack/lint'; |
| 24 | +// AiChatPage reads a dropped spreadsheet through `import('@object-ui/plugin-grid')`; load it |
| 25 | +// here so collection pays that transform, not a clocked case (check-test-source-alias). |
| 26 | +import '@object-ui/plugin-grid'; |
| 27 | +import { describe, it, expect, vi, afterEach } from 'vitest'; |
| 28 | +import React from 'react'; |
| 29 | +import { render, screen, fireEvent, cleanup } from '@testing-library/react'; |
| 30 | +import { MemoryRouter, useNavigate } from 'react-router-dom'; |
| 31 | + |
| 32 | +vi.mock('@object-ui/i18n', async (importOriginal) => ({ |
| 33 | + ...(await importOriginal<Record<string, unknown>>()), |
| 34 | + useObjectTranslation: () => ({ |
| 35 | + t: (key: string, options?: Record<string, unknown>) => String(options?.defaultValue ?? key), |
| 36 | + language: 'en', |
| 37 | + }), |
| 38 | +})); |
| 39 | + |
| 40 | +vi.mock('../ChatDock', async (importOriginal) => ({ |
| 41 | + ...(await importOriginal<Record<string, unknown>>()), |
| 42 | + ChatDockPanel: () => <aside data-testid="chat-dock-panel" />, |
| 43 | + ChatDockMobileSheet: () => null, |
| 44 | +})); |
| 45 | + |
| 46 | +vi.mock('../../hooks/useAiSurface', () => ({ |
| 47 | + useAiSurfaceEnabled: () => ({ enabled: true, isLoading: false }), |
| 48 | +})); |
| 49 | + |
| 50 | +// Chrome this card does not touch. |
| 51 | +vi.mock('../UnifiedSidebar', () => ({ UnifiedSidebar: () => null })); |
| 52 | +vi.mock('../AppHeader', () => ({ AppHeader: () => <div data-testid="app-header-stub" /> })); |
| 53 | +vi.mock('../ConsoleNotificationBanners', () => ({ ConsoleNotificationBanners: () => null })); |
| 54 | +vi.mock('../../preview/DraftPreviewBar', () => ({ DraftPreviewBar: () => null })); |
| 55 | +vi.mock('../../preview/UnpublishedAppBar', () => ({ UnpublishedAppBar: () => null })); |
| 56 | + |
| 57 | +import { ConsoleLayout } from '../ConsoleLayout'; |
| 58 | +import { AssistantTopBarButton } from '../AssistantTopBarButton'; |
| 59 | +import { NavigationProvider } from '../../context/NavigationContext'; |
| 60 | + |
| 61 | +const APP = { name: 'crm', label: 'CRM', active: true, navigation: [] }; |
| 62 | +const LIST = '/apps/crm/opportunity'; |
| 63 | +const ASK_PAGE = '/apps/crm/component/ai/chat'; |
| 64 | + |
| 65 | +function Links() { |
| 66 | + const navigate = useNavigate(); |
| 67 | + return ( |
| 68 | + <> |
| 69 | + <button data-testid="to-ask-page" onClick={() => navigate(ASK_PAGE)} /> |
| 70 | + <button data-testid="to-list" onClick={() => navigate(LIST)} /> |
| 71 | + </> |
| 72 | + ); |
| 73 | +} |
| 74 | + |
| 75 | +function mountConsole(entry: string) { |
| 76 | + return render( |
| 77 | + <MemoryRouter initialEntries={[entry]}> |
| 78 | + <NavigationProvider> |
| 79 | + <ConsoleLayout activeAppName="crm" activeApp={APP} onAppChange={vi.fn()} objects={[]}> |
| 80 | + <AssistantTopBarButton /> |
| 81 | + <Links /> |
| 82 | + </ConsoleLayout> |
| 83 | + </NavigationProvider> |
| 84 | + </MemoryRouter>, |
| 85 | + ); |
| 86 | +} |
| 87 | + |
| 88 | +const robot = () => screen.queryByTestId('topbar-ai-assistant'); |
| 89 | +const rail = () => screen.queryByTestId('chat-dock-panel'); |
| 90 | + |
| 91 | +afterEach(() => { |
| 92 | + cleanup(); |
| 93 | + window.sessionStorage.clear(); |
| 94 | + window.localStorage.clear(); |
| 95 | +}); |
| 96 | + |
| 97 | +describe('ConsoleLayout tells the drawer it is on the AI inquiry page (objectstack#37788)', () => { |
| 98 | + it('on the ai:chat route the entry is not drawn; on another route it is back', () => { |
| 99 | + mountConsole(ASK_PAGE); |
| 100 | + expect(robot()).not.toBeInTheDocument(); |
| 101 | + |
| 102 | + fireEvent.click(screen.getByTestId('to-list')); |
| 103 | + expect(robot()).toBeInTheDocument(); |
| 104 | + }); |
| 105 | + |
| 106 | + it('a drawer open on another page is closed on the ai:chat route and comes back after it', () => { |
| 107 | + mountConsole(LIST); |
| 108 | + fireEvent.click(robot()!); |
| 109 | + expect(rail()).toBeInTheDocument(); |
| 110 | + |
| 111 | + fireEvent.click(screen.getByTestId('to-ask-page')); |
| 112 | + expect(rail()).not.toBeInTheDocument(); |
| 113 | + |
| 114 | + fireEvent.click(screen.getByTestId('to-list')); |
| 115 | + expect(rail()).toBeInTheDocument(); |
| 116 | + }); |
| 117 | +}); |
0 commit comments