Files
payload/test/helpers/e2e/toggleNav.ts
Jarrod Flesch e5755110a9 fix(plugin-multi-tenant): selector could become hidden (#13134)
The selector could become hidden by:
- logging in with a user that only has 1 tenant
- logging out
- logging in with a user that has more than 1 tenant

Simplifies useEffect usage. Adds e2e test for this case.
2025-07-11 16:34:55 -04:00

27 lines
1.2 KiB
TypeScript

import type { Page } from '@playwright/test'
import { expect } from '@playwright/test'
export async function openNav(page: Page): Promise<void> {
// wait for the preferences/media queries to either open or close the nav
await expect(page.locator('.template-default--nav-hydrated')).toBeVisible()
// close all open modals
const dialogs = await page.locator('dialog[open]').elementHandles()
for (let i = 0; i < dialogs.length; i++) {
await page.keyboard.press('Escape')
}
// check to see if the nav is already open and if not, open it
// use the `--nav-open` modifier class to check if the nav is open
// this will prevent clicking nav links that are bleeding off the screen
if (await page.locator('.template-default.template-default--nav-open').isVisible()) {
return
}
// playwright: get first element with .nav-toggler which is VISIBLE (not hidden), could be 2 elements with .nav-toggler on mobile and desktop but only one is visible
await page.locator('.nav-toggler >> visible=true').click()
await expect(page.locator('.nav--nav-animate[inert], .nav--nav-hydrated[inert]')).toBeHidden()
await expect(page.locator('.template-default.template-default--nav-open')).toBeVisible()
}