({
return {
search,
+ /**
+ * Raw box write with no debounce/navigation — used after a typeahead pick
+ * so the URL can keep the committed `q` while the input is ready for the
+ * next filter keyword.
+ */
+ setSearch,
onSearchChange,
/**
* What the active-filters summary should describe. The draft wins while the
diff --git a/src/utilities/municipality/municipalityMobileFilterCombobox.ts b/src/utilities/municipality/municipalityMobileFilterCombobox.ts
new file mode 100644
index 00000000..f4189b58
--- /dev/null
+++ b/src/utilities/municipality/municipalityMobileFilterCombobox.ts
@@ -0,0 +1,263 @@
+/**
+ * Pure option/chip catalog for the mobile municipality filter combobox (B120).
+ * URL contract stays in `municipalityListFilters` / `municipalityListUrl` (B18).
+ */
+import {
+ DEFAULT_VOTE_ESTIMATE_SCENARIO,
+ VOTE_ESTIMATE_SCENARIOS,
+ voteEstimateScenarioLabels,
+ type VoteEstimateScenario,
+} from '@/lib/voteEstimate'
+import { municipalityPriorityLabels } from '@/utilities/municipality/municipalityLabels'
+import {
+ getMunicipalityMultiFilterValues,
+ municipalityFilterDefinitions,
+ toggleMunicipalityExclusiveFilterValue,
+ toggleMunicipalityMultiFilterValue,
+ toggleMunicipalityPriorityFilter,
+ type MunicipalityFilterOption,
+ type MunicipalityMultiFilterParam,
+} from '@/utilities/municipality/municipalityListFilters'
+import {
+ municipalityListSortOptions,
+ resolveMunicipalityListSort,
+ serializeMunicipalitySortValue,
+ type MunicipalityListSortDirection,
+ type MunicipalityListSortKey,
+ type MunicipalityListState,
+} from '@/utilities/municipality/municipalityListUrl'
+
+export type MunicipalityMobileFilterChip = {
+ id: string
+ label: string
+}
+
+export type MunicipalityMobileFilterOption =
+ | {
+ id: string
+ kind: 'priority'
+ label: string
+ active: boolean
+ }
+ | {
+ id: string
+ kind: 'multi'
+ label: string
+ param: MunicipalityMultiFilterParam
+ value: string
+ active: boolean
+ }
+ | {
+ id: string
+ kind: 'coverage'
+ label: string
+ value: string
+ active: boolean
+ }
+ | {
+ id: string
+ kind: 'sort'
+ label: string
+ sort: MunicipalityListSortKey
+ dir: MunicipalityListSortDirection
+ active: boolean
+ }
+ | {
+ id: string
+ kind: 'scenario'
+ label: string
+ scenario: VoteEstimateScenario
+ active: boolean
+ }
+
+const dimensionLabel = (dimension: string, option: string): string => `${dimension} · ${option}`
+
+export type BuildMunicipalityMobileFilterOptionsArgs = {
+ state: MunicipalityListState
+ showStaffFilters: boolean
+ regionFilterOptions: MunicipalityFilterOption[]
+ advisorFilterOptions: MunicipalityFilterOption[]
+ /** Client-only estimate scenario (not in the URL). */
+ scenario: VoteEstimateScenario
+}
+
+export const buildMunicipalityMobileFilterOptions = ({
+ state,
+ showStaffFilters,
+ regionFilterOptions,
+ advisorFilterOptions,
+ scenario,
+}: BuildMunicipalityMobileFilterOptionsArgs): MunicipalityMobileFilterOption[] => {
+ const options: MunicipalityMobileFilterOption[] = []
+ const { sort: activeSort, dir: activeDir } = resolveMunicipalityListSort(state)
+
+ if (showStaffFilters) {
+ options.push({
+ id: 'priority:alta',
+ kind: 'priority',
+ label: dimensionLabel('Prioridade', municipalityPriorityLabels.alta),
+ active: state.priority === 'alta',
+ })
+ }
+
+ for (const definition of municipalityFilterDefinitions) {
+ if (definition.param === 'name') continue
+ if (definition.staffOnly && !showStaffFilters) continue
+
+ if (definition.selection === 'multi') {
+ let filterOptions = definition.options ?? []
+ if (definition.param === 'region') filterOptions = regionFilterOptions
+ if (definition.param === 'advisor') filterOptions = advisorFilterOptions
+ if (filterOptions.length === 0) continue
+
+ let param: MunicipalityMultiFilterParam
+ if (definition.param === 'region') param = 'region'
+ else if (definition.param === 'advisor') param = 'advisor'
+ else if (definition.param === 'trend') param = 'trend'
+ else if (definition.param === 'class') param = 'class'
+ else if (definition.param === 'level') param = 'level'
+ else continue // `name` skipped above; `coverage` is toggle-only
+
+ const selected = new Set(getMunicipalityMultiFilterValues(state, param))
+ for (const option of filterOptions) {
+ options.push({
+ id: `multi:${param}:${option.value}`,
+ kind: 'multi',
+ label: dimensionLabel(definition.label, option.label),
+ param,
+ value: option.value,
+ active: selected.has(option.value),
+ })
+ }
+ continue
+ }
+
+ if (definition.selection === 'toggle' && definition.param === 'coverage') {
+ for (const option of definition.options ?? []) {
+ options.push({
+ id: `coverage:${option.value}`,
+ kind: 'coverage',
+ label: dimensionLabel(definition.label, option.label),
+ value: option.value,
+ active: state.coverage === option.value,
+ })
+ }
+ }
+ }
+
+ for (const sortOption of municipalityListSortOptions) {
+ const value = serializeMunicipalitySortValue(sortOption.key, sortOption.dir)
+ options.push({
+ id: `sort:${value}`,
+ kind: 'sort',
+ label: dimensionLabel('Ordenar', sortOption.label),
+ sort: sortOption.key,
+ dir: sortOption.dir,
+ active: sortOption.key === activeSort && sortOption.dir === activeDir,
+ })
+ }
+
+ if (showStaffFilters) {
+ for (const estimateScenario of VOTE_ESTIMATE_SCENARIOS) {
+ options.push({
+ id: `scenario:${estimateScenario}`,
+ kind: 'scenario',
+ label: dimensionLabel('Cenário', voteEstimateScenarioLabels[estimateScenario]),
+ scenario: estimateScenario,
+ active: scenario === estimateScenario,
+ })
+ }
+ }
+
+ return options
+}
+
+/**
+ * Active filter chips. Sort only when the URL overrides the default (B18 drops
+ * the default from the query); scenario only when not central.
+ */
+export const buildMunicipalityMobileFilterChips = (
+ state: MunicipalityListState,
+ options: readonly MunicipalityMobileFilterOption[],
+): MunicipalityMobileFilterChip[] => {
+ const chips: MunicipalityMobileFilterChip[] = []
+ let sortChip: MunicipalityMobileFilterChip | null = null
+ let scenarioChip: MunicipalityMobileFilterChip | null = null
+ const sortOverridden = state.sort !== undefined || state.dir !== undefined
+
+ for (const option of options) {
+ if (!option.active) continue
+ if (option.kind === 'sort') {
+ if (sortOverridden) sortChip = { id: option.id, label: option.label }
+ continue
+ }
+ if (option.kind === 'scenario') {
+ if (option.scenario !== DEFAULT_VOTE_ESTIMATE_SCENARIO) {
+ scenarioChip = { id: option.id, label: option.label }
+ }
+ continue
+ }
+ chips.push({ id: option.id, label: option.label })
+ }
+
+ if (sortChip) chips.push(sortChip)
+ if (scenarioChip) chips.push(scenarioChip)
+ return chips
+}
+
+/** Chip dismiss: filters toggle off; sort/scenario reset to defaults. */
+export const dismissMunicipalityMobileFilterChip = (
+ state: MunicipalityListState,
+ option: MunicipalityMobileFilterOption,
+): MunicipalityListState | 'scenario-default' => {
+ switch (option.kind) {
+ case 'sort':
+ return { ...state, page: 1, sort: undefined, dir: undefined }
+ case 'scenario':
+ return 'scenario-default'
+ case 'priority':
+ case 'multi':
+ case 'coverage': {
+ const next = applyMunicipalityMobileFilterOption(state, option)
+ if (next === 'scenario') {
+ throw new Error(`Unexpected scenario result for ${option.kind}`)
+ }
+ return next
+ }
+ default: {
+ const _exhaustive: never = option
+ return _exhaustive
+ }
+ }
+}
+
+/**
+ * Applies a typeahead pick (or chip dismiss) to list state. Scenario is not
+ * URL-backed — callers handle it via the estimate-scenario context.
+ */
+export const applyMunicipalityMobileFilterOption = (
+ state: MunicipalityListState,
+ option: MunicipalityMobileFilterOption,
+): MunicipalityListState | 'scenario' => {
+ switch (option.kind) {
+ case 'priority':
+ return toggleMunicipalityPriorityFilter(state)
+ case 'multi':
+ return toggleMunicipalityMultiFilterValue(state, option.param, option.value)
+ case 'coverage':
+ return toggleMunicipalityExclusiveFilterValue(state, 'coverage', option.value)
+ case 'sort':
+ return { ...state, page: 1, sort: option.sort, dir: option.dir }
+ case 'scenario':
+ return 'scenario'
+ default: {
+ const _exhaustive: never = option
+ return _exhaustive
+ }
+ }
+}
+
+export const findMunicipalityMobileFilterOption = (
+ options: readonly MunicipalityMobileFilterOption[],
+ id: string,
+): MunicipalityMobileFilterOption | undefined => options.find((option) => option.id === id)
diff --git a/tests/e2e/campaignMunicipalities.e2e.spec.ts b/tests/e2e/campaignMunicipalities.e2e.spec.ts
index 95649626..d6756add 100644
--- a/tests/e2e/campaignMunicipalities.e2e.spec.ts
+++ b/tests/e2e/campaignMunicipalities.e2e.spec.ts
@@ -54,9 +54,14 @@ test.describe('Municípios — list header mobile (B118)', () => {
await expect(heading).toHaveClass(/sr-only/)
const headingBox = await heading.boundingBox()
expect(headingBox?.height ?? 0).toBeLessThanOrEqual(2)
- await expect(page.locator('header p')).toBeHidden()
+ // Scope to the list page header (description is `hidden md:block`); avoid
+ // strict-mode flakes if React mounts more than one matching ``.
+ const pageHeader = page.locator('header').filter({ has: heading })
+ await expect(pageHeader.locator('p')).toBeHidden()
await expect(page.locator('[data-scope="campaign"]')).toBeHidden()
- await expect(page.getByLabel('Buscar município')).toBeVisible()
+ // B120: mobile uses the filter combobox; desktop search stays md+ only.
+ await expect(page.getByLabel('Filtrar municípios')).toBeVisible()
+ await expect(page.getByLabel('Buscar município')).toBeHidden()
await expect(page.getByText(/\d+ municípios encontrados/)).toBeVisible()
})
})
@@ -440,15 +445,11 @@ test.describe('Municípios — cards no celular (B42)', () => {
// Anywhere outside a control is the município's own link: the click lands on
// the stretched `after:inset-0` overlay, which belongs to the card heading.
- // The tap goes on a field LABEL inside the metrics grid on purpose — the
- // first version of this card positioned each grid cell instead of each
- // control, which lifted the labels and their padding above the overlay and
- // made half the card a tap that neither edited nor navigated.
- // `force`: Playwright's hit-target check retries forever here precisely
- // BECAUSE the stretched overlay intercepts the pointer — which is the
- // behavior under test. Force dispatches the tap at the label's point, the
- // overlay receives it (as a user's finger would), and the card navigates.
- await card.getByText('Tendência', { exact: true }).click({ force: true })
+ // B120 densified the card (no "Tendência" dt label). Do NOT tap the territory
+ // line — `TerritoryLink` is `relative` above the overlay on purpose. Tap the
+ // heading text; `force` because Playwright's hit-target check retries forever
+ // when the overlay intercepts — which is the behavior under test.
+ await card.getByRole('heading', { name: municipality.name }).click({ force: true })
await expect(page).toHaveURL(`${campaign.baseURL}/campanha/municipios/${municipality.slug}`)
await expect(page.getByRole('heading', { name: municipality.name })).toBeVisible()
})
diff --git a/tests/unit/campaignListFilterNavigation.unit.spec.ts b/tests/unit/campaignListFilterNavigation.unit.spec.ts
index 9788ca91..3cb4e49a 100644
--- a/tests/unit/campaignListFilterNavigation.unit.spec.ts
+++ b/tests/unit/campaignListFilterNavigation.unit.spec.ts
@@ -34,14 +34,36 @@ type FilterCase = {
/**
* A `key|dir` from the list's own sort options that is NOT its default —
* otherwise `sort=` drops out of the canonical href and the assertion fails
- * for a reason unrelated to the hook.
+ * for a reason unrelated to the hook. Used by shells that still expose
+ * NativeSelect "Ordenar"; municípios (B120) use `navigateSecondary` instead.
*/
sortValue: string
+ /** Href after secondary nav with `q=silva` carried. */
+ hrefWithQueryAndSecondary: string
+ /** Href after secondary nav with no query. */
+ hrefWithSecondary: string
+ /**
+ * Non-search control that navigates. Default: change NativeSelect "Ordenar".
+ * Municípios: pick a combobox filter option (sort NativeSelect removed in B120).
+ */
+ navigateSecondary: (filterCase: FilterCase) => void
element: (currentQuery?: string) => ReactElement
/** Same shell with `sortValue` already committed — an external navigation. */
elementWithSort: () => ReactElement
}
+const navigateViaSortSelect = (filterCase: FilterCase) => {
+ fireEvent.change(screen.getByLabelText('Ordenar'), { target: { value: filterCase.sortValue } })
+}
+
+const navigateViaMunicipalityPriorityOption = () => {
+ const combobox = screen.getByRole('combobox', { name: 'Filtrar municípios' })
+ fireEvent.focus(combobox)
+ // Open the list and land on the first staff option (Prioridade · Prioritária).
+ fireEvent.keyDown(combobox, { key: 'ArrowDown' })
+ fireEvent.keyDown(combobox, { key: 'Enter' })
+}
+
const filterCases: FilterCase[] = [
{
name: 'dobradinhas',
@@ -49,6 +71,9 @@ const filterCases: FilterCase[] = [
hrefWithQuery: '/campanha/dobradinhas?q=silva',
bareHref: '/campanha/dobradinhas',
sortValue: 'party|asc',
+ hrefWithQueryAndSecondary: '/campanha/dobradinhas?q=silva&sort=party',
+ hrefWithSecondary: '/campanha/dobradinhas?sort=party',
+ navigateSecondary: navigateViaSortSelect,
element: (currentQuery) =>
createElement(StateDeputyFilters, {
state: { page: 1, ...(currentQuery ? { q: currentQuery } : {}) },
@@ -68,6 +93,9 @@ const filterCases: FilterCase[] = [
hrefWithQuery: '/campanha/territorios?q=silva',
bareHref: '/campanha/territorios',
sortValue: 'region|asc',
+ hrefWithQueryAndSecondary: '/campanha/territorios?q=silva&sort=region',
+ hrefWithSecondary: '/campanha/territorios?sort=region',
+ navigateSecondary: navigateViaSortSelect,
element: (currentQuery) =>
createElement(TerritoryFilters, {
state: { page: 1, ...(currentQuery ? { q: currentQuery } : {}) },
@@ -85,6 +113,9 @@ const filterCases: FilterCase[] = [
hrefWithQuery: '/campanha/municipios?q=silva',
bareHref: '/campanha/municipios',
sortValue: 'name|asc',
+ hrefWithQueryAndSecondary: '/campanha/municipios?priority=alta',
+ hrefWithSecondary: '/campanha/municipios?priority=alta',
+ navigateSecondary: navigateViaMunicipalityPriorityOption,
element: (currentQuery) =>
createElement(
MunicipalityEstimateScenarioProvider,
@@ -135,10 +166,10 @@ const searchInput = (label: string) => screen.getByLabelText(label) as HTMLInput
/**
* `dir` never appears in these: every `sortValue` here is an `asc` key, which is
* each list's default direction, so the canonical serializer drops it.
+ * Municípios secondary is priority (B120 combobox), not sort — see
+ * `hrefWithQueryAndSecondary`.
*/
const sortKeyOf = ({ sortValue }: FilterCase) => sortValue.split('|')[0]
-const hrefWithSort = (filterCase: FilterCase) =>
- `${filterCase.bareHref}?sort=${sortKeyOf(filterCase)}`
const hrefWithQueryAndSort = (filterCase: FilterCase) =>
`${filterCase.bareHref}?q=silva&sort=${sortKeyOf(filterCase)}`
@@ -235,18 +266,27 @@ describe('campaign list filter navigation', () => {
it.each(filterCases)(
'$name: carries the uncommitted search when another control navigates',
(filterCase) => {
- const { searchLabel, sortValue } = filterCase
+ const { searchLabel, navigateSecondary, hrefWithQueryAndSecondary, name } = filterCase
mountCase(filterCase)
typeSearch(searchLabel, 'silva')
- fireEvent.change(screen.getByLabelText('Ordenar'), { target: { value: sortValue } })
+ navigateSecondary(filterCase)
expect(routerState.replace).toHaveBeenCalledTimes(1)
- expect(routerState.replace).toHaveBeenCalledWith(hrefWithQueryAndSort(filterCase), {
+ expect(routerState.replace).toHaveBeenCalledWith(hrefWithQueryAndSecondary, {
scroll: false,
})
- // The sort consumed the pending search; the timer must not fire a second one.
+ // Municípios B120: a combobox pick must NOT commit the typeahead draft as
+ // `q` (prefix text ≠ município name). Other shells still carry the draft.
+ if (name !== 'municípios') {
+ expect(hrefWithQueryAndSecondary).toContain('q=silva')
+ } else {
+ expect(hrefWithQueryAndSecondary).not.toContain('q=')
+ }
+
+ // The secondary control consumed the pending search; the timer must not
+ // fire a second navigation.
advance(SEARCH_DEBOUNCE_MS)
expect(routerState.replace).toHaveBeenCalledTimes(1)
},
@@ -287,7 +327,7 @@ describe('campaign list filter navigation', () => {
it.each(filterCases)(
'$name: follows the URL when the committed query is dropped from outside the shell',
(filterCase) => {
- const { searchLabel, element } = filterCase
+ const { searchLabel, element, navigateSecondary, hrefWithSecondary } = filterCase
const { rerenderWith } = mountCase(filterCase, 'silva')
// The empty state's "Limpar busca e filtros" is an anchor: it drops `q`
@@ -296,10 +336,8 @@ describe('campaign list filter navigation', () => {
expect(searchInput(searchLabel).value).toBe('')
// The box must not put the dropped query back on the next filter touch.
- fireEvent.change(screen.getByLabelText('Ordenar'), {
- target: { value: filterCase.sortValue },
- })
- expect(routerState.replace).toHaveBeenCalledWith(hrefWithSort(filterCase), { scroll: false })
+ navigateSecondary(filterCase)
+ expect(routerState.replace).toHaveBeenCalledWith(hrefWithSecondary, { scroll: false })
},
)
diff --git a/tests/unit/municipalityMobileFilterCombobox.unit.spec.ts b/tests/unit/municipalityMobileFilterCombobox.unit.spec.ts
new file mode 100644
index 00000000..75f1a29c
--- /dev/null
+++ b/tests/unit/municipalityMobileFilterCombobox.unit.spec.ts
@@ -0,0 +1,143 @@
+import { describe, expect, it } from 'vitest'
+
+import { DEFAULT_VOTE_ESTIMATE_SCENARIO } from '@/lib/voteEstimate'
+import { buildMunicipalityFilterHref } from '@/utilities/municipality/municipalityListFilters'
+import type { MunicipalityListState } from '@/utilities/municipality/municipalityListUrl'
+import {
+ applyMunicipalityMobileFilterOption,
+ buildMunicipalityMobileFilterChips,
+ buildMunicipalityMobileFilterOptions,
+ dismissMunicipalityMobileFilterChip,
+ findMunicipalityMobileFilterOption,
+} from '@/utilities/municipality/municipalityMobileFilterCombobox'
+
+const baseState = (): MunicipalityListState => ({ page: 1 })
+
+describe('municipalityMobileFilterCombobox', () => {
+ it('builds staff options including priority, coverage, sort and scenario', () => {
+ const options = buildMunicipalityMobileFilterOptions({
+ state: baseState(),
+ showStaffFilters: true,
+ regionFilterOptions: [{ value: 'Sertão Produtivo', label: 'Sertão Produtivo' }],
+ advisorFilterOptions: [{ value: '12', label: 'Ana' }],
+ scenario: DEFAULT_VOTE_ESTIMATE_SCENARIO,
+ })
+
+ expect(options.some((option) => option.id === 'priority:alta')).toBe(true)
+ expect(options.some((option) => option.id === 'coverage:sem_assessor')).toBe(true)
+ expect(options.some((option) => option.id === 'multi:region:Sertão Produtivo')).toBe(true)
+ expect(options.some((option) => option.id === 'multi:advisor:12')).toBe(true)
+ expect(options.some((option) => option.kind === 'sort')).toBe(true)
+ expect(options.some((option) => option.id === 'scenario:pessimistic')).toBe(true)
+ })
+
+ it('hides staff-only options when showStaffFilters is false', () => {
+ const options = buildMunicipalityMobileFilterOptions({
+ state: baseState(),
+ showStaffFilters: false,
+ regionFilterOptions: [{ value: 'Sertão Produtivo', label: 'Sertão Produtivo' }],
+ advisorFilterOptions: [{ value: '12', label: 'Ana' }],
+ scenario: 'optimistic',
+ })
+
+ expect(options.some((option) => option.kind === 'priority')).toBe(false)
+ expect(options.some((option) => option.kind === 'coverage')).toBe(false)
+ expect(options.some((option) => option.kind === 'scenario')).toBe(false)
+ expect(options.some((option) => option.id === 'multi:advisor:12')).toBe(false)
+ expect(options.some((option) => option.id === 'multi:region:Sertão Produtivo')).toBe(true)
+ })
+
+ it('empty dimension stays absent from chips and URL (OR-within / AND-across)', () => {
+ const state = baseState()
+ const options = buildMunicipalityMobileFilterOptions({
+ state,
+ showStaffFilters: true,
+ regionFilterOptions: [{ value: 'Sertão Produtivo', label: 'Sertão Produtivo' }],
+ advisorFilterOptions: [],
+ scenario: DEFAULT_VOTE_ESTIMATE_SCENARIO,
+ })
+ expect(buildMunicipalityMobileFilterChips(state, options)).toEqual([])
+ expect(buildMunicipalityFilterHref(state)).toBe('/campanha/municipios')
+ })
+
+ it('round-trips chips through URL helpers without inventing a new encoding', () => {
+ let state = baseState()
+ const catalog = () =>
+ buildMunicipalityMobileFilterOptions({
+ state,
+ showStaffFilters: true,
+ regionFilterOptions: [
+ { value: 'Sertão Produtivo', label: 'Sertão Produtivo' },
+ { value: 'Recôncavo', label: 'Recôncavo' },
+ ],
+ advisorFilterOptions: [],
+ scenario: DEFAULT_VOTE_ESTIMATE_SCENARIO,
+ })
+
+ const priority = findMunicipalityMobileFilterOption(catalog(), 'priority:alta')
+ expect(priority).toBeDefined()
+ state = applyMunicipalityMobileFilterOption(state, priority!) as MunicipalityListState
+
+ const region = findMunicipalityMobileFilterOption(catalog(), 'multi:region:Sertão Produtivo')
+ expect(region).toBeDefined()
+ state = applyMunicipalityMobileFilterOption(state, region!) as MunicipalityListState
+
+ const coverage = findMunicipalityMobileFilterOption(catalog(), 'coverage:sem_assessor')
+ expect(coverage).toBeDefined()
+ state = applyMunicipalityMobileFilterOption(state, coverage!) as MunicipalityListState
+
+ const href = buildMunicipalityFilterHref(state)
+ expect(href).toContain('priority=alta')
+ expect(href).toContain('region=')
+ expect(href).toContain('coverage=sem_assessor')
+ expect(href).not.toContain('is:')
+
+ const chips = buildMunicipalityMobileFilterChips(state, catalog())
+ expect(chips.map((chip) => chip.id)).toEqual(
+ expect.arrayContaining([
+ 'priority:alta',
+ 'multi:region:Sertão Produtivo',
+ 'coverage:sem_assessor',
+ ]),
+ )
+
+ const dismiss = findMunicipalityMobileFilterOption(catalog(), 'multi:region:Sertão Produtivo')!
+ state = dismissMunicipalityMobileFilterChip(state, dismiss) as MunicipalityListState
+ expect(state.regions).toBeUndefined()
+ expect(buildMunicipalityFilterHref(state)).not.toContain('region=')
+ })
+
+ it('sort chip only when URL overrides default; dismiss clears sort', () => {
+ let state: MunicipalityListState = { page: 1, sort: 'name', dir: 'asc' }
+ const options = buildMunicipalityMobileFilterOptions({
+ state,
+ showStaffFilters: false,
+ regionFilterOptions: [],
+ advisorFilterOptions: [],
+ scenario: DEFAULT_VOTE_ESTIMATE_SCENARIO,
+ })
+ const chips = buildMunicipalityMobileFilterChips(state, options)
+ expect(chips.some((chip) => chip.id.startsWith('sort:'))).toBe(true)
+
+ const sortChip = findMunicipalityMobileFilterOption(
+ options,
+ chips.find((c) => c.id.startsWith('sort:'))!.id,
+ )!
+ state = dismissMunicipalityMobileFilterChip(state, sortChip) as MunicipalityListState
+ expect(state.sort).toBeUndefined()
+ expect(state.dir).toBeUndefined()
+ })
+
+ it('scenario option does not mutate list state (client context owns it)', () => {
+ const state = baseState()
+ const options = buildMunicipalityMobileFilterOptions({
+ state,
+ showStaffFilters: true,
+ regionFilterOptions: [],
+ advisorFilterOptions: [],
+ scenario: DEFAULT_VOTE_ESTIMATE_SCENARIO,
+ })
+ const option = findMunicipalityMobileFilterOption(options, 'scenario:optimistic')!
+ expect(applyMunicipalityMobileFilterOption(state, option)).toBe('scenario')
+ })
+})