mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-14 17:43:04 +00:00
131 lines
4.8 KiB
TypeScript
131 lines
4.8 KiB
TypeScript
import type { Page } from '@playwright/test'
|
|
|
|
import {
|
|
expect,
|
|
mockSollinhaChat,
|
|
test,
|
|
waitForRouterSettled,
|
|
} from './fixtures/campaignE2EFixtures.js'
|
|
|
|
const STAFF_DESKTOP_CHIPS = [
|
|
'Quem foi o deputado mais votado em Feira de Santana?',
|
|
'Quantos votos tivemos em Ilhéus em 2022?',
|
|
'Quais dobradinhas temos em Salvador?',
|
|
'Como está o município de Vitória da Conquista?',
|
|
]
|
|
|
|
const STAFF_MOBILE_CHIPS = STAFF_DESKTOP_CHIPS.slice(0, 3)
|
|
|
|
const LEADER_CHIPS = [
|
|
'O que você sabe fazer?',
|
|
'Me manda o link dos meus contatos',
|
|
'Me manda o link do meu perfil',
|
|
]
|
|
|
|
const chipButton = (page: Page, text: string) =>
|
|
page.getByRole('button', { name: text, exact: true })
|
|
|
|
/**
|
|
* The opening chips exist in the SSR HTML, so a click that lands BEFORE
|
|
* hydration is a silent no-op (the SSR button has no handler) — the B13/B17
|
|
* flake class. Retry until the send actually lands: a sent message empties the
|
|
* slot (`messages.length > 0` unmounts the chips), which is the one
|
|
* unambiguous observable.
|
|
*/
|
|
const pickChip = async (page: Page, text: string) => {
|
|
await expect(async () => {
|
|
await chipButton(page, text).click({ timeout: 1_000 })
|
|
await expect(chipButton(page, text)).toHaveCount(0, { timeout: 1_000 })
|
|
}).toPass({ timeout: 15_000 })
|
|
}
|
|
|
|
test.describe('B191 — ações rápidas de abertura no chat Sollinha (chips de pergunta)', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
test.slow()
|
|
await mockSollinhaChat(page, 'Resposta mockada da Sollinha.')
|
|
})
|
|
|
|
test('staff no desktop vê 4 chips; tocar envia a pergunta e os chips somem', async ({
|
|
page,
|
|
campaign,
|
|
}) => {
|
|
await page.setViewportSize({ width: 1280, height: 800 })
|
|
const user = await campaign.fixtures.createCampaignUser('coordinator', {
|
|
name: campaign.fixtures.value('Chips Coordenador'),
|
|
})
|
|
await campaign.login(page, user.email!, user.password)
|
|
await page.goto('/campanha')
|
|
|
|
// B203 — fresh desktop sessions start closed; open explicitly.
|
|
await waitForRouterSettled(page)
|
|
await page
|
|
.getByRole('button', { name: 'Sollinha — Assistente virtual' })
|
|
.filter({ visible: true })
|
|
.click()
|
|
await expect(page.getByText('Olá! Eu sou o Sollinha')).toBeVisible({ timeout: 20_000 })
|
|
for (const text of STAFF_DESKTOP_CHIPS) {
|
|
await expect(chipButton(page, text)).toBeVisible()
|
|
}
|
|
|
|
const firstChip = STAFF_DESKTOP_CHIPS[0]!
|
|
await pickChip(page, firstChip)
|
|
// The sent message is now in the conversation.
|
|
await expect(page.getByText(firstChip)).toBeVisible({ timeout: 20_000 })
|
|
for (const text of STAFF_DESKTOP_CHIPS) {
|
|
await expect(chipButton(page, text)).toHaveCount(0)
|
|
}
|
|
})
|
|
|
|
test('staff no drawer mobile vê 3 chips e eles somem após o envio', async ({
|
|
page,
|
|
campaign,
|
|
}) => {
|
|
await page.setViewportSize({ width: 500, height: 800 })
|
|
const user = await campaign.fixtures.createCampaignUser('advisor', {
|
|
name: campaign.fixtures.value('Chips Assessor'),
|
|
})
|
|
await campaign.login(page, user.email!, user.password)
|
|
await page.goto('/campanha')
|
|
|
|
const drawer = page.getByRole('dialog', { name: 'Sollinha — Assistente virtual' })
|
|
// OPS42 — dev-only settle before the click (see `waitForRouterSettled`).
|
|
await waitForRouterSettled(page)
|
|
await page.getByRole('button', { name: 'Sollinha — Assistente virtual' }).click()
|
|
await expect(drawer).toBeVisible({ timeout: 20_000 })
|
|
await expect(page.getByText('Olá! Eu sou o Sollinha')).toBeVisible({ timeout: 20_000 })
|
|
|
|
for (const text of STAFF_MOBILE_CHIPS) {
|
|
await expect(chipButton(page, text)).toBeVisible()
|
|
}
|
|
await expect(chipButton(page, STAFF_DESKTOP_CHIPS[3]!)).toHaveCount(0)
|
|
|
|
await pickChip(page, STAFF_MOBILE_CHIPS[0]!)
|
|
await expect(page.getByText(STAFF_MOBILE_CHIPS[0]!)).toBeVisible({ timeout: 20_000 })
|
|
for (const text of STAFF_MOBILE_CHIPS) {
|
|
await expect(chipButton(page, text)).toHaveCount(0)
|
|
}
|
|
})
|
|
|
|
test('leader vê o conjunto seguro — nunca uma pergunta eleitoral', async ({ page, campaign }) => {
|
|
await page.setViewportSize({ width: 1280, height: 800 })
|
|
const user = await campaign.fixtures.createCampaignUser('leader', {
|
|
name: campaign.fixtures.value('Chips Liderança'),
|
|
})
|
|
await campaign.login(page, user.email!, user.password)
|
|
await page.goto('/campanha')
|
|
|
|
// B203 — fresh desktop sessions start closed; open explicitly.
|
|
await waitForRouterSettled(page)
|
|
await page
|
|
.getByRole('button', { name: 'Sollinha — Assistente virtual' })
|
|
.filter({ visible: true })
|
|
.click()
|
|
await expect(page.getByText('Olá! Eu sou o Sollinha')).toBeVisible({ timeout: 20_000 })
|
|
for (const text of LEADER_CHIPS) {
|
|
await expect(chipButton(page, text)).toBeVisible()
|
|
}
|
|
for (const text of STAFF_DESKTOP_CHIPS) {
|
|
await expect(chipButton(page, text)).toHaveCount(0)
|
|
}
|
|
})
|
|
})
|