Skip to content

Commit 348319d

Browse files
fix(MoreDrawer): show Assistant name on assistant routes
The drawer header was displaying the source repo name instead of "Assistant" when opened from /repos/:id/assistant or assistant session detail routes. Added route detection and conditional display name. Also fixed missing QueryClientProvider in tests.
1 parent 829d4af commit 348319d

2 files changed

Lines changed: 68 additions & 40 deletions

File tree

frontend/src/components/navigation/MoreDrawer.test.tsx

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { render, screen, fireEvent } from '@testing-library/react'
22
import { beforeEach, describe, it, expect, vi } from 'vitest'
3-
import { MemoryRouter, useNavigate } from 'react-router-dom'
3+
import { MemoryRouter, Route, Routes, useNavigate } from 'react-router-dom'
4+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
45
import { MoreDrawer } from './MoreDrawer'
56
import { useAuth } from '@/hooks/useAuth'
67
import { useServerHealth } from '@/hooks/useServerHealth'
78
import { useCommands } from '@/hooks/useCommands'
89
import { useUIState } from '@/stores/uiStateStore'
10+
import { getRepo } from '@/api/repos'
911

1012
vi.mock('@/hooks/useAuth')
1113
vi.mock('@/hooks/useServerHealth')
1214
vi.mock('@/hooks/useCommands')
15+
vi.mock('@/api/repos', () => ({
16+
getRepo: vi.fn(),
17+
}))
1318
vi.mock('@/hooks/useMemoryPluginStatus', () => ({
1419
useMemoryPluginStatus: () => ({ memoryPluginEnabled: false }),
1520
}))
@@ -72,6 +77,32 @@ const mockServerHealth = (health?: Partial<ReturnType<typeof useServerHealth>['d
7277
})
7378
}
7479

