Skip to content
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
14 changes: 12 additions & 2 deletions apps/web/src/__tests__/components/AssistantChatPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,18 @@ describe('AssistantPage (chat)', () => {
if (query.includes('ChatHistory'))
return Promise.resolve({
chatHistory: [
{ role: 'user', content: 'earlier question' },
{ role: 'assistant', content: 'earlier answer' },
{
id: 'm1',
role: 'user',
content: 'earlier question',
createdAt: '2024-01-01T00:00:00.000Z',
},
{
id: 'm2',
role: 'assistant',
content: 'earlier answer',
createdAt: '2024-01-01T00:00:01.000Z',
},
],
});
return Promise.resolve({});
Expand Down
148 changes: 148 additions & 0 deletions apps/web/src/__tests__/components/ChatConversationView.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

const { mockGqlRequest } = vi.hoisted(() => ({
mockGqlRequest: vi.fn(),
}));

vi.mock('@tanstack/react-router', () => ({
Link: ({ children, to }: { children: React.ReactNode; to: string }) => (
<a href={to}>{children}</a>
),
}));

vi.mock('#/graphql/client', () => ({
gqlClient: { request: mockGqlRequest },
}));

import { ChatConversationView } from '#/routes/_authenticated/assistant/-components/ChatConversationView';

const makeClient = () =>
new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } });

function Wrapper({ children }: { children: React.ReactNode }) {
return <QueryClientProvider client={makeClient()}>{children}</QueryClientProvider>;
}

describe('ChatConversationView', () => {
beforeEach(() => {
vi.clearAllMocks();
});

it('shows the empty state and no suggested questions when none are given', async () => {
render(
<ChatConversationView
conversationId={null}
provider={null}
model=""
onConversationCreated={vi.fn()}
/>,
{ wrapper: Wrapper },
);

await waitFor(() =>
expect(
screen.getByText('Ask about your applications, contacts, or interview rounds.'),
).toBeInTheDocument(),
);
expect(screen.queryByRole('button', { name: /summarize/i })).not.toBeInTheDocument();
});

it('renders suggested question chips when provided, and lazily creates a conversation on click', async () => {
// conversationId is a controlled prop — a real caller (AssistantPage's
// routing, or the dock's own state) re-renders with the new id once
// onConversationCreated fires, which is what makes the reply visible.
// This test asserts what the component itself is responsible for: the
// create + send calls firing with the right arguments, and the callback
// firing with the new id — not the caller's downstream re-render.
mockGqlRequest.mockImplementation((query: string) => {
if (query.includes('CreateConversation'))
return Promise.resolve({
createConversation: { id: 'new-conv', title: null, createdAt: '', updatedAt: '' },
});
if (query.includes('SendChatMessage'))
return Promise.resolve({ sendChatMessage: 'Here you go.' });
return Promise.resolve({});
});
const onConversationCreated = vi.fn();

render(
<ChatConversationView
conversationId={null}
provider="anthropic"
model=""
onConversationCreated={onConversationCreated}
suggestedQuestions={['What are my active applications?']}
/>,
{ wrapper: Wrapper },
);

await waitFor(() =>
expect(screen.getByText('What are my active applications?')).toBeInTheDocument(),
);
fireEvent.click(screen.getByText('What are my active applications?'));

await waitFor(() =>
expect(mockGqlRequest).toHaveBeenCalledWith(
expect.stringContaining('SendChatMessage'),
expect.objectContaining({
conversationId: 'new-conv',
message: 'What are my active applications?',
}),
),
);
expect(onConversationCreated).toHaveBeenCalledWith('new-conv');
});

it('renders existing chat history for an active conversation', async () => {
mockGqlRequest.mockImplementation((query: string) => {
if (query.includes('ChatHistory'))
return Promise.resolve({
chatHistory: [
{ id: 'm1', role: 'user', content: 'hi', createdAt: '2024-01-01T00:00:00.000Z' },
{
id: 'm2',
role: 'assistant',
content: 'hello!',
createdAt: '2024-01-01T00:00:01.000Z',
},
],
});
return Promise.resolve({});
});

render(
<ChatConversationView
conversationId="conv-1"
provider={null}
model=""
onConversationCreated={vi.fn()}
/>,
{ wrapper: Wrapper },
);

await waitFor(() => expect(screen.getByText('hi')).toBeInTheDocument());
expect(screen.getByText('hello!')).toBeInTheDocument();
});

it('applies compact spacing when compact is true', async () => {
const { container } = render(
<ChatConversationView
conversationId={null}
provider={null}
model=""
onConversationCreated={vi.fn()}
compact
/>,
{ wrapper: Wrapper },
);

await waitFor(() =>
expect(
screen.getByText('Ask about your applications, contacts, or interview rounds.'),
).toBeInTheDocument(),
);
expect(container.querySelector('.p-3')).not.toBeNull();
});
});
131 changes: 131 additions & 0 deletions apps/web/src/__tests__/components/ChatDockFloatingWindow.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

