syncova-links/tests/acceptance.spec.js
jf 6253406d31
All checks were successful
Docker-Image veröffentlichen / publish (push) Successful in 49s
Use the published Docker image in Compose
2026-11-16 15:33:42 +01:00

269 lines
15 KiB
JavaScript

import { promisify } from 'node:util'
import { execFile } from 'node:child_process'
import { expect, test } from '@playwright/test'
import sharp from 'sharp'
const exec = promisify(execFile)
const password = process.env.SYNCOVA_TEST_PASSWORD
const project = process.env.SYNCOVA_TEST_PROJECT
const baseURL = process.env.SYNCOVA_TEST_URL
const envFile = process.env.SYNCOVA_TEST_ENV
const writeHeaders = { 'X-Syncova-Request': '1' }
test('Frischer Docker-Start, Verwaltung und persistente öffentliche Ansicht', async ({ page, browser, request }, info) => {
if (!/^syncova-test-[a-f0-9]{10}$/.test(project ?? '') || !password || !baseURL || !envFile) {
throw new Error('Bitte über npm run test:e2e starten.')
}
const guest = await browser.newContext({ baseURL, colorScheme: 'light', viewport: { width: 390, height: 844 } })
const publicPage = await guest.newPage()
const dialog = page.getByRole('dialog')
const button = (name) => page.getByRole('button', { name, exact: true })
const apply = () => dialog.getByRole('button', { name: 'Übernehmen', exact: true }).click()
async function createDepartment(name) {
await button('Abteilung anlegen').click()
await dialog.getByLabel('Name', { exact: true }).fill(name)
await dialog.getByRole('button', { name: 'Abteilung anlegen', exact: true }).click()
await expect(page.getByRole('heading', { name, exact: true })).toBeVisible()
}
async function checkEmpty(slug) {
await publicPage.goto('/' + slug + '?bearbeiten=1')
await expect(publicPage.locator('body')).toHaveText('Anmelden')
await expect(publicPage.getByRole('button', { name: 'Anmelden' })).toBeVisible()
}
async function group(name) {
await button('Gruppe').click()
await dialog.getByLabel('Gruppenname').fill(name)
await apply()
}
async function link(groupName, title, url) {
await button(`Link hinzufügen · ${groupName}`).click()
await dialog.getByLabel('Titel', { exact: true }).fill(title)
await dialog.getByLabel('URL', { exact: true }).fill(url)
}
async function isLoaded(image) {
await expect(image).toBeVisible()
await expect.poll(() => image.evaluate((element) => element.complete && element.naturalWidth > 0)).toBe(true)
}
async function denyWrites(id) {
for (const [method, path] of [
['POST', '/api/pages'], ['PUT', '/api/pages/' + id], ['DELETE', '/api/pages/' + id],
['POST', '/api/icons/upload'], ['POST', '/api/icons/favicon'],
]) {
expect((await request.fetch(path, { method, headers: writeHeaders, data: {} })).status()).toBe(401)
}
expect((await request.get('/api/admin/pages')).status()).toBe(401)
}
async function publicLayout(view) {
const selected = publicPage.getByRole('radio', { name: view, exact: true })
await expect(selected).toBeChecked()
await expect(publicPage.getByRole('radiogroup', { name: 'Ansicht' })).toHaveCSS('border-radius', '12px')
expect(await publicPage.locator('body').evaluate((body) => body.scrollWidth <= window.innerWidth)).toBe(true)
await expect(publicPage.locator('.page-content > *').locator('h2, .clock-zone')).toHaveText([
'Europe/Berlin', 'Werkzeuge', 'Dokumentation', 'Hinweise', 'UTC',
])
await expect(publicPage.getByRole('region', { name: 'Dokumentation' }).getByRole('link'))
.toHaveText(['Lokales Portal', 'Handbuch', 'Python'])
await expect(publicPage.getByText('Zugänge für den Arbeitsalltag.')).toBeVisible()
await expect(publicPage.locator('time')).toHaveCount(2)
for (const title of ['Handbuch', 'Python']) await isLoaded(publicPage.getByRole('link', { name: title }).locator('img'))
await expect(publicPage.getByRole('link', { name: 'Lokales Portal' }).locator('img')).toHaveCount(0)
await expect(publicPage.locator('[data-grip], [data-drop]')).toHaveCount(0)
}
await test.step('Systemeinstellung und manuelle Moduswahl', async () => {
await page.emulateMedia({ colorScheme: 'dark' })
await page.goto('/')
await expect(page.locator('body')).toHaveCSS('background-color', 'rgb(16, 22, 19)')
await page.emulateMedia({ colorScheme: 'light' })
await expect(page.locator('body')).toHaveCSS('background-color', 'rgb(246, 247, 242)')
await button('Dunkelmodus').press('Space')
await page.reload()
await expect(button('Dunkelmodus')).toHaveAttribute('aria-pressed', 'true')
await expect(page.locator('body')).toHaveCSS('background-color', 'rgb(16, 22, 19)')
})
await test.step('Öffentliche Startseite, Anmeldung und zwei leere Abteilungen', async () => {
await page.goto('/')
await expect(page.getByRole('heading', { name: 'Abteilungen', exact: true })).toBeVisible()
await expect(page.getByText('Noch keine Abteilungen')).toBeVisible()
await expect(button('Abteilung anlegen')).toHaveCount(0)
await button('Anmelden').click()
await expect(dialog).toHaveCSS('background-color', 'rgb(25, 33, 29)')
if (process.env.SYNCOVA_CAPTURE) await page.screenshot({ path: info.outputPath('anmeldung.png'), animations: 'disabled' })
await dialog.getByLabel('Benutzername').fill('abnahme')
await dialog.getByLabel('Passwort').fill(password)
await dialog.getByRole('button', { name: 'Anmelden', exact: true }).click()
await expect(button('Abteilung anlegen')).toBeVisible()
const cookies = await page.context().cookies()
expect(cookies).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'syncova_session', httpOnly: true, sameSite: 'Strict' })]))
await createDepartment('IT')
await checkEmpty('it')
await page.getByRole('link', { name: 'Abteilungen', exact: true }).click()
await createDepartment('Personal')
await checkEmpty('personal')
await publicPage.goto('/')
await expect(publicPage.getByRole('link', { name: 'IT', exact: true })).toHaveAttribute('href', '/it')
await expect(publicPage.getByRole('button', { name: /anlegen|löschen/i })).toHaveCount(0)
await expect(publicPage.getByRole('link', { name: 'Bearbeiten', exact: true })).toHaveCount(0)
await publicPage.getByRole('link', { name: 'Personal', exact: true }).click()
await expect(publicPage).toHaveURL(/\/personal$/)
await expect(publicPage.locator('body')).toHaveText('Anmelden')
await page.getByRole('link', { name: 'Abteilungen', exact: true }).click()
await expect(page.getByRole('heading', { name: 'Personal', exact: true })).toBeVisible()
if (process.env.SYNCOVA_CAPTURE) await page.screenshot({ path: info.outputPath('abteilungen.png') })
await page.locator('.department-card').filter({ has: page.getByRole('heading', { name: 'IT', exact: true }) })
.getByRole('link', { name: 'Bearbeiten' }).click()
await expect(page.locator('.editor-toolbar')).toHaveCSS('background-color', 'rgb(25, 33, 29)')
await button('Dunkelmodus').click()
await expect(page.locator('body')).toHaveCSS('background-color', 'rgb(246, 247, 242)')
})
await test.step('Gruppen, Links, Icon-Vorschauen und Widgets bearbeiten', async () => {
await group('Werkzeuge')
await group('Dokumentation')
await link('Werkzeuge', 'Handbuch', 'https://example.com/handbuch')
const png = await sharp({
create: { width: 24, height: 24, channels: 4, background: '#176449' },
}).png().toBuffer()
await dialog.locator('input[type="file"]').setInputFiles({ name: 'icon.png', mimeType: 'image/png', buffer: png })
await isLoaded(dialog.getByRole('img', { name: 'Icon-Vorschau' }))
const stagedUrl = await dialog.getByRole('img', { name: 'Icon-Vorschau' }).getAttribute('src')
expect((await request.get(stagedUrl)).status()).toBe(404)
await apply()
await link('Dokumentation', 'Python', 'https://www.python.org/')
await dialog.getByRole('button', { name: 'Favicon abrufen' }).click()
await isLoaded(dialog.getByRole('img', { name: 'Icon-Vorschau' }))
await apply()
await link('Dokumentation', 'Lokales Portal', 'http://127.0.0.1:3000/')
await dialog.getByRole('button', { name: 'Favicon abrufen' }).click()
await expect(dialog.getByRole('status')).toContainText('Kein verwendbares Favicon')
await expect(dialog.getByText('Standard-Icon', { exact: true })).toBeVisible()
await apply()
await button('Text-Widget').click()
await dialog.getByLabel('Überschrift (optional)', { exact: true }).fill('Hinweise')
await dialog.getByLabel('Text', { exact: true }).fill('Zugänge für den Arbeitsalltag.')
await apply()
await button('Uhrzeit-Widget').click()
await apply()
await button('Uhrzeit-Widget').click()
await dialog.getByLabel('Zeitzone', { exact: true }).fill('UTC')
await dialog.getByText('12 Stunden', { exact: true }).click()
await apply()
await expect(page.locator('time').last()).toHaveText(/(?:AM|PM)/i)
await checkEmpty('it')
})
await test.step('Drag-and-drop und Tastatur, Standardansicht und Speichern', async () => {
const grip = button('Handbuch verschieben')
const box = await grip.boundingBox()
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2)
await page.mouse.down()
await page.mouse.move(box.x + box.width / 2 + 14, box.y + box.height / 2 + 4, { steps: 5 })
const drop = button('Dokumentation · Vor Python ablegen')
await expect(drop).toBeVisible()
await drop.scrollIntoViewIfNeeded()
const target = await drop.boundingBox()
await page.mouse.move(target.x + target.width / 2, target.y + target.height / 2, { steps: 10 })
await page.mouse.move(target.x + target.width / 2 + 1, target.y + target.height / 2)
await expect(drop.locator('..')).toHaveAttribute('data-over', 'true')
await page.mouse.up()
await expect(page.getByRole('region', { name: 'Werkzeuge' }).getByText('Handbuch')).toHaveCount(0)
await expect(page.getByRole('region', { name: 'Dokumentation' }).getByText('Handbuch')).toBeVisible()
await button('Lokales Portal verschieben').focus()
await page.keyboard.press('Enter')
const beforeHandbuch = button('Dokumentation · Vor Handbuch ablegen')
await page.keyboard.press('ArrowDown')
await page.keyboard.press('ArrowDown')
await expect(beforeHandbuch).toBeFocused()
await page.keyboard.press('Enter')
await button('Uhrzeit · Europe/Berlin verschieben').focus()
await page.keyboard.press('Space')
await expect(button('Vor Werkzeuge ablegen')).toBeFocused()
await page.keyboard.press('Space')
await button('Seiteneinstellungen').click()
await dialog.getByText('Kacheln', { exact: true }).click()
await apply()
await button('Seite speichern').click()
await expect(page.getByText('Seite gespeichert.')).toBeVisible()
await expect(button('Seite speichern')).toBeDisabled()
expect((await page.request.post('/api/pages', { data: { name: 'Falsch', slug: 'falsch', view: 'list' } })).status()).toBe(403)
if (process.env.SYNCOVA_CAPTURE) await page.screenshot({ path: info.outputPath('bearbeitung.png'), fullPage: true })
})
const id = (await (await request.get('/api/pages/it')).json()).id
await test.step('Veröffentlichung, Ansichtswechsel, Abmeldung und Zugriffsschutz', async () => {
await publicPage.goto('/it')
await publicLayout('Kacheln')
const guestMode = publicPage.getByRole('button', { name: 'Dunkelmodus', exact: true })
await guestMode.click()
await expect(guestMode.locator('svg')).toBeVisible()
await expect(publicPage.locator('.choice [data-part="indicator"]')).toHaveCSS('background-color', 'rgb(23, 25, 24)')
await expect(publicPage.locator('.clock-widget').first()).toHaveCSS('background-color', 'rgb(35, 61, 47)')
if (process.env.SYNCOVA_CAPTURE) await publicPage.screenshot({ path: info.outputPath('kacheln.png'), fullPage: true })
const previous = await publicPage.locator('time').first().textContent()
await expect(publicPage.locator('time').first()).not.toHaveText(previous)
await publicPage.getByText('Liste', { exact: true }).click()
await publicLayout('Liste')
if (process.env.SYNCOVA_CAPTURE) await publicPage.screenshot({ path: info.outputPath('mobil.png'), fullPage: true })
await button('Abmelden').click()
await expect(button('Anmelden')).toBeVisible()
expect((await page.context().cookies()).some(({ name }) => name === 'syncova_session')).toBe(false)
await denyWrites(id)
})
await test.step('Neustart aus demselben Volume', async () => {
await exec('docker', ['compose', '--env-file', envFile, '-p', project,
'-f', 'compose.yaml', '-f', 'tests/compose.build.yaml', 'restart', 'links'], { timeout: 25_000 })
await expect.poll(async () => (await fetch(baseURL + '/healthz').catch(() => null))?.status).toBe(200)
await publicPage.goto('/it')
await publicLayout('Kacheln')
await checkEmpty('personal')
await denyWrites(id)
})
await test.step('Abteilung und Gruppe umbenennen, Gruppe und Abteilung löschen', async () => {
await page.goto('/personal')
await button('Anmelden').click()
await dialog.getByLabel('Benutzername').fill('abnahme')
await dialog.getByLabel('Passwort').fill(password)
await dialog.getByRole('button', { name: 'Anmelden', exact: true }).click()
await button('Seite bearbeiten').click()
await button('Seiteneinstellungen').click()
await dialog.getByLabel('Name', { exact: true }).fill('Personalservice')
await dialog.getByLabel('URL-Pfad', { exact: true }).fill('personalservice')
await apply()
await button('Seite speichern').click()
await expect(page).toHaveURL(/\/personalservice\?bearbeiten=1$/)
expect((await request.get('/api/pages/personal')).status()).toBe(404)
await checkEmpty('personalservice')
await publicPage.goto('/')
await expect(publicPage.getByRole('link', { name: 'Personalservice', exact: true })).toHaveAttribute('href', '/personalservice')
await expect(publicPage.getByRole('link', { name: 'Personal', exact: true })).toHaveCount(0)
await group('Anträge')
await button('Anträge bearbeiten').click()
await dialog.getByLabel('Gruppenname').fill('Formulare')
await apply()
await link('Formulare', 'Urlaubsantrag', 'https://example.com/urlaub')
await apply()
await button('Formulare löschen').click()
await dialog.getByRole('button', { name: 'Entfernen', exact: true }).click()
await expect(page.getByRole('region', { name: 'Ungruppierte Links' }).getByText('Urlaubsantrag')).toBeVisible()
await button('Seite speichern').click()
await expect(page.getByText('Seite gespeichert.')).toBeVisible()
await page.getByRole('link', { name: 'Abteilungen', exact: true }).click()
await button('Personalservice löschen').click()
await dialog.getByRole('button', { name: 'Abteilung löschen', exact: true }).click()
await expect(page.getByRole('heading', { name: 'Personalservice', exact: true })).toHaveCount(0)
expect((await request.get('/api/pages/personalservice')).status()).toBe(404)
await publicPage.goto('/')
await expect(publicPage.getByRole('link', { name: 'IT', exact: true })).toBeVisible()
await expect(publicPage.locator('.department-card')).toHaveCount(1)
})
await guest.close()
})