Files
backspace/packages/web/src/utils/searchQuery.test.ts
T
devsyncwrldandClaude Opus 5 50a8f12c77 feat(search): inline filters, and translate the search UI
The filters themselves already existed end to end — the server takes q, from,
has, before and after, the API client passes them, and the popover has fields
for each. What it lacked was discovery: the panel sits behind a button, so the
capability was invisible.

Typing 'de:fulano' or 'has:image' straight into the search box now applies the
same filters. Keys are accepted in both languages, since the app is bilingual,
and an unrecognised token falls back to being search text — otherwise a message
containing a URL or 'algo:coisa' would become unfindable.

Inline filters win over the panel's: whoever just typed one is expressing the
more recent intent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-01 17:49:05 -03:00

38 lines
1.3 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { parseSearchQuery } from './searchQuery';
describe('parseSearchQuery', () => {
it('separa filtro do texto', () => {
expect(parseSearchQuery('from:ana bolo')).toEqual({ text: 'bolo', from: 'ana' });
});
it('aceita as chaves em português', () => {
expect(parseSearchQuery('de:ana antes:2026-01-31')).toEqual({
text: '', from: 'ana', before: '2026-01-31',
});
});
it('traduz os valores de has para o que a API espera', () => {
expect(parseSearchQuery('contém:imagem').has).toBe('image');
expect(parseSearchQuery('has:file').has).toBe('file');
});
it('deixa token desconhecido virar texto de busca', () => {
// Uma URL não pode ser confundida com filtro, senão fica impossível
// procurar por um link que alguém mandou.
expect(parseSearchQuery('olha http://exemplo.com').text).toBe('olha http://exemplo.com');
expect(parseSearchQuery('coisa:aleatoria').text).toBe('coisa:aleatoria');
});
it('ignora filtro sem valor', () => {
expect(parseSearchQuery('from:').text).toBe('from:');
expect(parseSearchQuery('from:').from).toBeUndefined();
});
it('combina vários filtros com o texto', () => {
expect(parseSearchQuery('de:joao contém:link reunião')).toEqual({
text: 'reunião', from: 'joao', has: 'link',
});
});
});