mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-26 21:53:06 +00:00
OH14 — fix offline e2e: ops-sync wait, local list search, vote-pledges registry, B27 POST wait
This commit is contained in:
parent
d6d3089f7d
commit
12f2d97f0a
4 changed files with 33 additions and 12 deletions
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import { createCollection, localOnlyCollectionOptions } from '@tanstack/db'
|
||||
import { createCollection, localOnlyCollectionOptions, type Transaction } from '@tanstack/db'
|
||||
import {
|
||||
IndexedDBAdapter,
|
||||
NonRetriableError,
|
||||
|
|
@ -19,6 +19,7 @@ import {
|
|||
applyOpsVotePledgeEstimateWrite,
|
||||
patchOpsVotePledgeEstimateOptimistic,
|
||||
readOpsVotePledge,
|
||||
votePledgesCollection,
|
||||
} from '@/components/campaign/opsSync/opsVotePledgeMirror'
|
||||
import { opsOutboxKey, type OpsOutboxKey } from '@/lib/campaignOps/opsContract'
|
||||
import {
|
||||
|
|
@ -28,6 +29,14 @@ import {
|
|||
|
||||
const ESTIMATE_MUTATION_FN = 'estimateVotes'
|
||||
|
||||
const outboxMutationRow = <TRow>(transaction: Transaction, collectionId: string): TRow => {
|
||||
const mutation = transaction.mutations.find((entry) => entry.collection?.id === collectionId)
|
||||
if (!mutation) {
|
||||
throw new NonRetriableError(`Mutação de outbox ausente (${collectionId}).`)
|
||||
}
|
||||
return mutation.modified as TRow
|
||||
}
|
||||
|
||||
const opsEstimateOutboxCollection = createCollection(
|
||||
localOnlyCollectionOptions<OpsEstimateOutboxRow, number>({
|
||||
id: 'ops-estimate-outbox',
|
||||
|
|
@ -40,17 +49,16 @@ let initPromise: Promise<OfflineExecutor> | null = null
|
|||
|
||||
const createEstimateOfflineExecutor = (): OfflineExecutor =>
|
||||
startOfflineExecutor({
|
||||
collections: { estimateOutbox: opsEstimateOutboxCollection },
|
||||
collections: {
|
||||
estimateOutbox: opsEstimateOutboxCollection,
|
||||
// Mirror rows touched in onMutate must be registered for persistence.
|
||||
votePledges: votePledgesCollection,
|
||||
},
|
||||
storage: new IndexedDBAdapter('teqo-ops-estimate', 'outbox'),
|
||||
beforeRetry: collapseEstimateOutboxByPledge,
|
||||
mutationFns: {
|
||||
[ESTIMATE_MUTATION_FN]: async ({ transaction }) => {
|
||||
const mutation = transaction.mutations[0]
|
||||
if (!mutation) {
|
||||
throw new NonRetriableError('Mutação de estimativa vazia.')
|
||||
}
|
||||
|
||||
const row = mutation.modified as OpsEstimateOutboxRow
|
||||
const row = outboxMutationRow<OpsEstimateOutboxRow>(transaction, 'ops-estimate-outbox')
|
||||
|
||||
try {
|
||||
const updated = await estimateVotesCas({
|
||||
|
|
|
|||
|
|
@ -163,7 +163,10 @@ test.describe('Municípios — jornadas por papel', () => {
|
|||
// no-op, so the probe retries until the chip sticks.
|
||||
await expect(async () => {
|
||||
await search.fill(searchNamePart)
|
||||
await option.click({ timeout: 1_000 })
|
||||
await Promise.all([
|
||||
expectPostResponse(page, '/campanha/municipios'),
|
||||
option.click({ timeout: 1_000 }),
|
||||
])
|
||||
await expect(chip).toBeVisible({ timeout: 4_000 })
|
||||
}).toPass({ timeout: 20_000 })
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
import { expect, test } from './fixtures/campaignE2EFixtures.js'
|
||||
|
||||
/** Offline specs intentionally hit blocked network resources — allowlist for the guard. */
|
||||
test.use({ expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'] })
|
||||
|
||||
/** OH6 — flaky-network outbox for estimateVotes. */
|
||||
test.describe('OH6 estimate outbox', () => {
|
||||
test('offline edit stays queued across reload and flushes when online', async ({
|
||||
|
|
@ -37,6 +40,12 @@ test.describe('OH6 estimate outbox', () => {
|
|||
await campaign.login(page, advisor.email!, advisor.password)
|
||||
await page.goto(`${campaign.baseURL}/campanha/municipios/${municipality.slug}`)
|
||||
|
||||
await page.waitForResponse(
|
||||
(response) =>
|
||||
response.url().includes('/campanha/api/ops-sync') && response.request().method() === 'GET',
|
||||
{ timeout: 30_000 },
|
||||
)
|
||||
|
||||
await page.context().setOffline(true)
|
||||
await page.getByLabel('Média', { exact: true }).fill('55')
|
||||
await page.getByLabel('Justificativa').fill('Editado na estrada.')
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
import { expect, test } from './fixtures/campaignE2EFixtures.js'
|
||||
|
||||
/** Offline specs intentionally hit blocked network resources — allowlist for the guard. */
|
||||
test.use({ expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'] })
|
||||
|
||||
/** OH9/OH11/OH12 — dual-path municipality detail + offline journey + list Local. */
|
||||
test.describe('OH9/OH11 campaign ops offline', () => {
|
||||
test('offline swaps to Local header + pledges with honest online-only placeholder', async ({
|
||||
|
|
@ -141,9 +144,7 @@ test.describe('OH12 municipality list Local', () => {
|
|||
)
|
||||
|
||||
await page.context().setOffline(true)
|
||||
await page.goto(
|
||||
`${campaign.baseURL}/campanha/municipios?q=${encodeURIComponent(municipality.name)}`,
|
||||
)
|
||||
await page.getByLabel('Buscar município').fill(municipality.name)
|
||||
|
||||
await expect(page.getByRole('heading', { name: 'Municípios' })).toBeVisible()
|
||||
await expect(
|
||||
|
|
|
|||
Loading…
Reference in a new issue