Skip to content

Commit aeb54b6

Browse files
committed
test(core): add cypress tests to ensure navigation works
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 9c4a32f commit aeb54b6

1 file changed

Lines changed: 40 additions & 7 deletions

File tree

cypress/e2e/core/header_app-menu.cy.ts

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@ const getAppMenu = () => getNextcloudHeader().find('.app-menu')
1212
// the next-best stable selectors.
1313
const getWaffleTrigger = () => getAppMenu().find('.app-menu__waffle')
1414

15-
describe('Header: App menu (waffle launcher)', { testIsolation: true }, () => {
16-
beforeEach(() => {
17-
clearState()
18-
})
15+
before(clearState)
1916

20-
describe('Open and click', () => {
17+
describe('Header: App menu (waffle launcher)', { testIsolation: true }, () => {
18+
describe('Normal user', () => {
2119
beforeEach(() => {
2220
cy.createRandomUser().then(($user) => {
2321
cy.login($user)
2422
cy.visit('/')
2523
})
2624
})
2725

28-
it('opens the popover and navigates when a tile is clicked', () => {
26+
it('Open and click opens the popover and navigates when a tile is clicked', () => {
2927
getWaffleTrigger().click()
3028
cy.get('.app-menu__popover').should('be.visible')
3129
getWaffleTrigger().should('have.attr', 'aria-expanded', 'true')
@@ -39,9 +37,16 @@ describe('Header: App menu (waffle launcher)', { testIsolation: true }, () => {
3937
cy.location('pathname').should('include', '/apps/')
4038
})
4139
})
40+
41+
it('has all correct app navigation items', () => {
42+
waffleMenuShouldContainApps([
43+
{ name: 'Files', href: '/apps/files' },
44+
{ name: 'Dashboard', href: '/apps/dashboard' },
45+
])
46+
})
4247
})
4348

44-
describe('Admin gating: "More apps" tile', () => {
49+
describe('Admin', () => {
4550
const admin = new User('admin', 'admin')
4651

4752
beforeEach(() => {
@@ -54,5 +59,33 @@ describe('Header: App menu (waffle launcher)', { testIsolation: true }, () => {
5459
cy.get('.app-menu__popover').should('be.visible')
5560
cy.findByRole('menuitem', { name: 'More apps' }).should('be.visible')
5661
})
62+
63+
it('has all correct app navigation items', () => {
64+
waffleMenuShouldContainApps([
65+
{ name: 'Files', href: '/apps/files' },
66+
{ name: 'Dashboard', href: '/apps/dashboard' },
67+
{ name: 'Appstore', href: '/settings/apps' },
68+
])
69+
})
5770
})
5871
})
72+
73+
/**
74+
* Check that the waffle menu contains the given apps, by name and href.
75+
*
76+
* @param apps - The apps that should be present in the waffle menu, with their expected name and href.
77+
*/
78+
function waffleMenuShouldContainApps(apps: { name: string, href: string }[]) {
79+
getWaffleTrigger().click()
80+
getWaffleTrigger().should('have.attr', 'aria-expanded', 'true')
81+
cy.findByRole('menu', { name: 'Apps' }).should('be.visible')
82+
83+
cy.findAllByRole('menuitem')
84+
.then((items) => {
85+
apps.forEach((app) => {
86+
const item = items.toArray().find((i) => i.textContent?.includes(app.name))
87+
expect(item, `App menu should contain ${app.name}`).to.exist
88+
expect(item?.getAttribute('href')).to.match(new RegExp(`${app.href}(\\?.+|/?$)`))
89+
})
90+
})
91+
}

0 commit comments

Comments
 (0)