const { mockGqlRequest, mockNavigate, mockDock } = vi.hoisted(() => ({
mockGqlRequest: vi.fn(),
mockNavigate: vi.fn(),
mockDock: {
sections: [] as string[],
expanded: null as string | 'new' | null,
openNew: vi.fn(),
openConversation: vi.fn(),
minimize: vi.fn(),
closeExpanded: vi.fn(),
closeSection: vi.fn(),
promoteNewConversation: vi.fn(),
},
}));

vi.mock('@tanstack/react-router', () => ({
useNavigate: () => mockNavigate,
Link: ({ children, to }: { children: React.ReactNode; to: string }) => (
<a href={to}>{children}</a>
),
}));

vi.mock('#/graphql/client', () => ({
gqlClient: { request: mockGqlRequest },
}));

vi.mock('#/lib/chatDock', () => ({
useChatDock: () => mockDock,
}));

import { ChatDockFloatingWindow } from '#/routes/_authenticated/-chat-dock-floating-window';

const makeClient = () => new QueryClient({ defaultOptions: { queries: { retry: false } } });

function Wrapper({ children }: { children: React.ReactNode }) {
return <QueryClientProvider client={makeClient()}>{children}</QueryClientProvider>;
}

describe('ChatDockFloatingWindow', () => {
beforeEach(() => {
vi.clearAllMocks();
mockDock.sections = [];
mockDock.expanded = null;
mockGqlRequest.mockImplementation((query: string) => {
if (query.includes('LlmApiKeys'))
return Promise.resolve({
llmApiKeys: [{ provider: 'anthropic' }],
me: { defaultLlmProvider: 'anthropic' },
});
if (query.includes('Conversations'))
return Promise.resolve({
conversations: [
{ id: 'conv-1', title: 'Ghosted applications', updatedAt: '2024-01-01T00:00:00.000Z' },
],
});
return Promise.resolve({ chatHistory: [] });
});
});

it('renders nothing when nothing is expanded', () => {
const { container } = render(<ChatDockFloatingWindow />, { wrapper: Wrapper });
expect(container).toBeEmptyDOMElement();
});

it('shows "New conversation" with maximize disabled for a not-yet-created draft', async () => {
mockDock.expanded = 'new';
render(<ChatDockFloatingWindow />, { wrapper: Wrapper });

await waitFor(() => expect(screen.getByText('New conversation')).toBeInTheDocument());
expect(screen.getByLabelText('Maximize')).toBeDisabled();
});

it('shows the real conversation title when an existing conversation is expanded', async () => {
mockDock.expanded = 'conv-1';
render(<ChatDockFloatingWindow />, { wrapper: Wrapper });

await waitFor(() => expect(screen.getByText('Ghosted applications')).toBeInTheDocument());
expect(screen.getByLabelText('Maximize')).not.toBeDisabled();
});

it('clicking minimize calls dock.minimize', async () => {
mockDock.expanded = 'conv-1';
render(<ChatDockFloatingWindow />, { wrapper: Wrapper });
await waitFor(() => expect(screen.getByText('Ghosted applications')).toBeInTheDocument());

fireEvent.click(screen.getByLabelText('Minimize'));

expect(mockDock.minimize).toHaveBeenCalledOnce();
});

it('clicking close calls dock.closeExpanded', async () => {
mockDock.expanded = 'conv-1';
render(<ChatDockFloatingWindow />, { wrapper: Wrapper });
await waitFor(() => expect(screen.getByText('Ghosted applications')).toBeInTheDocument());

fireEvent.click(screen.getByLabelText('Close'));

expect(mockDock.closeExpanded).toHaveBeenCalledOnce();
});

it('clicking maximize navigates to the full assistant page and closes the dock section', async () => {
mockDock.expanded = 'conv-1';
render(<ChatDockFloatingWindow />, { wrapper: Wrapper });
await waitFor(() => expect(screen.getByText('Ghosted applications')).toBeInTheDocument());

fireEvent.click(screen.getByLabelText('Maximize'));

expect(mockNavigate).toHaveBeenCalledWith({
to: '/assistant',
search: { conversation: 'conv-1' },
});
expect(mockDock.closeExpanded).toHaveBeenCalledOnce();
});

it('shows a settings prompt instead of the chat view when no AI API key is configured', async () => {
mockDock.expanded = 'new';
mockGqlRequest.mockImplementation((query: string) => {
if (query.includes('LlmApiKeys'))
return Promise.resolve({ llmApiKeys: [], me: { defaultLlmProvider: null } });
return Promise.resolve({ conversations: [] });
});
render(<ChatDockFloatingWindow />, { wrapper: Wrapper });

await waitFor(() => expect(screen.getByText(/Add an AI API key/)).toBeInTheDocument());
expect(screen.queryByPlaceholderText('Ask a question…')).not.toBeInTheDocument();
});
});
88 changes: 88 additions & 0 deletions apps/web/src/__tests__/components/ChatDockFooter.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

