finish new demo
This commit is contained in:
parent
e2b85fe819
commit
30d36a33d5
16 changed files with 318 additions and 94 deletions
|
|
@ -228,6 +228,43 @@ describe('useFilters', () => {
|
|||
expect(Object.keys(result.current.filters)).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('blocks adding new filters when lockAdds is set (shared link), but allows replacing existing ones', () => {
|
||||
const sixFeatures: FeatureMeta[] = ['a', 'b', 'c', 'd', 'e', 'f'].map((name) => ({
|
||||
name,
|
||||
type: 'numeric',
|
||||
min: 0,
|
||||
max: 100,
|
||||
}));
|
||||
const onFilterLimitReached = vi.fn();
|
||||
|
||||
// A non-paying user on a shared link: still under the cap (5), but adds are
|
||||
// locked. They can adjust the shared filter ('a') but not add a new one.
|
||||
const { result } = renderHook(() =>
|
||||
useFilters({
|
||||
initialFilters: { a: [0, 100] },
|
||||
features: sixFeatures,
|
||||
filterLimit: 5,
|
||||
lockAdds: true,
|
||||
onFilterLimitReached,
|
||||
})
|
||||
);
|
||||
|
||||
// Adding a brand-new filter is blocked and reported, even though count < cap.
|
||||
act(() => {
|
||||
result.current.handleAddFilter('b');
|
||||
});
|
||||
expect(Object.keys(result.current.filters)).toHaveLength(1);
|
||||
expect(result.current.filters.b).toBeUndefined();
|
||||
expect(onFilterLimitReached).toHaveBeenCalledTimes(1);
|
||||
|
||||
// Re-applying the existing filter replaces it (no new key) and is allowed.
|
||||
act(() => {
|
||||
result.current.handleAddFilter('a');
|
||||
});
|
||||
expect(Object.keys(result.current.filters)).toHaveLength(1);
|
||||
expect(onFilterLimitReached).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('does not cap filters when filterLimit is null (licensed users)', () => {
|
||||
const sixFeatures: FeatureMeta[] = ['a', 'b', 'c', 'd', 'e', 'f'].map((name) => ({
|
||||
name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue