teqo-backup/tests/unit/campaignLastActedMunicipality.unit.spec.ts
Cursor Agent dbf6a7fdce
B93 — wizard empty state continuity (visitados + última ação)
Merge client-side recent visits and last-acted municipality storage into
wizard municipality suggest idle list ahead of B92 server rankings.

- Add campaignLastActedMunicipality + wizardMunicipalitySuggestMerge libs
- Extend wizard-municipality-suggest with scopeMunicipalities for hit lookup
- Record last-acted on wizard write success (votes, signal, trend, leadership)
- Clear last-acted on logout alongside recent visits

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
2026-08-01 07:21:56 +00:00

36 lines
1.2 KiB
TypeScript

import { afterEach, describe, expect, it } from 'vitest'
import {
clearLastActedMunicipality,
getLastActedMunicipalitySlug,
LAST_ACTED_MUNICIPALITY_STORAGE_KEY,
recordLastActedMunicipality,
} from '@/lib/campaignLastActedMunicipality'
describe('campaignLastActedMunicipality storage', () => {
afterEach(() => {
localStorage.clear()
})
it('returns null when storage is missing or invalid', () => {
expect(getLastActedMunicipalitySlug()).toBeNull()
localStorage.setItem(LAST_ACTED_MUNICIPALITY_STORAGE_KEY, 'not-json')
expect(getLastActedMunicipalitySlug()).toBeNull()
localStorage.setItem(LAST_ACTED_MUNICIPALITY_STORAGE_KEY, JSON.stringify(''))
expect(getLastActedMunicipalitySlug()).toBeNull()
})
it('records and reads the last acted municipality slug', () => {
recordLastActedMunicipality('itabuna')
expect(getLastActedMunicipalitySlug()).toBe('itabuna')
recordLastActedMunicipality(' cairu ')
expect(getLastActedMunicipalitySlug()).toBe('cairu')
})
it('clears stored slug', () => {
recordLastActedMunicipality('valenca')
clearLastActedMunicipality()
expect(getLastActedMunicipalitySlug()).toBeNull()
expect(localStorage.getItem(LAST_ACTED_MUNICIPALITY_STORAGE_KEY)).toBeNull()
})
})