const { mockGqlRequest } = vi.hoisted(() => ({
mockGqlRequest: vi.fn(),
}));

vi.mock('#/graphql/client', () => ({
gqlClient: { request: mockGqlRequest },
}));

import { ChatDockProvider } from '#/lib/chatDock';
import { ChatDockFooter } from '#/routes/_authenticated/-chat-dock-footer';

const makeClient = () => new QueryClient({ defaultOptions: { queries: { retry: false } } });

function Wrapper({ children }: { children: React.ReactNode }) {
return (
<QueryClientProvider client={makeClient()}>
<ChatDockProvider>{children}</ChatDockProvider>
</QueryClientProvider>
);
}

describe('ChatDockFooter', () => {
beforeEach(() => {
vi.clearAllMocks();
mockGqlRequest.mockResolvedValue({
conversations: [
{
id: 'conv-1',
title: 'Ghosted applications',
llmProvider: 'anthropic',
updatedAt: '2024-01-01T00:00:00.000Z',
},
],
});
});

it('renders the launcher button and no pills initially', () => {
render(<ChatDockFooter />, { wrapper: Wrapper });
expect(screen.getByLabelText('Chat with Assistant')).toBeInTheDocument();
expect(screen.queryByLabelText('Close conversation')).not.toBeInTheDocument();
});

it('opens the picker on click, showing New conversation and recent conversations', async () => {
render(<ChatDockFooter />, { wrapper: Wrapper });
fireEvent.click(screen.getByLabelText('Chat with Assistant'));

expect(screen.getByText('New conversation')).toBeInTheDocument();
await waitFor(() => expect(screen.getByText('Ghosted applications')).toBeInTheDocument());
});

it('selecting a recent conversation closes the picker and pins a pill', async () => {
render(<ChatDockFooter />, { wrapper: Wrapper });
fireEvent.click(screen.getByLabelText('Chat with Assistant'));
await waitFor(() => expect(screen.getByText('Ghosted applications')).toBeInTheDocument());

fireEvent.click(screen.getByText('Ghosted applications'));

expect(screen.queryByText('New conversation')).not.toBeInTheDocument();
expect(screen.getByLabelText('Close conversation')).toBeInTheDocument();
});

it('picking "New conversation" closes the picker without pinning a pill', async () => {
render(<ChatDockFooter />, { wrapper: Wrapper });
fireEvent.click(screen.getByLabelText('Chat with Assistant'));
await waitFor(() => expect(screen.getByText('New conversation')).toBeInTheDocument());

fireEvent.click(screen.getByText('New conversation'));

expect(screen.queryByText('New conversation')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Close conversation')).not.toBeInTheDocument();
});

it('closing a pill via its × button removes it from the rail', async () => {
render(<ChatDockFooter />, { wrapper: Wrapper });
fireEvent.click(screen.getByLabelText('Chat with Assistant'));
await waitFor(() => expect(screen.getByText('Ghosted applications')).toBeInTheDocument());
fireEvent.click(screen.getByText('Ghosted applications'));
expect(screen.getByLabelText('Close conversation')).toBeInTheDocument();

fireEvent.click(screen.getByLabelText('Close conversation'));

expect(screen.queryByLabelText('Close conversation')).not.toBeInTheDocument();
});
});
Loading
Loading