|
| 1 | +import {ListBoxItem} from '../src/ListBox'; |
| 2 | +import React from 'react'; |
| 3 | +import {render} from '@testing-library/react'; |
| 4 | +import {useCollection} from '../src/Collection'; |
| 5 | + |
| 6 | + |
| 7 | +const CollectionTest = (props) => { |
| 8 | + const result = useCollection(props); |
| 9 | + props.spyCollection.current = result.collection; |
| 10 | + return <>{result.portal}</>; |
| 11 | +}; |
| 12 | + |
| 13 | +const renderItems = (items, spyCollection) => ( |
| 14 | + <CollectionTest spyCollection={spyCollection}> |
| 15 | + {items.map((item) => <ListBoxItem key={item} />)} |
| 16 | + </CollectionTest> |
| 17 | +); |
| 18 | + |
| 19 | +describe('Collection', () => { |
| 20 | + it('should be frozen even in case of empty initial collection', () => { |
| 21 | + let spyCollection = {}; |
| 22 | + render(renderItems([], spyCollection)); |
| 23 | + expect(spyCollection.current.frozen).toBe(true); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should have correct firstKey, lastKey and should be frozen after all items are deleted', () => { |
| 27 | + let spyCollection = {}; |
| 28 | + const {rerender} = render(renderItems(['a'], spyCollection)); |
| 29 | + rerender(renderItems([], spyCollection)); |
| 30 | + expect(spyCollection.current.frozen).toBe(true); |
| 31 | + expect(spyCollection.current.firstKey).toBe(null); |
| 32 | + expect(spyCollection.current.lastKey).toBe(null); |
| 33 | + }); |
| 34 | +}); |
0 commit comments