// @vitest-environment nuxt import { describe, it, expect } from 'vitest'; import { useFilterChipsItems } from '../use-model-filter-chips'; const t = (key: string) => key; describe('useFilterChipsItems', () => { it('пустой массив без filter_ в query', () => { const filters = ref([]); const route = { query: {} }; const { chipsItems } = useFilterChipsItems(filters, route, t, ref('en')); expect(chipsItems.value).toEqual([]); }); it('игнорирует не-filter параметры', () => { const filters = ref([]); const route = { query: { page: '1', sort: 'popular' } }; const { chipsItems } = useFilterChipsItems(filters, route, t, ref('en')); expect(chipsItems.value).toEqual([]); }); it('создаёт чип из одного фильтра', () => { const filters = ref([{ name: 'hair_color', title: 'Hair color', options: [ { name: 'blonde', title: 'Blonde' }, { name: 'brunette', title: 'Brunette' }, ], }]); const route = { query: { filter_hair_color: 'blonde' } }; const { chipsItems } = useFilterChipsItems(filters, route, t, ref('en')); expect(chipsItems.value).toHaveLength(1); expect(chipsItems.value[0].title).toBe('Hair color: Blonde'); expect(chipsItems.value[0].value).toEqual(['filter_hair_color']); }); it('группирует from/to фильтры', () => { const filters = ref([{ name: 'age', title: 'Age', options: [ { name: '18', title: '18' }, { name: '50', title: '50' }, ], }]); const route = { query: { filter_age_from: '18', filter_age_to: '30' } }; const { chipsItems } = useFilterChipsItems(filters, route, t, ref('en')); expect(chipsItems.value).toHaveLength(1); expect(chipsItems.value[0].title).toBe('Age: 18 - 30'); expect(chipsItems.value[0].value).toEqual(['filter_age_from', 'filter_age_to']); }); it('числовое значение возвращается как есть', () => { const filters = ref([{ name: 'weight', title: 'Weight', options: [ { name: '40', title: '40' }, { name: '120', title: '120' }, ], }]); const route = { query: { filter_weight: '65' } }; const { chipsItems } = useFilterChipsItems(filters, route, t, ref('en')); expect(chipsItems.value[0].title).toBe('Weight: 65'); }); it('месяц → локализованное название', () => { const filters = ref([{ name: 'birth_month', title: 'Birth month', options: [ { name: '1', title: '1' }, { name: '12', title: '12' }, ], }]); const route = { query: { filter_birth_month: '6' } }; const { chipsItems } = useFilterChipsItems(filters, route, t, ref('en')); expect(chipsItems.value[0].title).toBe('Birth month: June'); }); });