mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
Merge pull request #371 from chriswritescode-dev/fix/schedules-mobile-run-history
fix(schedules): improve mobile run history layout
This commit is contained in:
14 files changed
+687
-71
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import type { Migration } from '../migration-runner'
|
||||
|
||||
const migration: Migration = {
|
||||
version: 22,
|
||||
name: 'schedule-runs-session-index',
|
||||
|
||||
up(db) {
|
||||
db.run(`
|
||||
CREATE INDEX IF NOT EXISTS idx_schedule_runs_session
|
||||
ON schedule_runs(session_id, started_at DESC)
|
||||
`)
|
||||
},
|
||||
|
||||
down(db) {
|
||||
db.run('DROP INDEX IF EXISTS idx_schedule_runs_session')
|
||||
},
|
||||
}
|
||||
|
||||
export default migration
|
||||
@@ -20,6 +20,7 @@ import migration018 from './018-session-pins'
|
||||
import migration019 from './019-drop-opencode-configs'
|
||||
import migration020 from './020-drop-opencode-model-state'
|
||||
import migration021 from './021-drop-schedule-run-workspace-id'
|
||||
import migration022 from './022-schedule-runs-session-index'
|
||||
|
||||
export const allMigrations: Migration[] = [
|
||||
migration001,
|
||||
@@ -43,4 +44,5 @@ export const allMigrations: Migration[] = [
|
||||
migration019,
|
||||
migration020,
|
||||
migration021,
|
||||
migration022,
|
||||
]
|
||||
@@ -598,10 +598,11 @@ export interface ListAllRunsOptions {
|
||||
repoId?: number
|
||||
jobId?: number
|
||||
triggerSource?: string
|
||||
runId?: number
|
||||
}
|
||||
|
||||
export function listAllScheduleRuns(db: Database, options: ListAllRunsOptions = {}): ScheduleRunWithContext[] {
|
||||
const { limit = 50, offset = 0, status, repoId, jobId, triggerSource } = options
|
||||
const { limit = 50, offset = 0, status, repoId, jobId, triggerSource, runId } = options
|
||||
const conditions: string[] = []
|
||||
const params: (string | number)[] = []
|
||||
|
||||
@@ -621,6 +622,10 @@ export function listAllScheduleRuns(db: Database, options: ListAllRunsOptions =
|
||||
conditions.push('sr.trigger_source = ?')
|
||||
params.push(triggerSource)
|
||||
}
|
||||
if (runId !== undefined) {
|
||||
conditions.push('sr.id = ?')
|
||||
params.push(runId)
|
||||
}
|
||||
|
||||
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''
|
||||
|
||||
|
||||
@@ -19,6 +19,23 @@ function parseRunListLimit(value: string | undefined): number {
|
||||
return Math.min(parsed, 100)
|
||||
}
|
||||
|
||||
function parseRunIdFilter(value: string | undefined): number | undefined {
|
||||
if (value === undefined) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (!/^\d+$/.test(value)) {
|
||||
throw new ScheduleServiceError('Invalid run id', 400)
|
||||
}
|
||||
|
||||
const parsed = Number(value)
|
||||
if (!Number.isSafeInteger(parsed) || parsed < 1) {
|
||||
throw new ScheduleServiceError('Run id must be a positive integer', 400)
|
||||
}
|
||||
|
||||
return parsed
|
||||
}
|
||||
|
||||
export function createScheduleRoutes(scheduleService: ScheduleService) {
|
||||
const app = new Hono()
|
||||
|
||||
@@ -48,7 +65,8 @@ export function createScheduleRoutes(scheduleService: ScheduleService) {
|
||||
return Number.isNaN(parsed) ? undefined : parsed
|
||||
})() : undefined
|
||||
const triggerSource = c.req.query('triggerSource') || undefined
|
||||
const runs = scheduleService.listAllRuns({ limit, offset, status, repoId, jobId, triggerSource })
|
||||
const runId = parseRunIdFilter(c.req.query('runId'))
|
||||
const runs = scheduleService.listAllRuns({ limit, offset, status, repoId, jobId, triggerSource, runId })
|
||||
return c.json({ runs })
|
||||
} catch (error) {
|
||||
return handleServiceError(c, error, 'Failed to list all schedule runs', ScheduleServiceError)
|
||||
|
||||
@@ -4,6 +4,7 @@ import migration007 from '../../src/db/migrations/007-schedules'
|
||||
import migration008 from '../../src/db/migrations/008-schedule-cron-support'
|
||||
import migration015 from '../../src/db/migrations/015-schedule-worktree-isolation'
|
||||
import migration021 from '../../src/db/migrations/021-drop-schedule-run-workspace-id'
|
||||
import migration022 from '../../src/db/migrations/022-schedule-runs-session-index'
|
||||
|
||||
describe('schedule migrations', () => {
|
||||
it('creates schedule jobs with nullable interval minutes in v7', () => {
|
||||
@@ -206,3 +207,33 @@ describe('migration 021 - drop schedule run workspace id', () => {
|
||||
db.close()
|
||||
})
|
||||
})
|
||||
|
||||
describe('migration 022 - schedule run session index', () => {
|
||||
it('creates the composite session index on schedule_runs', () => {
|
||||
const db = new Database(':memory:')
|
||||
db.run('CREATE TABLE schedule_runs (id INTEGER PRIMARY KEY, session_id TEXT, started_at INTEGER NOT NULL)')
|
||||
|
||||
migration022.up(db)
|
||||
|
||||
const indexes = (db.prepare('PRAGMA index_list(schedule_runs)').all() as { name: string }[]).map((index) => index.name)
|
||||
expect(indexes).toContain('idx_schedule_runs_session')
|
||||
|
||||
const columns = (db.prepare('PRAGMA index_info(idx_schedule_runs_session)').all() as { name: string }[]).map((column) => column.name)
|
||||
expect(columns).toEqual(['session_id', 'started_at'])
|
||||
|
||||
db.close()
|
||||
})
|
||||
|
||||
it('drops the index on rollback', () => {
|
||||
const db = new Database(':memory:')
|
||||
db.run('CREATE TABLE schedule_runs (id INTEGER PRIMARY KEY, session_id TEXT, started_at INTEGER NOT NULL)')
|
||||
|
||||
migration022.up(db)
|
||||
migration022.down(db)
|
||||
|
||||
const indexes = (db.prepare('PRAGMA index_list(schedule_runs)').all() as { name: string }[]).map((index) => index.name)
|
||||
expect(indexes).not.toContain('idx_schedule_runs_session')
|
||||
|
||||
db.close()
|
||||
})
|
||||
})
|
||||
@@ -580,6 +580,25 @@ describe('schedule database queries', () => {
|
||||
expect(stmt.all).toHaveBeenCalledWith('manual', 50, 0)
|
||||
})
|
||||
|
||||
it('applies runId filter', () => {
|
||||
const stmt = { all: vi.fn().mockReturnValue([]) }
|
||||
mockDb.prepare.mockReturnValue(stmt)
|
||||
|
||||
schedulesDb.listAllScheduleRuns(mockDb, { runId: 99 })
|
||||
|
||||
expect(mockDb.prepare).toHaveBeenCalledWith(expect.stringContaining('sr.id = ?'))
|
||||
expect(stmt.all).toHaveBeenCalledWith(99, 50, 0)
|
||||
})
|
||||
|
||||
it('applies runId together with other filters', () => {
|
||||
const stmt = { all: vi.fn().mockReturnValue([]) }
|
||||
mockDb.prepare.mockReturnValue(stmt)
|
||||
|
||||
schedulesDb.listAllScheduleRuns(mockDb, { runId: 99, repoId: 42, limit: 1 })
|
||||
|
||||
expect(stmt.all).toHaveBeenCalledWith(42, 99, 1, 0)
|
||||
})
|
||||
|
||||
it('applies limit and offset', () => {
|
||||
const stmt = { all: vi.fn().mockReturnValue([]) }
|
||||
mockDb.prepare.mockReturnValue(stmt)
|
||||
|
||||
@@ -273,4 +273,33 @@ describe('Schedule Routes', () => {
|
||||
triggerSource: 'manual',
|
||||
})
|
||||
})
|
||||
|
||||
it('passes a runId bound to the service for all runs', async () => {
|
||||
scheduleService.listAllRuns.mockReturnValue([])
|
||||
|
||||
const response = await app.request('/repos/42/schedules/all/runs?runId=99')
|
||||
const body = await response.json() as { runs: Array<unknown> }
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
expect(body.runs).toHaveLength(0)
|
||||
expect(scheduleService.listAllRuns).toHaveBeenCalledWith(expect.objectContaining({ runId: 99 }))
|
||||
})
|
||||
|
||||
it.each(['abc', '1abc', '1.5', '-1', ''])('rejects an invalid runId format %s for all runs', async (runId) => {
|
||||
const response = await app.request(`/repos/42/schedules/all/runs?runId=${encodeURIComponent(runId)}`)
|
||||
const body = await response.json() as { error: string }
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
expect(body.error).toBe('Invalid run id')
|
||||
expect(scheduleService.listAllRuns).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it.each(['0', '99999999999999999999'])('rejects a non-positive or unsafe runId %s for all runs', async (runId) => {
|
||||
const response = await app.request(`/repos/42/schedules/all/runs?runId=${runId}`)
|
||||
const body = await response.json() as { error: string }
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
expect(body.error).toBe('Run id must be a positive integer')
|
||||
expect(scheduleService.listAllRuns).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -26,6 +26,7 @@ export interface ListAllRunsParams {
|
||||
repoId?: number
|
||||
jobId?: number
|
||||
triggerSource?: string
|
||||
runId?: number
|
||||
}
|
||||
|
||||
export interface ScheduleCount {
|
||||
@@ -45,6 +46,7 @@ export async function listAllScheduleRuns(params: ListAllRunsParams = {}): Promi
|
||||
if (params.repoId !== undefined) searchParams.set('repoId', String(params.repoId))
|
||||
if (params.jobId !== undefined) searchParams.set('jobId', String(params.jobId))
|
||||
if (params.triggerSource) searchParams.set('triggerSource', params.triggerSource)
|
||||
if (params.runId !== undefined) searchParams.set('runId', String(params.runId))
|
||||
const qs = searchParams.toString()
|
||||
return fetchWrapper(`${API_BASE_URL}/api/schedules/all/runs${qs ? `?${qs}` : ''}`)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, waitFor, fireEvent } from '@testing-library/react'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import { RunDetailPanel } from './RunDetailPanel'
|
||||
import type { Repo } from '@/api/types'
|
||||
import type { ScheduleRun } from '@opencode-manager/shared/types'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
getRepo: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/repos', () => ({
|
||||
getRepo: mocks.getRepo,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/file-browser/FileBrowserSheet', () => ({
|
||||
FileBrowserSheet: ({ isOpen, initialSelectedFile }: { isOpen: boolean; initialSelectedFile?: string }) =>
|
||||
isOpen ? <div data-testid="file-browser-sheet" data-selected-file={initialSelectedFile} /> : null,
|
||||
}))
|
||||
|
||||
const repo: Repo = {
|
||||
id: 5,
|
||||
name: 'my-repo',
|
||||
localPath: 'repos/my-repo',
|
||||
fullPath: '/abs/repos/my-repo',
|
||||
defaultBranch: 'main',
|
||||
cloneStatus: 'ready',
|
||||
clonedAt: 0,
|
||||
}
|
||||
|
||||
const run: ScheduleRun = {
|
||||
id: 1,
|
||||
jobId: 1,
|
||||
repoId: 5,
|
||||
triggerSource: 'manual',
|
||||
status: 'completed',
|
||||
startedAt: 0,
|
||||
finishedAt: null,
|
||||
createdAt: 0,
|
||||
sessionId: null,
|
||||
sessionTitle: null,
|
||||
logText: null,
|
||||
responseText: '[Report](recaps/daily.html)\n\n[Docs](https://example.com)',
|
||||
errorText: null,
|
||||
runBranch: null,
|
||||
commitHash: null,
|
||||
worktreePath: null,
|
||||
}
|
||||
|
||||
function renderPanel() {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: { retry: false },
|
||||
mutations: { retry: false },
|
||||
},
|
||||
})
|
||||
return render(
|
||||
<MemoryRouter>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<RunDetailPanel
|
||||
repoId={5}
|
||||
activeRun={run}
|
||||
selectedRunLoading={false}
|
||||
onCancelRun={vi.fn()}
|
||||
cancelRunPending={false}
|
||||
/>
|
||||
</QueryClientProvider>
|
||||
</MemoryRouter>,
|
||||
)
|
||||
}
|
||||
|
||||
function clickLink(name: string) {
|
||||
const link = screen.getByRole('link', { name })
|
||||
const event = new MouseEvent('click', { bubbles: true, cancelable: true })
|
||||
fireEvent(link, event)
|
||||
return event
|
||||
}
|
||||
|
||||
describe('RunDetailPanel local link handling', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('prevents navigation and opens no sheet while the repo query is pending', async () => {
|
||||
mocks.getRepo.mockReturnValue(new Promise(() => {}))
|
||||
renderPanel()
|
||||
|
||||
await screen.findByRole('status')
|
||||
|
||||
const event = clickLink('Report')
|
||||
|
||||
expect(event.defaultPrevented).toBe(true)
|
||||
expect(screen.queryByTestId('file-browser-sheet')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('prevents navigation, shows a retryable error, and refetches when the repo query fails', async () => {
|
||||
mocks.getRepo.mockRejectedValue(new Error('failed'))
|
||||
renderPanel()
|
||||
|
||||
await screen.findByRole('alert')
|
||||
expect(mocks.getRepo).toHaveBeenCalledTimes(1)
|
||||
|
||||
const event = clickLink('Report')
|
||||
|
||||
expect(event.defaultPrevented).toBe(true)
|
||||
expect(screen.queryByTestId('file-browser-sheet')).not.toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Retry' }))
|
||||
|
||||
await waitFor(() => expect(mocks.getRepo).toHaveBeenCalledTimes(2))
|
||||
})
|
||||
|
||||
it('opens the sheet with the resolved path once the repo is loaded and keeps external links external', async () => {
|
||||
mocks.getRepo.mockResolvedValue(repo)
|
||||
renderPanel()
|
||||
|
||||
await waitFor(() => expect(screen.queryByRole('status')).not.toBeInTheDocument())
|
||||
|
||||
const event = clickLink('Report')
|
||||
|
||||
expect(event.defaultPrevented).toBe(true)
|
||||
const sheet = await screen.findByTestId('file-browser-sheet')
|
||||
expect(sheet.getAttribute('data-selected-file')).toBe('repos/my-repo/recaps/daily.html')
|
||||
|
||||
const docs = screen.getByRole('link', { name: 'Docs' })
|
||||
expect(docs.getAttribute('target')).toBe('_blank')
|
||||
expect(docs.getAttribute('rel')).toBe('noopener noreferrer')
|
||||
})
|
||||
})
|
||||
@@ -23,20 +23,19 @@ interface RunDetailPanelProps {
|
||||
export function RunDetailPanel({ repoId, activeRun, selectedRunLoading, onCancelRun, cancelRunPending }: RunDetailPanelProps) {
|
||||
const navigate = useNavigate()
|
||||
const [selectedFilePath, setSelectedFilePath] = useState<string | null>(null)
|
||||
const { data: repo } = useQuery({
|
||||
const { data: repo, isPending: repoPending, isError: repoError, refetch: refetchRepo } = useQuery({
|
||||
queryKey: ['repo', repoId],
|
||||
queryFn: () => getRepo(repoId),
|
||||
})
|
||||
|
||||
const handleOpenLocalPath = repo
|
||||
? (linkPath: string) => {
|
||||
setSelectedFilePath(getWorkspaceFilePath(linkPath, {
|
||||
directory: activeRun?.worktreePath ?? repo.fullPath,
|
||||
repoFullPath: repo.fullPath,
|
||||
repoLocalPath: repo.localPath,
|
||||
}))
|
||||
}
|
||||
: undefined
|
||||
const handleOpenLocalPath = (linkPath: string) => {
|
||||
if (!repo) return
|
||||
setSelectedFilePath(getWorkspaceFilePath(linkPath, {
|
||||
directory: activeRun?.worktreePath ?? repo.fullPath,
|
||||
repoFullPath: repo.fullPath,
|
||||
repoLocalPath: repo.localPath,
|
||||
}))
|
||||
}
|
||||
|
||||
if (selectedRunLoading && !activeRun) {
|
||||
return (
|
||||
@@ -62,7 +61,7 @@ export function RunDetailPanel({ repoId, activeRun, selectedRunLoading, onCancel
|
||||
<TabsTrigger value="error" disabled={!activeRun.errorText} className="rounded-none border-b-2 border-transparent px-3 py-1.5 text-xs data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none">{activeRun.status === 'cancelled' ? 'Details' : 'Error'}</TabsTrigger>
|
||||
</TabsList>
|
||||
</div>
|
||||
{(activeRun.status === 'running' || activeRun.sessionId || activeRun.responseText) && (
|
||||
{(activeRun.status === 'running' || activeRun.sessionId) && (
|
||||
<div className="flex items-center justify-between gap-2 px-3 py-2">
|
||||
<div className="flex items-center gap-2">
|
||||
{sessionId && (
|
||||
@@ -71,13 +70,15 @@ export function RunDetailPanel({ repoId, activeRun, selectedRunLoading, onCancel
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Button variant="outline" size="sm" onClick={onCancelRun} disabled={cancelRunPending || activeRun.status !== 'running'}>
|
||||
{cancelRunPending ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : null}
|
||||
Cancel run
|
||||
</Button>
|
||||
{activeRun.status === 'running' && (
|
||||
<Button variant="outline" size="sm" onClick={onCancelRun} disabled={cancelRunPending}>
|
||||
{cancelRunPending ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : null}
|
||||
Cancel run
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<TabsContent value="log" className="mt-0 min-h-0 flex-1 overflow-y-auto px-0 py-3 [mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
||||
<TabsContent value="log" className="mt-0 min-h-0 flex-1 overflow-y-auto px-3 py-3 xl:[mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
||||
{selectedRunLoading && !activeRun ? (
|
||||
<div className="flex items-center justify-center p-4"><Loader2 className="h-6 w-6 animate-spin text-muted-foreground" /></div>
|
||||
) : (
|
||||
@@ -88,14 +89,25 @@ export function RunDetailPanel({ repoId, activeRun, selectedRunLoading, onCancel
|
||||
{selectedRunLoading && !activeRun ? (
|
||||
<div className="flex items-center justify-center p-4"><Loader2 className="h-6 w-6 animate-spin text-muted-foreground" /></div>
|
||||
) : activeRun.responseText ? (
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-0 py-2 [mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
||||
<ScheduleRunMarkdown content={activeRun.responseText} onOpenLocalPath={handleOpenLocalPath} />
|
||||
</div>
|
||||
<>
|
||||
{repoPending && (
|
||||
<div role="status" className="px-3 pt-2 text-xs text-muted-foreground">Loading repository details for local links.</div>
|
||||
)}
|
||||
{repoError && (
|
||||
<div role="alert" className="flex items-center gap-2 px-3 pt-2 text-xs text-destructive">
|
||||
<span>Could not load repository details for local links.</span>
|
||||
<Button variant="outline" size="sm" onClick={() => { void refetchRepo() }}>Retry</Button>
|
||||
</div>
|
||||
)}
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-3 py-2 xl:[mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
||||
<ScheduleRunMarkdown content={activeRun.responseText} onOpenLocalPath={handleOpenLocalPath} />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="p-3"><pre className="whitespace-pre-wrap break-words text-sm font-mono leading-6">No assistant output captured.</pre></div>
|
||||
)}
|
||||
</TabsContent>
|
||||
<TabsContent value="error" className="mt-0 min-h-0 flex-1 overflow-y-auto px-0 py-3 [mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
||||
<TabsContent value="error" className="mt-0 min-h-0 flex-1 overflow-y-auto px-3 py-3 xl:[mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
||||
{selectedRunLoading && !activeRun ? (
|
||||
<div className="flex items-center justify-center p-4"><Loader2 className="h-6 w-6 animate-spin text-muted-foreground" /></div>
|
||||
) : (
|
||||
|
||||
@@ -78,20 +78,17 @@ export function RunHistoryCards({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col min-h-0 flex-1 h-full">
|
||||
<div className="min-h-0 flex-1 overflow-y-auto pt-4 px-2 [mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
||||
{runs.map((run, index) => {
|
||||
const isExpanded = expandedRunId === run.id
|
||||
const displayRun = isExpanded && runDetail ? runDetail : run
|
||||
<div className="flex flex-col gap-2">
|
||||
{runs.map((run) => {
|
||||
const isExpanded = expandedRunId === run.id
|
||||
const displayRun = isExpanded && runDetail ? runDetail : run
|
||||
|
||||
return (
|
||||
<div
|
||||
key={run.id}
|
||||
className={`rounded-xl border overflow-hidden transition-all bg-card ${
|
||||
isExpanded ? 'border-border/70' : 'border-border/70'
|
||||
} ${index === 0 ? 'mt-0' : 'mt-2'}`}
|
||||
>
|
||||
<div className="flex items-stretch">
|
||||
return (
|
||||
<div
|
||||
key={run.id}
|
||||
className="rounded-xl border border-border/70 overflow-hidden transition-all bg-card"
|
||||
>
|
||||
<div className="flex items-stretch">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleCardClick(run.id)}
|
||||
@@ -141,24 +138,21 @@ export function RunHistoryCards({
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{isExpanded && (
|
||||
<div className="border-t border-border/60 flex flex-col" style={{ maxHeight: 'calc(100vh - 200px)' }}>
|
||||
<div className="flex flex-col min-h-0 flex-1 overflow-hidden">
|
||||
<RunDetailPanel
|
||||
repoId={run.repoId}
|
||||
activeRun={displayRun}
|
||||
selectedRunLoading={isExpanded && isLoading}
|
||||
onCancelRun={onCancelRun}
|
||||
cancelRunPending={cancelRunPending}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
{isExpanded && (
|
||||
<div className="border-t border-border/60 flex flex-col xl:max-h-[calc(100vh-200px)] xl:overflow-hidden">
|
||||
<RunDetailPanel
|
||||
repoId={run.repoId}
|
||||
activeRun={displayRun}
|
||||
selectedRunLoading={isExpanded && isLoading}
|
||||
onCancelRun={onCancelRun}
|
||||
cancelRunPending={cancelRunPending}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -71,17 +71,19 @@ export function RunHistoryTab({
|
||||
</Button>
|
||||
</div>
|
||||
<div className="min-h-0 flex-1 overflow-hidden pt-2 xl:gap-4 xl:grid xl:grid-cols-[320px_minmax(0,1fr)] xl:grid-rows-1">
|
||||
<RunHistoryCards
|
||||
runs={runs}
|
||||
runsLoading={runsLoading}
|
||||
onSelectRun={onSelectRun}
|
||||
onCancelRun={onCancelRun}
|
||||
cancelRunPending={cancelRunPending}
|
||||
onDeleteRun={onDeleteRun}
|
||||
deleteRunPending={deleteRunPending}
|
||||
/>
|
||||
<div className="min-h-0 h-full overflow-y-auto pb-2 xl:pr-1">
|
||||
<RunHistoryCards
|
||||
runs={runs}
|
||||
runsLoading={runsLoading}
|
||||
onSelectRun={onSelectRun}
|
||||
onCancelRun={onCancelRun}
|
||||
cancelRunPending={cancelRunPending}
|
||||
onDeleteRun={onDeleteRun}
|
||||
deleteRunPending={deleteRunPending}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="hidden xl:flex min-h-0 flex-col overflow-hidden rounded-xl border border-border/60 bg-background/60 p-4">
|
||||
<div className="hidden xl:flex min-h-0 flex-col overflow-hidden rounded-xl border border-border/60 bg-background/60 py-3">
|
||||
<RunDetailPanel
|
||||
repoId={repoId}
|
||||
activeRun={activeRun}
|
||||
|
||||
@@ -12,7 +12,7 @@ import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { DeleteDialog } from '@/components/ui/delete-dialog'
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { CalendarClock, Loader2, Plus, ArrowLeft, Play, Pencil, Trash2, Pause, PlayCircle, Clock3, History, SlidersHorizontal } from 'lucide-react'
|
||||
import { CalendarClock, Loader2, Plus, ArrowLeft, Play, Pencil, Trash2, Pause, PlayCircle, Clock3, History, SlidersHorizontal, XCircle, SearchX } from 'lucide-react'
|
||||
|
||||
import { useScheduleUrlState } from '@/hooks/useScheduleUrlState'
|
||||
import type { ScheduleTab } from '@/hooks/useScheduleUrlState'
|
||||
@@ -70,6 +70,27 @@ export function GlobalSchedules() {
|
||||
|
||||
const { data: runsPage = [], isLoading: runsLoading } = useAllScheduleRuns(runsParams, scheduleTab === 'runs')
|
||||
|
||||
const selectedRunInHistory = useMemo(
|
||||
() => (runId !== null ? allRuns.find((run) => run.id === runId) ?? null : null),
|
||||
[allRuns, runId],
|
||||
)
|
||||
|
||||
const selectedRunParams = useMemo(() => ({ limit: 1, runId: runId ?? undefined }), [runId])
|
||||
|
||||
const {
|
||||
data: selectedRunPage,
|
||||
isLoading: selectedRunLoading,
|
||||
isError: selectedRunError,
|
||||
refetch: refetchSelectedRun,
|
||||
} = useAllScheduleRuns(
|
||||
selectedRunParams,
|
||||
scheduleTab === 'runs' && runId !== null && selectedRunInHistory === null,
|
||||
)
|
||||
|
||||
const selectedRun = runId === null
|
||||
? null
|
||||
: selectedRunInHistory ?? selectedRunPage?.[0] ?? null
|
||||
|
||||
const createMutation = useCreateRepoSchedule()
|
||||
const deleteMutation = useDeleteRepoSchedule()
|
||||
const runMutation = useRunRepoSchedule()
|
||||
@@ -96,8 +117,15 @@ export function GlobalSchedules() {
|
||||
}
|
||||
}, [runsPage])
|
||||
|
||||
const runsForDisplay = useMemo(() => {
|
||||
if (!selectedRun || allRuns.some((run) => run.id === selectedRun.id)) {
|
||||
return allRuns
|
||||
}
|
||||
return [...allRuns, selectedRun]
|
||||
}, [allRuns, selectedRun])
|
||||
|
||||
const sortedRuns = useMemo(() => {
|
||||
const sorted = [...allRuns]
|
||||
const sorted = [...runsForDisplay]
|
||||
sorted.sort((a, b) => {
|
||||
switch (runSortOption) {
|
||||
case 'jobName':
|
||||
@@ -113,7 +141,7 @@ export function GlobalSchedules() {
|
||||
}
|
||||
})
|
||||
return sorted
|
||||
}, [allRuns, runSortOption])
|
||||
}, [runsForDisplay, runSortOption])
|
||||
|
||||
const uniqueRepos = useMemo(() => {
|
||||
const repoMap = new Map<string, { name: string; url: string }>()
|
||||
@@ -312,6 +340,11 @@ export function GlobalSchedules() {
|
||||
|
||||
const hasJobs = jobs.length > 0
|
||||
|
||||
const selectedRunMissing = runId !== null && selectedRunInHistory === null
|
||||
const selectedRunLookupLoading = selectedRunMissing && selectedRunLoading
|
||||
const selectedRunLookupError = selectedRunMissing && selectedRunError && selectedRun === null
|
||||
const selectedRunLookupNotFound = selectedRunMissing && !selectedRunLoading && !selectedRunError && selectedRun === null
|
||||
|
||||
return (
|
||||
<div className="h-dvh max-h-dvh overflow-hidden bg-background flex flex-col">
|
||||
<Header>
|
||||
@@ -355,7 +388,7 @@ export function GlobalSchedules() {
|
||||
</div>
|
||||
|
||||
<TabsContent value="jobs" className="mt-0 flex-1 min-h-0 flex flex-col overflow-hidden">
|
||||
<div className="px-4 pt-1 space-y-2">
|
||||
<div className="px-2 sm:px-4 pt-1 space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap hidden sm:inline">Filter by repo:</span>
|
||||
<Combobox
|
||||
@@ -504,7 +537,7 @@ export function GlobalSchedules() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-h-0 overflow-y-auto p-4 pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-4 [mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
||||
<div className="flex-1 min-h-0 overflow-y-auto px-2 sm:px-4 pt-2 pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-4">
|
||||
{!hasJobs ? (
|
||||
<div className="flex min-h-full items-center justify-center">
|
||||
<Card className="max-w-md border-dashed border-border/70">
|
||||
@@ -667,7 +700,7 @@ export function GlobalSchedules() {
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="runs" className="mt-0 flex-1 min-h-0 flex flex-col overflow-hidden">
|
||||
<div className="px-4 pt-1 space-y-2">
|
||||
<div className="px-2 sm:px-4 pt-1 space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap hidden sm:inline">Filter by repo:</span>
|
||||
<Combobox
|
||||
@@ -816,13 +849,60 @@ export function GlobalSchedules() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-h-0 overflow-y-auto py-4 pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-4 [mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
||||
<div className="flex-1 min-h-0 overflow-y-auto px-2 sm:px-4 pt-2 pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-4">
|
||||
{runsLoading && allRuns.length === 0 ? (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
) : allRuns.length === 0 ? (
|
||||
<div className="flex items-center justify-center px-4 py-12">
|
||||
) : selectedRunLookupLoading ? (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
) : selectedRunLookupError ? (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Card className="max-w-md border-dashed border-border/70">
|
||||
<CardContent className="flex flex-col items-center gap-4 p-8 text-center">
|
||||
<div className="rounded-full border border-border bg-muted/40 p-4">
|
||||
<XCircle className="h-8 w-8 text-destructive" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<p className="text-lg font-semibold">Failed to load run</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
The selected run could not be loaded.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={() => { void refetchSelectedRun() }}>
|
||||
Retry
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => selectRun(null)}>
|
||||
Back to run history
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
) : selectedRunLookupNotFound ? (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Card className="max-w-md border-dashed border-border/70">
|
||||
<CardContent className="flex flex-col items-center gap-4 p-8 text-center">
|
||||
<div className="rounded-full border border-border bg-muted/40 p-4">
|
||||
<SearchX className="h-8 w-8 text-muted-foreground" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<p className="text-lg font-semibold">Run not found</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
The requested run no longer exists.
|
||||
</p>
|
||||
</div>
|
||||
<Button variant="outline" onClick={() => selectRun(null)}>
|
||||
Back to run history
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
) : sortedRuns.length === 0 ? (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Card className="max-w-md border-dashed border-border/70">
|
||||
<CardContent className="flex flex-col items-center gap-4 p-8 text-center">
|
||||
<div className="rounded-full border border-border bg-muted/40 p-4">
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { GlobalSchedules } from '../GlobalSchedules'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
useAllSchedules: vi.fn(),
|
||||
useAllScheduleRuns: vi.fn(),
|
||||
useCreateRepoSchedule: vi.fn(),
|
||||
useUpdateRepoSchedule: vi.fn(),
|
||||
useDeleteRepoSchedule: vi.fn(),
|
||||
useRunRepoSchedule: vi.fn(),
|
||||
useCancelRepoScheduleRun: vi.fn(),
|
||||
useScheduleUrlState: vi.fn(),
|
||||
RunHistoryCards: vi.fn(() => null),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSchedules', () => ({
|
||||
useAllSchedules: mocks.useAllSchedules,
|
||||
useAllScheduleRuns: mocks.useAllScheduleRuns,
|
||||
useCreateRepoSchedule: mocks.useCreateRepoSchedule,
|
||||
useUpdateRepoSchedule: mocks.useUpdateRepoSchedule,
|
||||
useDeleteRepoSchedule: mocks.useDeleteRepoSchedule,
|
||||
useRunRepoSchedule: mocks.useRunRepoSchedule,
|
||||
useCancelRepoScheduleRun: mocks.useCancelRepoScheduleRun,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useScheduleUrlState', () => ({
|
||||
useScheduleUrlState: mocks.useScheduleUrlState,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/schedules', () => ({
|
||||
ScheduleJobDialog: vi.fn(() => null),
|
||||
RunHistoryCards: mocks.RunHistoryCards,
|
||||
PromptsTab: vi.fn(() => null),
|
||||
}))
|
||||
|
||||
function makeRun(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
id: 1,
|
||||
jobId: 7,
|
||||
repoId: 42,
|
||||
triggerSource: 'manual',
|
||||
status: 'completed',
|
||||
startedAt: Date.UTC(2026, 2, 9, 12, 0, 0),
|
||||
finishedAt: Date.UTC(2026, 2, 9, 12, 5, 0),
|
||||
createdAt: Date.UTC(2026, 2, 9, 12, 0, 0),
|
||||
sessionId: 'ses-1',
|
||||
sessionTitle: 'Run title',
|
||||
logText: null,
|
||||
responseText: null,
|
||||
errorText: null,
|
||||
runBranch: null,
|
||||
commitHash: null,
|
||||
worktreePath: null,
|
||||
jobName: 'Weekly summary',
|
||||
repoName: 'my-repo',
|
||||
repoPath: '/home/user/my-repo',
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
function createMockScheduleUrlState(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
scheduleTab: 'runs',
|
||||
setScheduleTab: vi.fn(),
|
||||
dialog: null,
|
||||
promptDialog: null,
|
||||
jobId: null,
|
||||
runId: null,
|
||||
templateId: null,
|
||||
openNewJob: vi.fn(),
|
||||
openEditJob: vi.fn(),
|
||||
openDeleteJob: vi.fn(),
|
||||
openNewTemplate: vi.fn(),
|
||||
openEditTemplate: vi.fn(),
|
||||
openDeleteTemplate: vi.fn(),
|
||||
openImportTemplate: vi.fn(),
|
||||
closeDialog: vi.fn(),
|
||||
closePromptDialog: vi.fn(),
|
||||
selectRun: vi.fn(),
|
||||
selectJobAndView: vi.fn(),
|
||||
selectJobAndCloseDialog: vi.fn(),
|
||||
replaceUrlParams: vi.fn(),
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
let mainRunsResult: { data: unknown; isLoading: boolean; isError?: boolean }
|
||||
let selectedRunResult: { data: unknown; isLoading: boolean; isError?: boolean; refetch?: () => void }
|
||||
|
||||
const createWrapper = () => {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: { retry: false },
|
||||
mutations: { retry: false },
|
||||
},
|
||||
})
|
||||
return ({ children }: { children: React.ReactNode }) =>
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
}
|
||||
|
||||
const renderGlobalSchedules = () => {
|
||||
return render(
|
||||
<MemoryRouter initialEntries={['/schedules']}>
|
||||
<GlobalSchedules />
|
||||
</MemoryRouter>,
|
||||
{ wrapper: createWrapper() }
|
||||
)
|
||||
}
|
||||
|
||||
const runHistoryProps = () => mocks.RunHistoryCards.mock.calls.at(-1)?.[0] as {
|
||||
runs: Array<{ id: number }>
|
||||
selectedRunId: number | null
|
||||
}
|
||||
|
||||
describe('GlobalSchedules run history', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mainRunsResult = { data: [], isLoading: false }
|
||||
selectedRunResult = { data: undefined, isLoading: false, isError: false }
|
||||
|
||||
mocks.useAllScheduleRuns.mockImplementation((params: { limit?: number }) =>
|
||||
params.limit === 1 ? selectedRunResult : mainRunsResult
|
||||
)
|
||||
mocks.useAllSchedules.mockReturnValue({ data: [], isLoading: false, error: null })
|
||||
mocks.useCreateRepoSchedule.mockReturnValue({ mutate: vi.fn(), isPending: false })
|
||||
mocks.useUpdateRepoSchedule.mockReturnValue({ mutate: vi.fn(), isPending: false })
|
||||
mocks.useDeleteRepoSchedule.mockReturnValue({ mutate: vi.fn(), isPending: false })
|
||||
mocks.useRunRepoSchedule.mockReturnValue({ mutate: vi.fn(), isPending: false })
|
||||
mocks.useCancelRepoScheduleRun.mockReturnValue({ mutate: vi.fn(), isPending: false })
|
||||
mocks.useScheduleUrlState.mockReturnValue(createMockScheduleUrlState())
|
||||
})
|
||||
|
||||
it('loads and pins a selected run outside the loaded history', () => {
|
||||
const historyRuns = Array.from({ length: 50 }, (_, index) => makeRun({ id: index + 1, sessionTitle: `Run ${index + 1}` }))
|
||||
mainRunsResult = { data: historyRuns, isLoading: false }
|
||||
selectedRunResult = { data: [makeRun({ id: 999, sessionTitle: 'Deep linked run' })], isLoading: false, isError: false }
|
||||
mocks.useScheduleUrlState.mockReturnValue(createMockScheduleUrlState({ scheduleTab: 'runs', runId: 999 }))
|
||||
|
||||
renderGlobalSchedules()
|
||||
|
||||
expect(mocks.useAllScheduleRuns).toHaveBeenCalledWith({ limit: 1, runId: 999 }, true)
|
||||
const props = runHistoryProps()
|
||||
expect(props.selectedRunId).toBe(999)
|
||||
expect(props.runs.some((run) => run.id === 999)).toBe(true)
|
||||
expect(screen.queryByText('No runs found')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not duplicate a selected run already present in history', () => {
|
||||
mainRunsResult = { data: [makeRun({ id: 5 }), makeRun({ id: 6 })], isLoading: false }
|
||||
mocks.useScheduleUrlState.mockReturnValue(createMockScheduleUrlState({ scheduleTab: 'runs', runId: 5 }))
|
||||
|
||||
renderGlobalSchedules()
|
||||
|
||||
expect(mocks.useAllScheduleRuns).toHaveBeenCalledWith({ limit: 1, runId: 5 }, false)
|
||||
const props = runHistoryProps()
|
||||
expect(props.runs.filter((run) => run.id === 5)).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('shows loading instead of no runs while the selected run lookup is pending', () => {
|
||||
selectedRunResult = { data: undefined, isLoading: true, isError: false }
|
||||
mocks.useScheduleUrlState.mockReturnValue(createMockScheduleUrlState({ scheduleTab: 'runs', runId: 999 }))
|
||||
|
||||
const { container } = renderGlobalSchedules()
|
||||
|
||||
expect(screen.queryByText('No runs found')).not.toBeInTheDocument()
|
||||
expect(container.querySelector('.animate-spin')).not.toBeNull()
|
||||
expect(mocks.RunHistoryCards).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows run not found when the selected run lookup returns empty', () => {
|
||||
selectedRunResult = { data: [], isLoading: false, isError: false }
|
||||
const selectRun = vi.fn()
|
||||
mocks.useScheduleUrlState.mockReturnValue(createMockScheduleUrlState({ scheduleTab: 'runs', runId: 999, selectRun }))
|
||||
|
||||
renderGlobalSchedules()
|
||||
|
||||
expect(screen.getByText('Run not found')).toBeInTheDocument()
|
||||
expect(screen.queryByText('No runs found')).not.toBeInTheDocument()
|
||||
expect(mocks.RunHistoryCards).not.toHaveBeenCalled()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Back to run history' }))
|
||||
|
||||
expect(selectRun).toHaveBeenCalledWith(null)
|
||||
})
|
||||
|
||||
it('shows an error with retry and back actions when the selected run lookup fails', () => {
|
||||
const refetch = vi.fn()
|
||||
selectedRunResult = { data: undefined, isLoading: false, isError: true, refetch }
|
||||
const selectRun = vi.fn()
|
||||
mocks.useScheduleUrlState.mockReturnValue(createMockScheduleUrlState({ scheduleTab: 'runs', runId: 999, selectRun }))
|
||||
|
||||
renderGlobalSchedules()
|
||||
|
||||
expect(screen.getByText('Failed to load run')).toBeInTheDocument()
|
||||
expect(screen.queryByText('No runs found')).not.toBeInTheDocument()
|
||||
expect(mocks.RunHistoryCards).not.toHaveBeenCalled()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Retry' }))
|
||||
expect(refetch).toHaveBeenCalledTimes(1)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Back to run history' }))
|
||||
expect(selectRun).toHaveBeenCalledWith(null)
|
||||
})
|
||||
|
||||
it('renders the cached selected run when a background refetch fails', () => {
|
||||
selectedRunResult = { data: [makeRun({ id: 999, sessionTitle: 'Deep linked run' })], isLoading: false, isError: true }
|
||||
mocks.useScheduleUrlState.mockReturnValue(createMockScheduleUrlState({ scheduleTab: 'runs', runId: 999 }))
|
||||
|
||||
renderGlobalSchedules()
|
||||
|
||||
expect(screen.queryByText('Failed to load run')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Run not found')).not.toBeInTheDocument()
|
||||
expect(mocks.RunHistoryCards).toHaveBeenCalled()
|
||||
const props = runHistoryProps()
|
||||
expect(props.selectedRunId).toBe(999)
|
||||
expect(props.runs.filter((run) => run.id === 999)).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('re-queries when the selected run id changes', () => {
|
||||
mainRunsResult = { data: [], isLoading: false }
|
||||
selectedRunResult = { data: [makeRun({ id: 999 })], isLoading: false, isError: false }
|
||||
mocks.useScheduleUrlState.mockReturnValue(createMockScheduleUrlState({ scheduleTab: 'runs', runId: 999 }))
|
||||
|
||||
const { rerender } = renderGlobalSchedules()
|
||||
|
||||
expect(mocks.useAllScheduleRuns).toHaveBeenCalledWith({ limit: 1, runId: 999 }, true)
|
||||
|
||||
selectedRunResult = { data: [makeRun({ id: 1000 })], isLoading: false, isError: false }
|
||||
mocks.useScheduleUrlState.mockReturnValue(createMockScheduleUrlState({ scheduleTab: 'runs', runId: 1000 }))
|
||||
|
||||
rerender(
|
||||
<MemoryRouter initialEntries={['/schedules']}>
|
||||
<GlobalSchedules />
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
expect(mocks.useAllScheduleRuns).toHaveBeenCalledWith({ limit: 1, runId: 1000 }, true)
|
||||
expect(runHistoryProps().runs.some((run) => run.id === 1000)).toBe(true)
|
||||
})
|
||||
|
||||
it('ignores cached selected run data when the selection is cleared', () => {
|
||||
mainRunsResult = { data: [], isLoading: false }
|
||||
selectedRunResult = { data: [makeRun({ id: 999, sessionTitle: 'Deep linked run' })], isLoading: false, isError: false }
|
||||
mocks.useScheduleUrlState.mockReturnValue(createMockScheduleUrlState({ scheduleTab: 'runs', runId: 999 }))
|
||||
|
||||
const { rerender } = renderGlobalSchedules()
|
||||
|
||||
expect(runHistoryProps().runs.some((run) => run.id === 999)).toBe(true)
|
||||
|
||||
mocks.RunHistoryCards.mockClear()
|
||||
mocks.useScheduleUrlState.mockReturnValue(createMockScheduleUrlState({ scheduleTab: 'runs', runId: null }))
|
||||
|
||||
rerender(
|
||||
<MemoryRouter initialEntries={['/schedules']}>
|
||||
<GlobalSchedules />
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
expect(screen.getByText('No runs found')).toBeInTheDocument()
|
||||
expect(mocks.RunHistoryCards).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not query the selected run when the runs tab is inactive', () => {
|
||||
mocks.useScheduleUrlState.mockReturnValue(createMockScheduleUrlState({ scheduleTab: 'jobs', runId: 999 }))
|
||||
|
||||
renderGlobalSchedules()
|
||||
|
||||
expect(mocks.useAllScheduleRuns).toHaveBeenCalledWith({ limit: 1, runId: 999 }, false)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user