SPB Git

Repository Public

integration.spec.ts 3.1 KB 51 lines typescript

1// The lots meeting each other: explorer → share dialog → public page → viewer, and explorer → portal dialog.2import { expect, test, type Page } from '@playwright/test';3import { apiSignUp } from './helpers.ts';45test.use({ locale: 'fr-CA' });6const row = (page: Page, name: string) => page.locator(`[role=row][data-id]:has([data-name]:text-is("${name}"))`);7const menu = async (page: Page, name: string, action: string) => { await row(page, name).locator('[data-more]').click(); await page.getByRole('menuitem', { name: action, exact: true }).click(); };8const api = (page: Page, method: string, path: string, body?: unknown) => page.evaluate(async ([m, p, b]) => {9  const r = await fetch(`/api/v1${p}`, { method: m as string, headers: { 'X-SPD-CSRF': '1', 'Content-Type': 'application/json' }, body: b ? JSON.stringify(b) : m === 'GET' ? undefined : '{}' });10  return r.json();11}, [method, path, body] as const);1213test('share a file from the explorer, open the link anonymously, preview it; create a portal on a folder', async ({ context, page, browser }) => {14  await apiSignUp(context, page);15  const folder = await api(page, 'POST', '/folders', { parentId: 'root', name: 'Clients' });16  const text = 'Bonjour depuis SP Drive';17  await page.evaluate(async ([folderId, content]) => {18    const h = { 'X-SPD-CSRF': '1' };19    const data = new TextEncoder().encode(content);20    const u = await (await fetch('/api/v1/uploads', { method: 'POST', headers: { ...h, 'Content-Type': 'application/json' }, body: JSON.stringify({ folderId, name: 'note.txt', size: data.length }) })).json();21    await fetch(`/api/v1/uploads/${u.id}?offset=0`, { method: 'PATCH', headers: { ...h, 'Content-Type': 'application/octet-stream' }, body: data });22    await fetch(`/api/v1/uploads/${u.id}/complete`, { method: 'POST', headers: { ...h, 'Content-Type': 'application/json' }, body: '{}' });23  }, [folder.id, text] as const);24  await page.goto(`/folder/${folder.id}`);25  await expect(row(page, 'note.txt')).toBeVisible();2627  // explorer → share dialog28  await menu(page, 'note.txt', 'Partager');29  const dialog = page.getByRole('dialog').filter({ hasText: 'note.txt' });30  await expect(dialog).toBeVisible();31  await dialog.getByLabel('Libellé').fill('Intégration'); // a file with no link yet opens straight on the form32  await dialog.getByRole('button', { name: 'Créer un lien' }).click();33  const url = await dialog.getByTestId('link-once').getByRole('textbox', { name: 'Lien' }).inputValue();34  expect(url).toContain('/s/');3536  // anonymous visitor37  const visitor = await browser.newContext();38  const v = await visitor.newPage();39  await v.goto(new URL(url).pathname);40  await expect(v.getByText('note.txt').first()).toBeVisible();41  await v.getByRole('button', { name: 'Aperçu' }).first().click();42  await expect(v.getByRole('dialog').getByText(text)).toBeVisible();43  await visitor.close();4445  // explorer → portal dialog on a folder46  await page.keyboard.press('Escape'); await page.keyboard.press('Escape');47  await page.goto('/');48  await menu(page, 'Clients', 'Créer un portail de dépôt');49  await expect(page.getByRole('dialog', { name: 'Nouveau portail de dépôt' })).toBeVisible();50});51
Files main
Menu

Theme