Skip to content

Commit 743645a

Browse files
authored
[CI-3134] Filters Components (#77)
* [CI-3134] Filters Components * Update mocks * Checkpoint 2 - Ranged Slider * Update to styles * CSS Updates - Options List * Filter Group Header css * Add tests * Fix Merge conflicts and update story * Add Documentation * lint * lint 2 * Only update filter-range after onMouseUp event * Increased debounced time, bugfix rerender calls * Fixes based on comments * Add Classnames * lint: remove unnecessary else statement * bugfixes to remove console errors * Update styles * Update inputs to only update on blur * Add more tests * Add new test * Show invalid state if slider range inputs are empty * Fix input resizing on num digits increase * Change callback fn name, fix trackClick * CSS updates * Updates placeholders and naming
1 parent 9483a9c commit 743645a

24 files changed

+1443
-10
lines changed

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,8 @@
111111
"vite": "^4.5.3",
112112
"vite-plugin-css-injected-by-js": "^3.1.0",
113113
"webpack": "^5.75.0"
114+
},
115+
"dependencies": {
116+
"classnames": "^2.5.1"
114117
}
115118
}

spec/Filters.server.test.jsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React from 'react';
2+
import { renderToString } from 'react-dom/server';
3+
import '@testing-library/jest-dom';
4+
import { DEMO_API_KEY } from '../src/constants';
5+
import CioPlp from '../src/components/CioPlp';
6+
import Filters from '../src/components/Filters';
7+
import mockTransformedFacets from './local_examples/sampleFacets.json';
8+
9+
const mockSearchOrBrowseResponse = { facets: mockTransformedFacets };
10+
11+
describe('Testing Component on the server: Filters', () => {
12+
beforeEach(() => {
13+
// Mock console error to de-clutter the console for expected errors
14+
const spy = jest.spyOn(console, 'error');
15+
spy.mockImplementation(() => {});
16+
});
17+
18+
afterAll(() => {
19+
jest.resetAllMocks(); // This will reset all mocks after each test
20+
});
21+
22+
it('Should throw error if used outside the CioPlp', () => {
23+
expect(() => renderToString(<Filters facets={mockTransformedFacets} />)).toThrow();
24+
});
25+
26+
it('Should render filters based on search or browse response', async () => {
27+
const html = renderToString(
28+
<CioPlp apiKey={DEMO_API_KEY}>
29+
<Filters response={mockSearchOrBrowseResponse} />
30+
</CioPlp>,
31+
);
32+
33+
mockTransformedFacets.forEach((facetGroup) => {
34+
expect(html).toContain(facetGroup.displayName);
35+
});
36+
});
37+
38+
it('Should render correctly with render props', () => {
39+
const mockChildren = jest.fn().mockReturnValue(<div>Custom Filters</div>);
40+
41+
const filterProps = {
42+
response: mockSearchOrBrowseResponse,
43+
children: mockChildren,
44+
};
45+
46+
const html = renderToString(
47+
<CioPlp apiKey={DEMO_API_KEY}>
48+
<Filters {...filterProps} />
49+
</CioPlp>,
50+
);
51+
expect(mockChildren).toHaveBeenCalled();
52+
expect(html).toContain('Custom Filters');
53+
});
54+
});

0 commit comments

Comments
 (0)