120 lines
4.1 KiB
TypeScript
120 lines
4.1 KiB
TypeScript
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 }) => {
|
|
let projectTitle = 'Website refresh'
|
|
const tasks: Record<string, unknown>[] = []
|
|
const projectResponse = () => ({
|
|
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: projectTitle, owner: 7 },
|
|
children: [{
|
|
entity: {
|
|
id: 4,
|
|
name: 'Task',
|
|
identifier: 'task',
|
|
fields: [
|
|
{ id: 20, name: 'Description', identifier: 'description', type: 'TEXT' },
|
|
{
|
|
id: 21,
|
|
name: 'Project',
|
|
identifier: 'project',
|
|
type: 'RELATIONSHIP',
|
|
targetEntityId: 3,
|
|
},
|
|
],
|
|
},
|
|
relationshipField: {
|
|
id: 21,
|
|
name: 'Project',
|
|
identifier: 'project',
|
|
type: 'RELATIONSHIP',
|
|
targetEntityId: 3,
|
|
},
|
|
records: tasks,
|
|
}],
|
|
})
|
|
|
|
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', async route => {
|
|
if (route.request().method() === 'PATCH') {
|
|
const values = new URLSearchParams(route.request().postData() ?? '')
|
|
projectTitle = values.get('title') ?? projectTitle
|
|
}
|
|
await route.fulfill({ json: projectResponse() })
|
|
})
|
|
await page.route('**/api/users/7/entities/3/records/42/children/4/21', async route => {
|
|
const values = new URLSearchParams(route.request().postData() ?? '')
|
|
const created = { id: 55, description: values.get('description'), project: 42 }
|
|
tasks.push(created)
|
|
await route.fulfill({
|
|
status: 201,
|
|
json: {
|
|
entity: projectResponse().children.at(0)!.entity,
|
|
values: created,
|
|
children: [],
|
|
},
|
|
})
|
|
})
|
|
|
|
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()
|
|
|
|
await page.getByRole('button', { name: 'Edit record' }).click()
|
|
const editForm = page.getByRole('form', { name: 'Edit record' })
|
|
await editForm.getByLabel('Title').fill('Mobile application')
|
|
await editForm.getByRole('button', { name: 'Save changes' }).click()
|
|
await expect(page.getByText('Mobile application')).toBeVisible()
|
|
|
|
await page.getByRole('button', { name: 'Add Task' }).click()
|
|
const childForm = page.getByRole('form', { name: 'Add Task' })
|
|
await childForm.getByLabel('Description').fill('Prepare launch')
|
|
await childForm.getByRole('button', { name: 'Add Task' }).click()
|
|
await expect(page.getByRole('row').filter({ hasText: 'Prepare launch' })).toContainText('42')
|
|
})
|