Files
nextcloud-server-mirror/tests/playwright/e2e/core/header-app-menu.spec.ts
Ferdinand Thiessen 5fd406c784 test(core): migrate end-to-end test to PlayWright
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2026-06-12 01:13:44 +02:00

81 lines
2.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { expect } from '@playwright/test'
import { test as userTest } from '../../support/fixtures/random-user-session.ts'
import { test as adminTest } from '../../support/fixtures/admin-session.ts'
import { NavigationHeaderPage } from '../../support/sections/NavigationHeaderPage.ts'
// Regular-user tests — logged in as a fresh random user.
userTest.describe('Header: App menu (waffle launcher) regular user', () => {
userTest('opens the popover and navigates when a tile is clicked', async ({ page }) => {
await page.goto('/')
const navigationHeader = new NavigationHeaderPage(page)
await navigationHeader.openMenu()
await expect(navigationHeader.popover()).toBeVisible()
const firstEntry = navigationHeader.navigationEntries().first()
await expect(firstEntry).toBeVisible()
const href = await firstEntry.getAttribute('href')
expect(href).toMatch(/\/apps\//)
await firstEntry.click()
await expect(page).toHaveURL(/\/apps\//)
})
userTest('has the correct app navigation items', async ({ page }) => {
await page.goto('/')
const navigationHeader = new NavigationHeaderPage(page)
await expectWaffleMenuContainsApps(navigationHeader, [
{ name: 'Files', href: '/apps/files' },
{ name: 'Dashboard', href: '/apps/dashboard' },
])
})
})
// Admin tests — logged in as the built-in admin user.
adminTest.describe('Header: App menu (waffle launcher) admin', () => {
adminTest('shows the "More apps" tile for admins', async ({ page }) => {
await page.goto('/')
const navigationHeader = new NavigationHeaderPage(page)
await navigationHeader.openMenu()
await expect(navigationHeader.popover()).toBeVisible()
await expect(navigationHeader.popover().getByRole('menuitem', { name: 'More apps' })).toBeVisible()
})
adminTest('has the correct app navigation items', async ({ page }) => {
await page.goto('/')
const navigationHeader = new NavigationHeaderPage(page)
await expectWaffleMenuContainsApps(navigationHeader, [
{ name: 'Files', href: '/apps/files' },
{ name: 'Dashboard', href: '/apps/dashboard' },
{ name: 'Appstore', href: '/settings/apps' },
])
})
})
/**
* Open the waffle menu and assert that each expected app is present
* with a matching name and href.
*/
async function expectWaffleMenuContainsApps(
navigationHeader: NavigationHeaderPage,
apps: Array<{ name: string; href: string }>,
): Promise<void> {
await navigationHeader.openMenu()
await expect(navigationHeader.popover()).toBeVisible()
for (const app of apps) {
const entry = navigationHeader.navigationEntries().filter({ hasText: app.name })
await expect(entry).toBeVisible()
const href = await entry.getAttribute('href')
// href may include a query string or a trailing slash
expect(href).toMatch(new RegExp(`${app.href}(\\?.+|/?$)`))
}
}