mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-16 03:03:06 +00:00
Merge por Contact (uma linha por pessoa física) de lideranças, dobradinhas e staff, com capacidades como colunas; omnibox com capacidade/município/apoio + filtros salvos (2º call site do B18 via factory createSavedFilterStore); apagar pessoa com manifest de confirmação e cascata transacional; mobile edge-to-edge (omnibox sem bordas, cards com divisórias, salvar filtro no header). Sem migration. Closes #495
126 lines
4.5 KiB
TypeScript
126 lines
4.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
buildPeopleDeputySourceWhere,
|
|
buildPeopleLeadershipSourceWhere,
|
|
buildPeopleListHref,
|
|
buildPeopleStaffSourceWhere,
|
|
parsePeopleListParams,
|
|
resolvePeopleListUrl,
|
|
serializeCanonicalPeopleListSearchParams,
|
|
} from '@/utilities/people/peopleListUrl'
|
|
|
|
describe('people list URL contract', () => {
|
|
it('defaults to page 1 with no filters', () => {
|
|
expect(parsePeopleListParams({})).toEqual({ page: 1 })
|
|
})
|
|
|
|
it('validates page as a positive decimal integer', () => {
|
|
expect(parsePeopleListParams({ page: '4' }).page).toBe(4)
|
|
expect(parsePeopleListParams({ page: '0' }).page).toBe(1)
|
|
expect(parsePeopleListParams({ page: '-2' }).page).toBe(1)
|
|
expect(parsePeopleListParams({ page: 'abc' }).page).toBe(1)
|
|
})
|
|
|
|
it('trims q, omits it when empty and takes the first repeated cell', () => {
|
|
expect(parsePeopleListParams({ q: ' ana ' }).q).toBe('ana')
|
|
expect(parsePeopleListParams({ q: ' ' }).q).toBeUndefined()
|
|
expect(parsePeopleListParams({ q: ['primeiro', 'segundo'] }).q).toBe('primeiro')
|
|
})
|
|
|
|
it('parses and dedupes known capacity values', () => {
|
|
expect(parsePeopleListParams({ capacity: 'assessora' }).capacities).toEqual(['assessora'])
|
|
expect(
|
|
parsePeopleListParams({ capacity: ['lideranca', 'dobradinha', 'lideranca', 'unknown'] })
|
|
.capacities,
|
|
).toEqual(['lideranca', 'dobradinha'])
|
|
})
|
|
|
|
it('treats selecting every capacity as no filter (canonical "todas")', () => {
|
|
const all = parsePeopleListParams({ capacity: ['assessora', 'lideranca', 'dobradinha'] })
|
|
expect(all.capacities).toBeUndefined()
|
|
})
|
|
|
|
it('parses and dedupes integer municipality ids and known status values', () => {
|
|
expect(
|
|
parsePeopleListParams({
|
|
municipality: ['12', '12', '0', 'abc', '3'],
|
|
status: ['engajado', 'em_disputa', 'unknown'],
|
|
}),
|
|
).toEqual({ page: 1, municipalities: [12, 3], statuses: ['engajado', 'em_disputa'] })
|
|
})
|
|
|
|
it('serializes canonical params in stable order and omits defaults', () => {
|
|
const params = serializeCanonicalPeopleListSearchParams({
|
|
page: 1,
|
|
q: 'ana',
|
|
capacities: ['lideranca'],
|
|
municipalities: [3, 12],
|
|
statuses: ['engajado'],
|
|
})
|
|
expect(params.toString()).toBe(
|
|
'q=ana&capacity=lideranca&municipality=3&municipality=12&status=engajado',
|
|
)
|
|
})
|
|
|
|
it('builds hrefs through the canonical serializer and drops page 1', () => {
|
|
expect(buildPeopleListHref({ page: 1, capacities: ['dobradinha'] }, 1)).toBe(
|
|
'/campanha/pessoas?capacity=dobradinha',
|
|
)
|
|
expect(buildPeopleListHref({ page: 3 }, 3)).toBe('/campanha/pessoas?page=3')
|
|
})
|
|
|
|
it('resolves a bare URL to the bare path and rejects unsupported params', () => {
|
|
const resolved = resolvePeopleListUrl({ q: 'ana' })
|
|
expect(resolved.state).toEqual({ page: 1, q: 'ana' })
|
|
expect(resolved.href).toBe('/campanha/pessoas?q=ana')
|
|
expect(resolved.redirectHref).toBeUndefined()
|
|
|
|
const unsupported = resolvePeopleListUrl({ q: 'ana', sort: 'name' })
|
|
expect(unsupported.redirectHref).toBe('/campanha/pessoas?q=ana')
|
|
})
|
|
|
|
it('clamps an out-of-range page to totalPages', () => {
|
|
const resolved = resolvePeopleListUrl({ page: '9' }, 3)
|
|
expect(resolved.state.page).toBe(3)
|
|
expect(resolved.redirectHref).toBe('/campanha/pessoas?page=3')
|
|
})
|
|
})
|
|
|
|
describe('people list source-level wheres', () => {
|
|
it('builds the leadership where from q, statuses and municipalities', () => {
|
|
expect(buildPeopleLeadershipSourceWhere({ page: 1 })).toEqual({})
|
|
expect(
|
|
buildPeopleLeadershipSourceWhere({
|
|
page: 1,
|
|
q: 'ana',
|
|
statuses: ['engajado'],
|
|
municipalities: [3],
|
|
}),
|
|
).toEqual({
|
|
and: [
|
|
{ 'contact.name': { contains: 'ana' } },
|
|
{ supportStatus: { in: ['engajado'] } },
|
|
{ municipalities: { in: [3] } },
|
|
],
|
|
})
|
|
})
|
|
|
|
it('restricts the deputy where to q only', () => {
|
|
expect(buildPeopleDeputySourceWhere({ page: 1, q: 'ana', statuses: ['engajado'] })).toEqual({
|
|
and: [{ 'contact.name': { contains: 'ana' } }],
|
|
})
|
|
})
|
|
|
|
it('always restricts the staff source to staff roles with a ficha', () => {
|
|
expect(buildPeopleStaffSourceWhere({ page: 1 })).toEqual({
|
|
and: [
|
|
{ role: { in: ['advisor', 'coordinator', 'candidate'] } },
|
|
{ contact: { exists: true } },
|
|
],
|
|
})
|
|
expect(buildPeopleStaffSourceWhere({ page: 1, q: 'ana' }).and).toContainEqual({
|
|
'contact.name': { contains: 'ana' },
|
|
})
|
|
})
|
|
})
|