import { describe, it, type TestContext } from 'node:test'; import { isTextFacet, isColorFacet, isSizeFacet, isRangeFacet, isCheckboxFacet } from './type.ts'; import type { Facet } from '../models/mod.ts'; const facets = Object.freeze([ { id: 'brand', label: 'Brand', type: 'TEXT', sort: 'RELEVANCE', selectedCount: 1, values: [] }, { id: 'color', label: 'Color', type: 'COLOR', selectedCount: 2, values: [] }, { id: 'outOfStock', label: 'Out of stock', type: 'CHECKBOX', selected: true, count: 42 }, { id: 'size', label: 'Sizes', type: 'SIZE', selectedCount: 3, sizeTypes: [] }, { id: 'style', label: 'Style', type: 'TEXT', sort: 'RELEVANCE', selectedCount: 4, values: [] }, { id: 'color2', label: 'Color2', type: 'COLOR', selectedCount: 5, values: [] }, { id: 'price', label: 'Price', type: 'RANGE', min: 20, max: 50 }, { id: 'custom.sale', label: 'On sale', type: 'CHECKBOX', selected: false }, { id: 'custom.width', label: 'Width', type: 'RANGE', min: 200, max: 220 } ]); describe('types', () => { it('should filter only TEXT types', (t: TestContext) => { t.assert.deepStrictEqual(facets.filter(isTextFacet), [ { id: 'brand', label: 'Brand', type: 'TEXT', sort: 'RELEVANCE', selectedCount: 1, values: [] }, { id: 'style', label: 'Style', type: 'TEXT', sort: 'RELEVANCE', selectedCount: 4, values: [] } ]); }); it('should filter only COLOR types', (t: TestContext) => { t.assert.deepStrictEqual(facets.filter(isColorFacet), [ { id: 'color', label: 'Color', type: 'COLOR', selectedCount: 2, values: [] }, { id: 'color2', label: 'Color2', type: 'COLOR', selectedCount: 5, values: [] } ]); }); it('should filter only SIZE types', (t: TestContext) => { t.assert.deepStrictEqual(facets.filter(isSizeFacet), [ { id: 'size', label: 'Sizes', type: 'SIZE', selectedCount: 3, sizeTypes: [] } ]); }); it('should filter only RANGE types', (t: TestContext) => { t.assert.deepStrictEqual(facets.filter(isRangeFacet), [ { id: 'price', label: 'Price', type: 'RANGE', min: 20, max: 50 }, { id: 'custom.width', label: 'Width', type: 'RANGE', min: 200, max: 220 } ]); }); it('should filter only CHECKBOX types', (t: TestContext) => { t.assert.deepStrictEqual(facets.filter(isCheckboxFacet), [ { id: 'outOfStock', label: 'Out of stock', type: 'CHECKBOX', selected: true, count: 42 }, { id: 'custom.sale', label: 'On sale', type: 'CHECKBOX', selected: false } ]); }); });