forked from anti-work/shortest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Update Test to Fix button by providing logs to the AI (anti-w…
- Loading branch information
Showing
8 changed files
with
322 additions
and
425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,64 @@ | ||
import React from 'react' | ||
import { render, screen, fireEvent, waitFor } from '@testing-library/react' | ||
import { render, screen } from '@testing-library/react' | ||
import { LogView } from './log-view' | ||
import { getWorkflowLogs } from '@/lib/github' | ||
import { vi, describe, it, expect, beforeEach } from 'vitest' | ||
import { SWRConfig } from 'swr' | ||
|
||
vi.mock('@/lib/github', () => ({ | ||
getWorkflowLogs: vi.fn(), | ||
})) | ||
|
||
const mockLogs = ` | ||
2023-05-01T12:00:00.000Z File: test/file1.txt | ||
Line 1 of file 1 | ||
Line 2 of file 1 | ||
2023-05-01T12:01:00.000Z File: test/file2.txt | ||
Line 1 of file 2 | ||
Line 2 of file 2 | ||
2023-05-01T12:02:00.000Z Some other log | ||
` | ||
const mockParsedLogs = [ | ||
{ | ||
id: 'group-0', | ||
name: 'test', | ||
logs: [ | ||
'1 | Line 1 of file 1', | ||
'2 | Line 2 of file 1' | ||
] | ||
}, | ||
{ | ||
id: 'group-1', | ||
name: 'test', | ||
logs: [ | ||
'1 | Line 1 of file 2', | ||
'2 | Line 2 of file 2' | ||
] | ||
}, | ||
{ | ||
id: 'group-2', | ||
name: 'Other', | ||
logs: [ | ||
'1 | Some other log' | ||
] | ||
} | ||
] | ||
|
||
describe('LogView', () => { | ||
const defaultProps = { | ||
owner: 'testOwner', | ||
repo: 'testRepo', | ||
runId: '123', | ||
parsedLogs: mockParsedLogs, | ||
error: undefined, | ||
isLoading: false, | ||
} | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
it('renders loading state', () => { | ||
render(<LogView {...defaultProps} />) | ||
render(<LogView {...defaultProps} isLoading={true} />) | ||
expect(screen.getByText('Loading logs...')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders error state', async () => { | ||
vi.mocked(getWorkflowLogs).mockRejectedValue(new Error('Test error')) | ||
|
||
render( | ||
<SWRConfig value={{ provider: () => new Map() }}> | ||
<LogView {...defaultProps} /> | ||
</SWRConfig> | ||
) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Error loading logs: Test error')).toBeInTheDocument() | ||
}) | ||
it('renders error state', () => { | ||
render(<LogView {...defaultProps} error={new Error('Test error')} />) | ||
expect(screen.getByText('Error loading logs: Test error')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders logs and groups correctly', async () => { | ||
vi.mocked(getWorkflowLogs).mockResolvedValue(mockLogs) | ||
|
||
render( | ||
<SWRConfig value={{ provider: () => new Map() }}> | ||
<LogView {...defaultProps} /> | ||
</SWRConfig> | ||
) | ||
|
||
await waitFor(() => { | ||
const testElements = screen.getAllByText('test') | ||
expect(testElements.length).toBeGreaterThan(0) | ||
expect(screen.getByText('Other')).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
it('expands and collapses log groups', async () => { | ||
vi.mocked(getWorkflowLogs).mockResolvedValue(mockLogs) | ||
|
||
render( | ||
<SWRConfig value={{ provider: () => new Map() }}> | ||
<LogView {...defaultProps} /> | ||
</SWRConfig> | ||
) | ||
|
||
await waitFor(() => { | ||
const testElements = screen.getAllByText('test') | ||
expect(testElements.length).toBeGreaterThan(0) | ||
}) | ||
|
||
// Expand the first group | ||
const testButtons = screen.getAllByText('test') | ||
fireEvent.click(testButtons[0]) | ||
|
||
expect(screen.getByText(/1 \| Line 1 of file 1/)).toBeInTheDocument() | ||
expect(screen.getByText(/2 \| Line 2 of file 1/)).toBeInTheDocument() | ||
|
||
// Collapse the first group | ||
fireEvent.click(testButtons[0]) | ||
it('renders logs and groups correctly', () => { | ||
render(<LogView {...defaultProps} />) | ||
|
||
expect(screen.queryByText(/1 \| Line 1 of file 1/)).not.toBeInTheDocument() | ||
expect(screen.queryByText(/2 \| Line 2 of file 1/)).not.toBeInTheDocument() | ||
expect(screen.getAllByText('test').length).toBe(2) | ||
expect(screen.getByText('Other')).toBeInTheDocument() | ||
}) | ||
|
||
it('does not fetch logs when runId is null', () => { | ||
render(<LogView owner="testOwner" repo="testRepo" runId={null} />) | ||
expect(getWorkflowLogs).not.toHaveBeenCalled() | ||
it('renders empty state when no logs are provided', () => { | ||
render(<LogView parsedLogs={[]} error={undefined} isLoading={false} />) | ||
expect(screen.getByText(/No logs available/i)).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.