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
5 changes: 5 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# Playwright
test-results/
playwright-report/
blob-report/
149 changes: 149 additions & 0 deletions frontend/e2e/desktop.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { expect, test, type Page } from '@playwright/test';
import {
citations,
realTrials,
seedReturningVisitor,
sendMessage,
shortTitle,
stubChat,
type WireTrial,
} from './support';

const summary = (page: Page) => page.locator('[data-tour="summary"]');
const mapPins = (page: Page) => page.getByRole('button', { name: /^\d+ trials? — / });
const contextChip = (page: Page) => page.getByRole('button', { name: /^Remove .+ from context$/ });

async function chatTurn(page: Page, trials: WireTrial[]) {
const sent = await stubChat(page, {
message: `Two trials may fit: [${trials[0].trial_ref}] and [${trials[1].trial_ref}].`,
trials,
followUps: ['What are the eligibility requirements?'],
});
await sendMessage(page, 'breast cancer trials in Toronto');
await expect(citations(page).first()).toBeVisible();
return sent;
}

test.beforeEach(async ({ page }) => {
await seedReturningVisitor(page);
await page.goto('/');
});

test('a chat turn cites trials, pins them on the map and opens one in the summary', async ({
page,
request,
}) => {
const trials = await realTrials(request, 2);
await chatTurn(page, trials);

await expect(citations(page)).toHaveCount(2);
await expect(page.getByRole('button', { name: 'Contact research team' }).first()).toBeVisible();
await expect(
page.getByRole('button', { name: 'What are the eligibility requirements?' })
).toBeVisible();
await expect(mapPins(page).first()).toBeVisible();
await expect(page.getByText('Trials will appear here as you chat.')).toHaveCount(0);

await citations(page).first().click();
await expect(summary(page).getByRole('heading', { level: 2 })).toBeVisible();
await expect(summary(page).getByText('Status')).toBeVisible();
await expect(summary(page).getByText('No trial selected')).toHaveCount(0);

await summary(page).getByRole('button', { name: 'Close' }).click();
await expect(summary(page).getByText('No trial selected')).toBeVisible();
});

test('a map pin lists its trials and opens the chosen one', async ({ page, request }) => {
const trials = await realTrials(request, 2);
await chatTurn(page, trials);

await mapPins(page).first().click();
const popup = page.locator('.trial-cluster-popup');
await expect(popup).toBeVisible();
await popup.getByRole('option').first().click();

await expect(summary(page).getByText('No trial selected')).toHaveCount(0);
await expect(summary(page).getByRole('heading', { level: 2 })).toBeVisible();
});

test('a trial added to the chat rides along with every message until removed', async ({
page,
request,
}) => {
const trials = await realTrials(request, 2);
const sent = await chatTurn(page, trials);

await citations(page).first().click();
await summary(page)
.getByRole('button', { name: /^Ask .+ about this trial$/ })
.click();
await expect(summary(page).getByRole('button', { name: 'Added to your chat' })).toBeDisabled();
await expect(contextChip(page)).toHaveCount(1);

await sendMessage(page, 'what are the side effects?');
await expect.poll(() => sent.length).toBe(2);
expect(sent[1]).toContain(trials[0].trial_ref);

const userMessage = page.locator('.is-user').filter({ hasText: 'what are the side effects?' });
await expect(userMessage.getByRole('button', { name: /^Show .+ on the map$/ })).toBeVisible();

await contextChip(page).click();
await expect(contextChip(page)).toHaveCount(0);
await sendMessage(page, 'anything else?');
await expect.poll(() => sent.length).toBe(3);
expect(sent[2]).not.toContain(trials[0].trial_ref);
});

test('a saved trial survives a new conversation and reopens onto the map and chat', async ({
page,
request,
}) => {
const trials = await realTrials(request, 2);
await chatTurn(page, trials);

await citations(page).first().click();
await summary(page).getByRole('button', { name: 'Save this trial' }).click();
await expect(
summary(page).getByRole('button', { name: 'Remove from saved trials' })
).toBeVisible();

await page.getByRole('button', { name: 'New conversation' }).click();
await expect(page.getByText('Trials will appear here as you chat.')).toBeVisible();
await expect(summary(page).getByText('No trial selected')).toBeVisible();

await page.getByRole('button', { name: 'Saved trials (1)' }).click();
const sheet = page.getByRole('dialog', { name: /Saved trials/ });
await sheet.getByText(shortTitle(trials[0])).click();

await expect(sheet).toBeHidden();
await expect(summary(page).getByText('No trial selected')).toHaveCount(0);
await expect(mapPins(page).first()).toBeVisible();
await expect(contextChip(page)).toHaveCount(1);
});

test('a saved trial exports as a PDF', async ({ page, request }) => {
const trials = await realTrials(request, 2);
await chatTurn(page, trials);
await citations(page).first().click();
await summary(page).getByRole('button', { name: 'Save this trial' }).click();

await page.getByRole('button', { name: 'Saved trials (1)' }).click();
const download = page.waitForEvent('download');
await page.getByRole('button', { name: 'Export all as PDF' }).click();

expect((await download).suggestedFilename()).toMatch(/\.pdf$/);
});

test('the contact dialog opens from the summary with live site data', async ({ page, request }) => {
const trials = await realTrials(request, 2);
await chatTurn(page, trials);
await citations(page).first().click();

await summary(page).getByRole('button', { name: 'Contact research team' }).click();
const dialog = page.getByRole('dialog', { name: 'Contact the research team' });
await expect(dialog).toBeVisible();
await expect(dialog.getByText('Talk to your own care team first')).toBeVisible();
await expect(
dialog.getByText('Contact details could not be loaded. Please try again.')
).toHaveCount(0);
});
20 changes: 20 additions & 0 deletions frontend/e2e/live.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect, test } from '@playwright/test';
import { citations, seedReturningVisitor, sendMessage } from './support';

