teqo-backup/tests/e2e/campaignBottomNav.e2e.spec.ts
Francisco Solla eb94a81ebc fix(campaign): barra inferior mobile — folga no topo e rótulos sem sobreposição
B171 #443
- CampaignBottomNav: pt-2.5 no nav (respiro da borda superior) e rótulos
  text-[10px] nowrap com gap-1 — sem encolher a área de toque.
- e2e: assert paddingTop >= 8px, rótulos < 12px e sem sobreposição horizontal.
2026-08-08 18:37:12 -03:00

155 lines
6.3 KiB
TypeScript

import { expect, test } from './fixtures/campaignE2EFixtures.js'
test.use({ viewport: { width: 390, height: 844 } })
test.describe('Mobile bottom nav (B164)', () => {
test('staff sees five-item bottom nav', async ({ campaign, page }) => {
const { fixtures } = campaign
const coordinator = await fixtures.createCampaignUser('coordinator', {
name: fixtures.value('Coordenadora Nav'),
})
await campaign.login(page, coordinator.email!, coordinator.password)
await page.goto('/campanha')
const bottomNav = page.locator('[aria-label="Navegação principal"]')
await expect(bottomNav).toBeVisible()
await expect(bottomNav.getByRole('link', { name: 'Início' })).toBeVisible()
await expect(bottomNav.getByRole('link', { name: 'Municípios' })).toBeVisible()
await expect(bottomNav.getByRole('link', { name: 'Atualizações' })).toBeVisible()
await expect(bottomNav.getByRole('link', { name: 'Agenda' })).toBeVisible()
await expect(bottomNav.getByRole('button', { name: 'Mais' })).toBeVisible()
})
test('highlights active item and navigates on tap', async ({ campaign, page }) => {
const { fixtures } = campaign
const coordinator = await fixtures.createCampaignUser('coordinator', {
name: fixtures.value('Coordenadora Nav Ativa'),
})
await campaign.login(page, coordinator.email!, coordinator.password)
await page.goto('/campanha')
const bottomNav = page.locator('[aria-label="Navegação principal"]')
// Início is active on /campanha
await expect(bottomNav.getByRole('link', { name: 'Início' })).toHaveAttribute(
'aria-current',
'page',
)
// Navigate to Municípios — active state moves
await bottomNav.getByRole('link', { name: 'Municípios' }).click()
await expect(page).toHaveURL(/\/campanha\/municipios\/?$/)
await expect(bottomNav.getByRole('link', { name: 'Municípios' })).toHaveAttribute(
'aria-current',
'page',
)
await expect(bottomNav.getByRole('link', { name: 'Início' })).not.toHaveAttribute(
'aria-current',
'page',
)
})
test('Mais opens overflow drawer with secondary destinations', async ({ campaign, page }) => {
const { fixtures } = campaign
const coordinator = await fixtures.createCampaignUser('coordinator', {
name: fixtures.value('Coordenadora Drawer'),
})
await campaign.login(page, coordinator.email!, coordinator.password)
await page.goto('/campanha')
const bottomNav = page.locator('[aria-label="Navegação principal"]')
await bottomNav.getByRole('button', { name: 'Mais' }).click()
const drawer = page.locator('[data-slot="drawer-content"]')
await expect(drawer).toBeVisible()
await expect(drawer.getByRole('link', { name: 'Quadro', exact: true })).toBeVisible()
await expect(drawer.getByRole('link', { name: 'Conceitos' })).toBeVisible()
await expect(drawer.getByRole('link', { name: 'Perfil' })).toBeVisible()
await expect(drawer.getByRole('button', { name: 'Sair' })).toBeVisible()
})
test('leader does not see the bottom nav', async ({ campaign, page }) => {
const { fixtures } = campaign
const phone = fixtures.phone()
const leader = await fixtures.createCampaignUser('leader', {
name: fixtures.value('Líder Nav'),
username: phone,
})
await campaign.login(page, phone, leader.password)
await page.goto('/campanha/contatos')
await expect(page.locator('[aria-label="Navegação principal"]')).toHaveCount(0)
})
test('hidden on desktop viewport', async ({ campaign, page }) => {
const { fixtures } = campaign
const coordinator = await fixtures.createCampaignUser('coordinator', {
name: fixtures.value('Coordenadora Desktop'),
})
await campaign.login(page, coordinator.email!, coordinator.password)
await page.setViewportSize({ width: 1280, height: 800 })
await page.goto('/campanha')
// CSS-hidden, but still in DOM
await expect(page.locator('[aria-label="Navegação principal"]')).toBeHidden()
// Sidebar trigger is visible on desktop
await expect(page.getByRole('button', { name: /abrir ou fechar/i })).toBeVisible()
})
test('FAB sits above the bottom nav on mobile', async ({ campaign, page }) => {
const { fixtures } = campaign
const coordinator = await fixtures.createCampaignUser('coordinator', {
name: fixtures.value('Coordenadora FAB'),
})
await campaign.login(page, coordinator.email!, coordinator.password)
await page.goto('/campanha/municipios')
const fab = page.getByRole('button', { name: 'Ações rápidas' })
await expect(fab).toBeVisible()
await expect(page.locator('[aria-label="Navegação principal"]')).toBeVisible()
const fabBox = await fab.boundingBox()
const navBox = await (await page.locator('[aria-label="Navegação principal"]')).boundingBox()
if (fabBox && navBox) {
expect(fabBox.y).toBeLessThan(navBox.y)
}
})
test('items breathe below the top edge and labels never overlap (B171)', async ({
campaign,
page,
}) => {
const { fixtures } = campaign
const coordinator = await fixtures.createCampaignUser('coordinator', {
name: fixtures.value('Coordenadora Estilo'),
})
await campaign.login(page, coordinator.email!, coordinator.password)
await page.goto('/campanha')
const bottomNav = page.locator('[aria-label="Navegação principal"]')
await expect(bottomNav).toBeVisible()
// A small breathing gap between the item content and the bar's top border.
const paddingTop = await bottomNav.evaluate((el) => parseFloat(getComputedStyle(el).paddingTop))
expect(paddingTop).toBeGreaterThanOrEqual(8)
// Labels render smaller than the original text-xs (12px).
const labels = bottomNav.locator('a > span, button > span')
await expect(labels).toHaveCount(5)
const sizes = await labels.evaluateAll((els) =>
els.map((el) => parseFloat(getComputedStyle(el).fontSize)),
)
for (const fontSize of sizes) expect(fontSize).toBeLessThan(12)
// Adjacent labels must not overlap horizontally on a mobile viewport.
const boxes = await labels.evaluateAll((els) =>
els.map((el) => {
const rect = el.getBoundingClientRect()
return { left: rect.left, right: rect.right }
}),
)
for (let i = 1; i < boxes.length; i++) {
expect(boxes[i].left).toBeGreaterThanOrEqual(boxes[i - 1].right - 0.5)
}
})
})