Skip to content

Fix timeline entries display issue #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
631 changes: 631 additions & 0 deletions demo1.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/components/RunDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const RunDetails: React.FC<RunDetailsProps> = ({ owner, repo, run, initialConten
if (artifactContent?.content?.trajectory) {
return convertOpenHandsTrajectory(artifactContent.content.trajectory);
}
// Check if this is an uploaded trajectory file
if (artifactContent?.content?.fileType === 'trajectory' && artifactContent?.content?.trajectoryData) {
return convertOpenHandsTrajectory(artifactContent.content.trajectoryData);
}
return artifactContent?.content?.history || artifactContent?.content?.jsonlHistory || [];
} catch (error) {
console.error('Failed to convert trajectory:', error);
Expand Down
133 changes: 0 additions & 133 deletions src/components/timeline/TimelineStep.tsx

This file was deleted.

147 changes: 147 additions & 0 deletions src/components/timeline/__tests__/Timeline.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { vi, describe, test, expect } from 'vitest';
import { Timeline } from '../Timeline';
import { TimelineEntry } from '../types';

// Mock the TimelineStep component
vi.mock('../components/TimelineStep', () => ({
default: ({ entry, index, isSelected, onSelect }: any) => (
<div
data-testid={`timeline-step-${index}`}
data-selected={isSelected.toString()}
onClick={() => onSelect(index)}
>
<span>{entry.type}</span>
{entry.content && <span>{entry.content}</span>}
{entry.command && <span>{entry.command}</span>}
</div>
)
}));

describe('Timeline Component', () => {
const mockOnStepSelect = vi.fn();
const mockOnCommandClick = vi.fn();
const mockFormatTimelineDate = vi.fn().mockReturnValue('12:34 PM');

// Basic test to ensure the component renders
test('renders without crashing', () => {
const entries: TimelineEntry[] = [
{
type: 'message',
timestamp: '2025-03-28T12:34:56Z',
content: 'Test content 1',
actorType: 'User'
},
{
type: 'message',
timestamp: '2025-03-28T12:35:56Z',
content: 'Test content 2',
actorType: 'Assistant'
}
];

render(
<Timeline
entries={entries}
selectedIndex={0}
onStepSelect={mockOnStepSelect}
onCommandClick={mockOnCommandClick}
formatTimelineDate={mockFormatTimelineDate}
createdAt="2025-03-28T12:34:56Z"
/>
);

expect(screen.getByTestId('timeline-step-0')).toBeInTheDocument();
expect(screen.getByTestId('timeline-step-1')).toBeInTheDocument();
});

// Test for empty state
test('renders empty state when no entries are provided', () => {
render(
<Timeline
entries={[]}
selectedIndex={0}
onStepSelect={mockOnStepSelect}
onCommandClick={mockOnCommandClick}
formatTimelineDate={mockFormatTimelineDate}
createdAt="2025-03-28T12:34:56Z"
/>
);

expect(screen.getByText('No timeline entries available')).toBeInTheDocument();
});

// Test for selected step
test('passes isSelected prop correctly to TimelineStep', () => {
const entries: TimelineEntry[] = [
{
type: 'message',
timestamp: '2025-03-28T12:34:56Z',
content: 'Test content 1',
actorType: 'User'
},
{
type: 'message',
timestamp: '2025-03-28T12:35:56Z',
content: 'Test content 2',
actorType: 'Assistant'
}
];

render(
<Timeline
entries={entries}
selectedIndex={1}
onStepSelect={mockOnStepSelect}
onCommandClick={mockOnCommandClick}
formatTimelineDate={mockFormatTimelineDate}
createdAt="2025-03-28T12:34:56Z"
/>
);

expect(screen.getByTestId('timeline-step-0')).toHaveAttribute('data-selected', 'false');
expect(screen.getByTestId('timeline-step-1')).toHaveAttribute('data-selected', 'true');
});

// Test for different entry types
test('renders different types of timeline entries', () => {
const entries: TimelineEntry[] = [
{
type: 'message',
timestamp: '2025-03-28T12:34:56Z',
content: 'Test message',
actorType: 'User'
},
{
type: 'command',
timestamp: '2025-03-28T12:35:56Z',
command: 'ls -la',
actorType: 'Assistant'
},
{
type: 'edit',
timestamp: '2025-03-28T12:36:56Z',
path: '/path/to/file.txt',
actorType: 'Assistant'
}
];

render(
<Timeline
entries={entries}
selectedIndex={0}
onStepSelect={mockOnStepSelect}
onCommandClick={mockOnCommandClick}
formatTimelineDate={mockFormatTimelineDate}
createdAt="2025-03-28T12:34:56Z"
/>
);

expect(screen.getByText('message')).toBeInTheDocument();
expect(screen.getByText('command')).toBeInTheDocument();
expect(screen.getByText('edit')).toBeInTheDocument();
expect(screen.getByText('Test message')).toBeInTheDocument();
expect(screen.getByText('ls -la')).toBeInTheDocument();
});
});
Loading