// Calls the real agent (paid LLM tokens, slow, nondeterministic): run with E2E_LIVE=1.
test.skip(!process.env.E2E_LIVE, 'set E2E_LIVE=1 to exercise the real agent');

test('the real agent answers a search with cited trials', async ({ page }) => {
test.setTimeout(180_000);
await seedReturningVisitor(page);
await page.goto('/');
if ((page.viewportSize()?.width ?? 0) < 768)
await page.locator('[data-tour="mobile-search"]').click();

await sendMessage(
page,
'I am 54 with stage 3 breast cancer in Toronto. Are there recruiting trials for me?'
);

await expect(citations(page).first()).toBeVisible({ timeout: 150_000 });
});
135 changes: 135 additions & 0 deletions frontend/e2e/mobile.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { expect, test, type Page } from '@playwright/test';
import {
chatInput,
citations,
realTrials,
seedReturningVisitor,
sendMessage,
shortTitle,
stubChat,
type WireTrial,
} from './support';

const cards = (page: Page) => page.locator('[data-tour="mobile-cards"]');
const drawer = (page: Page) => page.locator('[data-tour="mobile-trial"]');
const contextChip = (page: Page) => page.getByRole('button', { name: /^Remove .+ from context$/ });

async function chatTurn(page: Page, trials: WireTrial[]) {
const sent = await stubChat(page, {
message: `Two trials may fit: [${trials[0].trial_ref}] and [${trials[1].trial_ref}].`,
trials,
title: 'Breast cancer trials in Toronto',
});
await page.locator('[data-tour="mobile-search"]').click();
await expect(chatInput(page)).toBeVisible();
await sendMessage(page, 'breast cancer trials in Toronto');
await expect(citations(page).first()).toBeVisible();
return sent;
}

test.beforeEach(async ({ page }) => {
await seedReturningVisitor(page);
await page.goto('/');
});

test('the phone opens on the map, and the search bar opens the chat', async ({ page }) => {
await expect(page.getByText('Trials will appear here as you chat.')).toBeVisible();
await expect(page.locator('[data-tour="mobile-search"]')).toHaveText(
'Tell me about your situation to find trials'
);

await page.locator('[data-tour="mobile-search"]').click();
await expect(chatInput(page)).toBeVisible();
await expect(page.getByText(/How can I help you today\?/)).toBeVisible();
});

test('a cited trial collapses the chat onto its card, which opens the details drawer', async ({
page,
request,
}) => {
const trials = await realTrials(request, 2);
await chatTurn(page, trials);
await expect(page.locator('[data-tour="mobile-search"]')).toHaveText(
'Breast cancer trials in Toronto'
);

await citations(page).first().click();
const selected = cards(page).locator('[data-selected="true"]');
await expect(selected).toBeVisible();
await expect(selected).toContainText(shortTitle(trials[0]));

await selected.click();
await expect(drawer(page)).toBeVisible();
await expect(
drawer(page).getByRole('heading', {
name: trials[0].official_title_en ?? shortTitle(trials[0]),
})
).toBeVisible();
await expect(drawer(page).getByText('Status')).toBeVisible();
});

test('asking about a trial from the drawer returns to the chat with it attached', async ({
page,
request,
}) => {
const trials = await realTrials(request, 2);
const sent = await chatTurn(page, trials);

await citations(page).first().click();
await cards(page).locator('[data-selected="true"]').click();
await drawer(page)
.getByRole('button', { name: /^Ask .+ about this trial$/ })
.click();

await expect(drawer(page)).toBeHidden();
await expect(contextChip(page)).toHaveCount(1);
await expect(chatInput(page)).toBeVisible();

await sendMessage(page, 'what are the side effects?');
await expect.poll(() => sent.length).toBe(2);
expect(sent[1]).toContain(trials[0].trial_ref);
});

test('a trial saved from the drawer shows up in the menu and the saved list', async ({
page,
request,
}) => {
const trials = await realTrials(request, 2);
await chatTurn(page, trials);

await citations(page).first().click();
await cards(page).locator('[data-selected="true"]').click();
await drawer(page).getByRole('button', { name: 'Save this trial' }).click();
await expect(
drawer(page).getByRole('button', { name: 'Remove from saved trials' })
).toBeVisible();
await drawer(page).getByRole('button', { name: 'Close' }).click();
await expect(drawer(page)).toBeHidden();

await page.getByRole('button', { name: 'Menu' }).click();
const savedRow = page.getByRole('button', { name: /^Saved trials/ });
await expect(savedRow).toContainText('1');
await savedRow.click();
await expect(
page.getByRole('dialog', { name: /Saved trials/ }).getByText(shortTitle(trials[0]))
).toBeVisible();
});

test('the map controls and legend sit level with each other, clear of the search bar', async ({
page,
request,
}) => {
const trials = await realTrials(request, 2);
await chatTurn(page, trials);
await citations(page).first().click();

const searchBar = await page.locator('[data-tour="mobile-search"]').boundingBox();
const zoom = await page.locator('.mapboxgl-ctrl-group').boundingBox();
const legend = await page.getByRole('list').filter({ hasText: 'Opening soon' }).boundingBox();
expect(searchBar && zoom && legend).toBeTruthy();
if (!searchBar || !zoom || !legend) return;

expect(zoom.y).toBeGreaterThan(searchBar.y + searchBar.height);
expect(Math.abs(legend.y + legend.height / 2 - (zoom.y + zoom.height / 2))).toBeLessThan(4);
await expect(page.getByRole('button', { name: 'Coverage area' })).toHaveCount(0);
});
Loading
Loading