import { expect, type Page, test } from '@playwright/test' async function useAdminSession (page: Page) { await page.addInitScript(() => { sessionStorage.setItem('bolts-session', JSON.stringify({ username: 'admin', role: 'admin', token: 'admin-token', })) }) } test('admin opens a user file and views a linked entity record', async ({ page }) => { await useAdminSession(page) await page.route('**/api/users', route => route.fulfill({ json: [{ id: 7, username: 'alex', role: 'user' }], })) await page.route('**/api/users/7/file', route => route.fulfill({ json: { user: { id: 7, username: 'alex', role: 'user' }, linkedEntities: [{ entity: { id: 3, name: 'Project', identifier: 'project', fields: [ { id: 11, name: 'Title', identifier: 'title', type: 'TEXT' }, { id: 12, name: 'Owner', identifier: 'owner', type: 'USER' }, ], }, records: [{ id: 42, title: 'Website refresh', owner: 7 }], }], }, })) await page.route('**/api/users/7/entities/3/records/42', route => route.fulfill({ json: { entity: { id: 3, name: 'Project', identifier: 'project', fields: [ { id: 11, name: 'Title', identifier: 'title', type: 'TEXT' }, { id: 12, name: 'Owner', identifier: 'owner', type: 'USER' }, ], }, values: { id: 42, title: 'Website refresh', owner: 7 }, }, })) await page.goto('/users') await page.getByRole('link', { name: 'alex' }).click() await expect(page.getByRole('heading', { name: 'alex' })).toBeVisible() await expect(page.getByRole('heading', { name: 'Project' })).toBeVisible() await expect(page.getByRole('row').filter({ hasText: 'Website refresh' })).toContainText('7') await page.getByRole('link', { name: 'View Project record 42' }).click() await expect(page.getByRole('heading', { name: 'Project #42' })).toBeVisible() await expect(page.getByText('Website refresh')).toBeVisible() await expect(page.getByText('Owner')).toBeVisible() })