-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterBar.test.tsx
More file actions
84 lines (74 loc) · 2.6 KB
/
FilterBar.test.tsx
File metadata and controls
84 lines (74 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen } from '../test-utils';
// Mock the utils module
vi.mock('../utils', () => ({
getAvailableValues: vi.fn(() => [['scatter', 10], ['bar', 5]]),
getAvailableValuesForGroup: vi.fn(() => [['scatter', 15]]),
getSearchResults: vi.fn(() => []),
}));
import { FilterBar } from './FilterBar';
// ResizeObserver polyfill
class MockResizeObserver {
observe = vi.fn();
unobserve = vi.fn();
disconnect = vi.fn();
}
const defaultProps = {
activeFilters: [] as { category: 'lib'; values: string[] }[],
filterCounts: {
lib: { matplotlib: 100, seaborn: 80 },
spec: {}, plot: {}, data: {}, dom: {}, feat: {},
dep: {}, tech: {}, pat: {}, prep: {}, style: {},
},
orCounts: [] as Record<string, number>[],
specTitles: {},
currentTotal: 100,
displayedCount: 20,
randomAnimation: null,
imageSize: 'normal' as const,
onImageSizeChange: vi.fn(),
onAddFilter: vi.fn(),
onAddValueToGroup: vi.fn(),
onRemoveFilter: vi.fn(),
onRemoveGroup: vi.fn(),
onTrackEvent: vi.fn(),
};
describe('FilterBar', () => {
beforeEach(() => {
vi.clearAllMocks();
vi.stubGlobal('ResizeObserver', MockResizeObserver);
});
it('renders without crashing', () => {
render(<FilterBar {...defaultProps} />);
// Component should mount and have an input
expect(document.querySelector('input')).toBeTruthy();
});
it('renders active filter chip with category:value format', () => {
const filters = [
{ category: 'lib' as const, values: ['matplotlib'] },
];
render(<FilterBar {...defaultProps} activeFilters={filters} />);
// Chip label is "category:value" format
expect(screen.getByText('lib:matplotlib')).toBeInTheDocument();
});
it('shows counter text with total', () => {
render(<FilterBar {...defaultProps} currentTotal={42} displayedCount={20} />);
expect(screen.getByText(/42/)).toBeInTheDocument();
});
it('renders chip for each filter group', () => {
const filters = [
{ category: 'lib' as const, values: ['matplotlib'] },
{ category: 'plot' as const, values: ['scatter'] },
];
render(<FilterBar {...defaultProps} activeFilters={filters} />);
const chips = document.querySelectorAll('.MuiChip-root');
expect(chips.length).toBeGreaterThanOrEqual(2);
});
it('renders comma-separated values in chip', () => {
const filters = [
{ category: 'lib' as const, values: ['matplotlib', 'seaborn'] },
];
render(<FilterBar {...defaultProps} activeFilters={filters} />);
expect(screen.getByText('lib:matplotlib,seaborn')).toBeInTheDocument();
});
});