feat(filters): move the availability preset into a bar dimension (#188)

This commit is contained in:
2026-08-25 15:18:23 -05:00
parent eb5799dd17
commit 1d7f928c48
2 changed files with 94 additions and 0 deletions
@@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest';
import { EMPTY_FILTERS, ItemFilters } from '../../src/filters';
import type { FilterContext } from '../../src/components/filters/dimension';
import {
availabilityDimension,
categoryDimension,
favoritesDimension,
priceDimension,
@@ -155,3 +156,36 @@ describe('statusDimension', () => {
expect(state.latest?.status).toBeNull();
});
});
describe('availabilityDimension', () => {
it('renders in the bar rather than the drawer', () => {
expect(availabilityDimension.placement).toBe('bar');
});
// Not sold is the default. A filter nobody chose must not read as one, or it
// shows in the tally and in the chip row on a page nobody has filtered.
it('reports no chip at the default', () => {
expect(availabilityDimension.chips(contextFor({ status: null }).ctx)).toEqual([]);
expect(
availabilityDimension.chips(contextFor({ status: ['available', 'reserved'] }).ctx)
).toEqual([]);
});
// The behaviour change in #188. This is what lets chips.length serve as both
// the tally and the "is anything filtered" predicate the empty state needs.
it('reports a chip for Sold and for All', () => {
expect(availabilityDimension.chips(contextFor({ status: ['sold'] }).ctx).map((c) => c.label))
.toEqual(['Sold']);
expect(
availabilityDimension
.chips(contextFor({ status: ['available', 'reserved', 'sold'] }).ctx)
.map((c) => c.label)
).toEqual(['All']);
});
it('returns to the default when removed', () => {
const { ctx, state } = contextFor({ status: ['sold'] });
availabilityDimension.chips(ctx)[0]?.onRemove();
expect(state.latest?.status).toBeNull();
});
});