Skip to content
Open
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
7 changes: 6 additions & 1 deletion frontend/src/components/SessionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function readViewMode(): ViewMode {
}

export function SessionPanel({ activeSessionId, onSelectSession, onNewChat }: SessionPanelProps) {
const { sessions, loading, dismissSession } = useSessionList();
const { sessions, loading, loadingMore, hasMore, loadMore, dismissSession } = useSessionList();
const { attendCount } = useSessionOverview();
const [viewMode, setViewMode] = useState<ViewMode>(readViewMode);

Expand Down Expand Up @@ -99,6 +99,11 @@ export function SessionPanel({ activeSessionId, onSelectSession, onNewChat }: Se
</button>
</div>
))}
{hasMore && (
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 missing_tests: The existing SessionPanel test file (components/tests/SessionPanel.test.tsx) mocks hasMore: false but has no test cases exercising the Load More button — rendering when hasMore is true, the disabled state when loadingMore is true, or that loadMore is called on click. The mobile SessionList page uses the identical pattern and also lacks dedicated tests for it, so this is a pre-existing gap, but worth noting. [fixable]

<button className="session-load-more" onClick={loadMore} disabled={loadingMore}>
{loadingMore ? 'Loading...' : 'Load More'}
</button>
)}
</div>
)}
</>
Expand Down
73 changes: 73 additions & 0 deletions frontend/src/components/__tests__/SessionPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ vi.mock('../../hooks/useSessionList', () => ({
useSessionList: vi.fn(),
}));

// Mock useSessionOverview to avoid EventSource dependency
vi.mock('../../hooks/useSessionOverview', () => ({
useSessionOverview: vi.fn(() => ({
activities: [],
attendCount: 0,
connected: false,
})),
}));

import { SessionPanel } from '../SessionPanel';
import { useSessionList } from '../../hooks/useSessionList';

Expand All @@ -32,11 +41,15 @@ function makeDefaultReturn(overrides = {}) {

beforeEach(() => {
mockUseSessionList.mockReturnValue(makeDefaultReturn());
// Default to "All" view so session list tests work (the "Active" view
// renders ActiveSessionsList which is tested separately).
localStorage.setItem('mitzo-session-view-mode', 'all');
});

afterEach(() => {
cleanup();
vi.clearAllMocks();
localStorage.clear();
});

describe('SessionPanel', () => {
Expand Down Expand Up @@ -143,4 +156,64 @@ describe('SessionPanel', () => {
fireEvent.click(deleteBtn);
expect(dismiss).toHaveBeenCalledWith('s1');
});

describe('Load More button', () => {
it('does not render Load More when hasMore is false', () => {
mockUseSessionList.mockReturnValue(
makeDefaultReturn({
sessions: [{ id: 's1', summary: 'A session', lastModified: Date.now() }],
hasMore: false,
}),
);
render(
<SessionPanel activeSessionId={undefined} onSelectSession={vi.fn()} onNewChat={vi.fn()} />,
);
expect(screen.queryByText('Load More')).toBeNull();
});

it('renders when hasMore is true', () => {
mockUseSessionList.mockReturnValue(
makeDefaultReturn({
sessions: [{ id: 's1', summary: 'A session', lastModified: Date.now() }],
hasMore: true,
}),
);
render(
<SessionPanel activeSessionId={undefined} onSelectSession={vi.fn()} onNewChat={vi.fn()} />,
);
expect(screen.getByText('Load More')).toBeTruthy();
});

it('shows disabled loading state when loadingMore is true', () => {
mockUseSessionList.mockReturnValue(
makeDefaultReturn({
sessions: [{ id: 's1', summary: 'A session', lastModified: Date.now() }],
hasMore: true,
loadingMore: true,
}),
);
render(
<SessionPanel activeSessionId={undefined} onSelectSession={vi.fn()} onNewChat={vi.fn()} />,
);
const btn = screen.getByText('Loading...');
expect(btn).toBeTruthy();
expect((btn as HTMLButtonElement).disabled).toBe(true);
});

it('calls loadMore when clicked', () => {
const loadMore = vi.fn();
mockUseSessionList.mockReturnValue(
makeDefaultReturn({
sessions: [{ id: 's1', summary: 'A session', lastModified: Date.now() }],
hasMore: true,
loadMore,
}),
);
render(
<SessionPanel activeSessionId={undefined} onSelectSession={vi.fn()} onNewChat={vi.fn()} />,
);
fireEvent.click(screen.getByText('Load More'));
expect(loadMore).toHaveBeenCalledOnce();
});
});
});
Loading