80+
const createQueryClient = () => new QueryClient({
81+
defaultOptions: {
82+
queries: {
83+
retry: false,
84+
},
85+
},
86+
})
87+
88+
const renderMoreDrawer = ({
89+
initialEntry = '/',
90+
routePath = '*',
91+
onClose = vi.fn(),
92+
}: {
93+
initialEntry?: string
94+
routePath?: string
95+
onClose?: () => void
96+
} = {}) => render(
97+
<QueryClientProvider client={createQueryClient()}>
98+
<MemoryRouter initialEntries={[initialEntry]}>
99+
<Routes>
100+
<Route path={routePath} element={<MoreDrawer isOpen onClose={onClose} />} />
101+
</Routes>
102+
</MemoryRouter>
103+
</QueryClientProvider>,
104+
)
105+
75106
describe('MoreDrawer', () => {
76107
beforeEach(() => {
77108
vi.clearAllMocks()
@@ -94,16 +125,22 @@ describe('MoreDrawer', () => {
94125
useUIState.getState().clearPendingPromptCommand()
95126
useUIState.getState().clearPendingPromptFile()
96127
useUIState.getState().setActivePromptFileBasePath(null)
128+
vi.mocked(getRepo).mockResolvedValue({
129+
id: 1,
130+
localPath: 'wrong-repo',
131+
fullPath: '/workspace/repos/wrong-repo',
132+
branch: 'main',
133+
defaultBranch: 'main',
134+
cloneStatus: 'ready',
135+
clonedAt: 0,
136+
})
97137
})
98138

99139
it('renders Settings and Logout menu items', () => {
100140
mockAuth()
101141
mockServerHealth()
102142
const handleClose = vi.fn()
103-
render(
104-
<MoreDrawer isOpen onClose={handleClose} />,
105-
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
106-
)
143+
renderMoreDrawer({ onClose: handleClose })
107144
expect(screen.getByText('Settings')).toBeInTheDocument()
108145
expect(screen.getByText('Logout')).toBeInTheDocument()
109146
})
@@ -112,10 +149,7 @@ describe('MoreDrawer', () => {
112149
mockAuth()
113150
mockServerHealth()
114151
const handleClose = vi.fn()
115-
render(
116-
<MoreDrawer isOpen onClose={handleClose} />,
117-
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
118-
)
152+
renderMoreDrawer({ onClose: handleClose })
119153
expect(screen.queryByText('Theme')).not.toBeInTheDocument()
120154
expect(screen.queryByText('Light')).not.toBeInTheDocument()
121155
expect(screen.queryByText('Dark')).not.toBeInTheDocument()
@@ -128,10 +162,7 @@ describe('MoreDrawer', () => {
128162
mockAuth()
129163
mockServerHealth()
130164
const handleClose = vi.fn()
131-
render(
132-
<MoreDrawer isOpen onClose={handleClose} />,
133-
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
134-
)
165+
renderMoreDrawer({ onClose: handleClose })
135166
fireEvent.click(screen.getByText('Settings'))
136167
expect(navigateMock).toHaveBeenCalledWith(
137168
{ search: 'settings=open&tab=account' },
@@ -144,10 +175,7 @@ describe('MoreDrawer', () => {
144175
mockAuth(logoutMock)
145176
mockServerHealth()
146177
const handleClose = vi.fn()
147-
render(
148-
<MoreDrawer isOpen onClose={handleClose} />,
149-
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
150-
)
178+
renderMoreDrawer({ onClose: handleClose })
151179
fireEvent.click(screen.getByText('Logout'))
152180
expect(logoutMock).toHaveBeenCalled()
153181
})
@@ -156,43 +184,31 @@ describe('MoreDrawer', () => {
156184
mockAuth()
157185
mockServerHealth({ opencodeVersion: '1.4.11', opencodeManagerVersion: '0.9.16' })
158186
const handleClose = vi.fn()
159-
render(
160-
<MoreDrawer isOpen onClose={handleClose} />,
161-
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
162-
)
187+
renderMoreDrawer({ onClose: handleClose })
163188
expect(screen.getByText('v1.4.11 · Manager v0.9.16')).toBeInTheDocument()
164189
})
165190

166191
it('shows unhealthy server status when server is unhealthy', () => {
167192
mockAuth()
168193
mockServerHealth({ opencode: 'unhealthy' as const, opencodeVersion: '1.4.11' })
169194
const handleClose = vi.fn()
170-
render(
171-
<MoreDrawer isOpen onClose={handleClose} />,
172-
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
173-
)
195+
renderMoreDrawer({ onClose: handleClose })
174196
expect(screen.getByText('v1.4.11')).toBeInTheDocument()
175197
})
176198

177199
it('shows fallback text when version is not available', () => {
178200
mockAuth()
179201
mockServerHealth({ opencodeVersion: null, opencodeManagerVersion: null })
180202
const handleClose = vi.fn()
181-
render(
182-
<MoreDrawer isOpen onClose={handleClose} />,
183-
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
184-
)
203+
renderMoreDrawer({ onClose: handleClose })
185204
expect(screen.queryByText('OpenCode')).not.toBeInTheDocument()
186205
})
187206

188207
it('shows session commands and selects a command', () => {
189208
mockAuth()
190209
mockServerHealth()
191210
const handleClose = vi.fn()
192-
render(
193-
<MoreDrawer isOpen onClose={handleClose} />,
194-
{ wrapper: ({ children }) => <MemoryRouter initialEntries={['/repos/1/sessions/session-1']}>{children}</MemoryRouter> },
195-
)
211+
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId', onClose: handleClose })
196212

197213
fireEvent.click(screen.getByText('Commands'))
198214
expect(screen.queryByText('/help')).not.toBeInTheDocument()
@@ -207,10 +223,7 @@ describe('MoreDrawer', () => {
207223
mockServerHealth()
208224
const handleClose = vi.fn()
209225
useUIState.getState().setActivePromptFileBasePath('repo')
210-
render(
211-
<MoreDrawer isOpen onClose={handleClose} />,
212-
{ wrapper: ({ children }) => <MemoryRouter initialEntries={['/repos/1/sessions/session-1']}>{children}</MemoryRouter> },
213-
)
226+
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId', onClose: handleClose })
214227

215228
fireEvent.click(screen.getByText('Mention File'))
216229
expect(screen.getByTestId('mention-file-browser')).toHaveAttribute('data-base-path', 'repo')
@@ -220,4 +233,14 @@ describe('MoreDrawer', () => {
220233
expect(handleClose).toHaveBeenCalled()
221234
})
222235

236+
it('shows Assistant instead of the source repo on assistant routes', () => {
237+
mockAuth()
238+
mockServerHealth()
239+
const handleClose = vi.fn()
240+
renderMoreDrawer({ initialEntry: '/repos/1/assistant', routePath: '/repos/:id/assistant', onClose: handleClose })
241+
242+
expect(screen.getByText('Assistant')).toBeInTheDocument()
243+
expect(screen.queryByText('wrong-repo')).not.toBeInTheDocument()
244+
})
245+
223246
})

frontend/src/components/navigation/MoreDrawer.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
3636
const { data: health } = useServerHealth()
3737
const { memoryPluginEnabled } = useMemoryPluginStatus()
3838
const isSessionDetail = /^\/repos\/\d+\/sessions\/[^/]+$/.test(location.pathname)
39+
const isAssistantRoute = /^\/repos\/\d+\/assistant$/.test(location.pathname)
40+
const isAssistantSession = isSessionDetail && new URLSearchParams(location.search).get('assistant') === '1'
3941
const { filterCommands } = useCommands(isSessionDetail ? OPENCODE_API_ENDPOINT : null)
4042
const activePromptFileBasePath = useUIState((state) => state.activePromptFileBasePath)
4143
const selectPromptCommand = useUIState((state) => state.selectPromptCommand)
@@ -55,6 +57,9 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
5557
})
5658

5759
const currentBranch = repo?.currentBranch || repo?.branch
60+
const repoDisplayName = isAssistantRoute || isAssistantSession
61+
? 'Assistant'
62+
: repo ? getRepoDisplayName(repo.repoUrl, repo.localPath, repo.sourcePath) : null
5863

5964
const handleSettingsClick = () => {
6065
const newParams = new URLSearchParams(location.search)
@@ -132,10 +137,10 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
132137
<X className="h-5 w-5" />
133138
</button>
134139
</div>
135-
{(repo || currentBranch) && (
140+
{(repoDisplayName || currentBranch) && (
136141
<div className="flex items-center gap-2 text-xs text-muted-foreground">
137-
{repo && (
138-
<span className="font-medium text-orange-600 dark:text-orange-400">{getRepoDisplayName(repo.repoUrl, repo.localPath, repo.sourcePath)}</span>
142+
{repoDisplayName && (
143+
<span className="font-medium text-orange-600 dark:text-orange-400">{repoDisplayName}</span>
139144
)}
140145

141146
{currentBranch && (

0 commit comments

Comments
 (0)