mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(ocm-cli): workspace repo sync and manager token targeting (#233)
This commit is contained in:
1 parent
e12f319592
commit
a86e4b1238
69 files changed
+4858
-161
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { ErrorBanner } from './error-banner'
|
||||
|
||||
describe('ErrorBanner', () => {
|
||||
it('renders summary text', () => {
|
||||
render(<ErrorBanner summary="Something went wrong" />)
|
||||
expect(screen.getByText('Something went wrong')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders title when provided', () => {
|
||||
render(<ErrorBanner title="Error" summary="Something went wrong" />)
|
||||
expect(screen.getByText('Error')).toBeInTheDocument()
|
||||
expect(screen.getByText('Something went wrong')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders detail when provided', () => {
|
||||
render(
|
||||
<ErrorBanner
|
||||
summary="Something went wrong"
|
||||
detail="Stack trace here"
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByText('Something went wrong')).toBeInTheDocument()
|
||||
expect(screen.getByText('Stack trace here')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not render dismiss button when onDismiss is not provided', () => {
|
||||
render(<ErrorBanner summary="Something went wrong" />)
|
||||
expect(screen.queryByRole('button')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders dismiss button when onDismiss is provided', () => {
|
||||
const onDismiss = vi.fn()
|
||||
render(
|
||||
<ErrorBanner summary="Something went wrong" onDismiss={onDismiss} />,
|
||||
)
|
||||
expect(screen.getByRole('button')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls onDismiss when dismiss button is clicked', () => {
|
||||
const onDismiss = vi.fn()
|
||||
render(
|
||||
<ErrorBanner summary="Something went wrong" onDismiss={onDismiss} />,
|
||||
)
|
||||
fireEvent.click(screen.getByRole('button'))
|
||||
expect(onDismiss).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('applies custom className', () => {
|
||||
const { container } = render(
|
||||
<ErrorBanner summary="Something went wrong" className="custom-class" />,
|
||||
)
|
||||
expect(container.firstChild).toHaveClass('custom-class')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { AlertCircle, X } from 'lucide-react'
|
||||
|
||||
export interface ErrorBannerProps {
|
||||
title?: string
|
||||
summary: string
|
||||
detail?: string
|
||||
onDismiss?: () => void
|
||||
className?: string
|
||||
}
|
||||
|
||||
export function ErrorBanner({ title, summary, detail, onDismiss, className }: ErrorBannerProps) {
|
||||
return (
|
||||
<Alert variant="destructive" className={className}>
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-start gap-2">
|
||||
<AlertCircle className="h-4 w-4 mt-0.5 flex-shrink-0" />
|
||||
<div className="flex-1 min-w-0">
|
||||
{title && (
|
||||
<AlertTitle className="mb-1 font-medium leading-none tracking-tight">{title}</AlertTitle>
|
||||
)}
|
||||
<AlertDescription className="text-sm">{summary}</AlertDescription>
|
||||
</div>
|
||||
{onDismiss && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-7 w-7 p-0 flex-shrink-0"
|
||||
onClick={onDismiss}
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{detail && (
|
||||
<pre className="p-2 rounded border bg-destructive/5 border-destructive/20 text-xs font-mono overflow-auto max-h-32">
|
||||
{detail}
|
||||
</pre>
|
||||
)}
|
||||
</div>
|
||||
</Alert>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user