feat: polish speaker material upload control

This commit is contained in:
Lago committed 2026-10-07 19:58:00 +02:00
1 parent 8d8d3ae4b8
commit ef0121a3e4
6 files changed
+180 -10

No files matched your search

+89 -1
View File
@@ -14,6 +14,12 @@ function mockSession(email = '[email protected]') {
return { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test-signature`, refresh_token: 'mock-refresh-token', token_type: 'bearer', expires_in: 3600 };
}
function deferred() {
let resolve!: () => void;
const promise = new Promise<void>((done) => { resolve = done; });
return { promise, resolve };
}
async function mockApi(page: Page, talks: Record<string, unknown>[] = [], email = '[email protected]') {
const session = mockSession(email);
const calls = { users: 0, exchanges: 0, portal: 0, unexpected: [] as string[] };
@@ -147,6 +153,88 @@ test.describe('Speaker portal', () => {
expect(removed).toHaveLength(1);
});
test('material upload control keeps the native input accessible', async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
const { session } = await mockApi(page, [{ ...talk }]);
await page.goto(`${portalUrl}#access_token=${session.access_token}&refresh_token=${session.refresh_token}`);
const article = page.getByTestId(`speaker-talk-${talkId}`);
const upload = article.locator('.speaker-upload');
const input = article.getByLabel('Upload material for Past talk');
const box = await upload.boundingBox();
expect(box?.height).toBeGreaterThanOrEqual(44);
expect(box?.width).toBeGreaterThanOrEqual(44);
await expect(upload.locator('svg')).toBeVisible();
await expect(upload.getByText('Upload material', { exact: true })).toBeVisible();
await expect(input).toHaveAttribute('accept', '.pdf,.ppt,.pptx,.odp,.zip,.txt');
await expect(input).toHaveCSS('opacity', '0');
const inputBox = await input.boundingBox();
expect(inputBox?.height).toBeGreaterThanOrEqual(44);
await expect(input).toHaveAttribute('aria-describedby', `material-help-${talkId}`);
await expect(input).toHaveAccessibleDescription('PDF, PowerPoint, ODP, ZIP, TXT · Max 50 MB');
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await expect(input).toBeFocused();
await expect.poll(() => upload.evaluate((element) => getComputedStyle(element).outlineStyle)).toBe('solid');
const fileChooser = page.waitForEvent('filechooser');
await input.press('Enter');
await (await fileChooser).setFiles([]);
await expect.poll(() => input.evaluate((entry) => (entry as HTMLInputElement).value)).toBe('');
});
test('held storage request disables file inputs, reports failure and retries the same file', async ({ page }) => {
const otherTalk = { ...talk, session_id: '55555555-5555-4555-8555-555555555555', title: 'Second talk' };
const materialTalk = { ...talk };
const { session } = await mockApi(page, [materialTalk, otherTalk]);
const uploaded: string[] = [];
const removed: string[] = [];
const firstRpc = deferred();
const releaseFirstRpc = deferred();
let attempts = 0;
await page.route('**/rest/v1/sessions?**', (route) => route.fulfill({ json: { material_path: materialTalk.material_path } }));
await page.route('**/storage/v1/object/materials/**', async (route) => {
uploaded.push(decodeURIComponent(new URL(route.request().url()).pathname.split('/object/materials/')[1]));
await route.fulfill({ json: { Key: 'uploaded' } });
});
await page.route('**/storage/v1/object/materials', async (route) => {
removed.push(...route.request().postDataJSON().prefixes);
await route.fulfill({ json: [] });
});
await page.route('**/rest/v1/rpc/set_session_material', async (route) => {
attempts++;
const body = route.request().postDataJSON();
expect(body.p_session_id).toBe(talkId);
if (attempts === 1) {
firstRpc.resolve();
await releaseFirstRpc.promise;
await route.fulfill({ status: 403, json: { message: 'Assignment removed', code: '42501' } });
return;
}
materialTalk.material_path = body.p_material_path;
await route.fulfill({ json: { material_path: materialTalk.material_path } });
});
await page.goto(`${portalUrl}#access_token=${session.access_token}&refresh_token=${session.refresh_token}`);
const article = page.getByTestId(`speaker-talk-${talkId}`);
const input = article.getByLabel('Upload material for Past talk');
const slides = { name: 'slides.txt', mimeType: 'text/plain', buffer: Buffer.from('Slides') };
await input.setInputFiles(slides);
await firstRpc.promise;
await expect(article.locator('.speaker-upload')).toContainText('Saving material...');
await expect(article.getByRole('status')).toHaveText('Saving material...');
await expect(page.locator('input[type="file"]')).toHaveCount(2);
await expect.poll(() => page.locator('input[type="file"]').evaluateAll((inputs) => inputs.every((entry) => (entry as HTMLInputElement).disabled))).toBe(true);
releaseFirstRpc.resolve();
await expect(page.getByRole('alert')).toHaveText('Assignment removed');
await expect.poll(() => page.locator('input[type="file"]').evaluateAll((inputs) => inputs.every((entry) => !(entry as HTMLInputElement).disabled))).toBe(true);
await expect(input).toBeEnabled();
expect(removed).toHaveLength(1);
await expect.poll(() => input.evaluate((entry) => (entry as HTMLInputElement).value)).toBe('');
await input.setInputFiles(slides);
await expect.poll(() => uploaded.length).toBe(2);
await expect(article.getByRole('link', { name: 'Download material' })).toBeVisible();
await expect.poll(() => article.locator('input[type="file"]').evaluate((entry) => (entry as HTMLInputElement).value)).toBe('');
expect(attempts).toBe(2);
});
test('portal authentication does not bypass the normal app check-in gate', async ({ page }) => {
const { session } = await mockApi(page);
await page.goto(`${portalUrl}#access_token=${session.access_token}&refresh_token=${session.refresh_token}`);
@@ -232,4 +320,4 @@ test.describe('Speaker portal', () => {
expect(await page.evaluate(() => Object.keys(localStorage).filter((key) => key.endsWith('-auth-token')))).toEqual([]);
});
}
});
});