12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import {renderHook} from 'sentry-test/reactTestingLibrary';
- import {useCompactSelectOptionsCache} from 'sentry/views/insights/common/utils/useCompactSelectOptionsCache';
- describe('useCompactSelectOptionsCache', function () {
- it('keeps a cache', function () {
- const {result, rerender} = renderHook(
- (args: Parameters<typeof useCompactSelectOptionsCache>) => {
- return useCompactSelectOptionsCache(...args);
- },
- {
- initialProps: [
- [
- {value: '', label: 'All'},
- {value: '2', label: '2XX'},
- {value: '3', label: '3XX'},
- ],
- ],
- }
- );
- expect(result.current.options).toEqual([
- {value: '', label: 'All'},
- {value: '2', label: '2XX'},
- {value: '3', label: '3XX'},
- ]);
- rerender([[{value: '4', label: '4XX'}]]);
- rerender([[{value: '5', label: '5XX'}]]);
- expect(result.current.options).toEqual([
- {value: '', label: 'All'},
- {value: '2', label: '2XX'},
- {value: '3', label: '3XX'},
- {value: '4', label: '4XX'},
- {value: '5', label: '5XX'},
- ]);
- });
- it('sorts the output', function () {
- const {result} = renderHook(
- (args: Parameters<typeof useCompactSelectOptionsCache>) => {
- return useCompactSelectOptionsCache(...args);
- },
- {
- initialProps: [
- [
- {value: '3', label: '3XX'},
- {value: '5', label: '5XX'},
- {value: '', label: 'All'},
- {value: '2', label: '2XX'},
- {value: '4', label: '4XX'},
- ],
- ],
- }
- );
- expect(result.current.options).toEqual([
- {value: '', label: 'All'},
- {value: '2', label: '2XX'},
- {value: '3', label: '3XX'},
- {value: '4', label: '4XX'},
- {value: '5', label: '5XX'},
- ]);
- });
- it('clears the cache', function () {
- const {result, rerender} = renderHook(
- (args: Parameters<typeof useCompactSelectOptionsCache>) => {
- return useCompactSelectOptionsCache(...args);
- },
- {
- initialProps: [
- [
- {value: '3', label: '3XX'},
- {value: '5', label: '5XX'},
- {value: '', label: 'All'},
- {value: '2', label: '2XX'},
- {value: '4', label: '4XX'},
- ],
- ],
- }
- );
- expect(result.current.options).toEqual([
- {value: '', label: 'All'},
- {value: '2', label: '2XX'},
- {value: '3', label: '3XX'},
- {value: '4', label: '4XX'},
- {value: '5', label: '5XX'},
- ]);
- result.current.clear();
- rerender([[]]);
- expect(result.current.options).toEqual([]);
- });
- });
|