import React from 'react'; import {mountWithTheme} from 'sentry-test/enzyme'; import Button from 'app/components/button'; import Collapsible from 'app/components/collapsible'; const items = [1, 2, 3, 4, 5, 6, 7].map(i =>
Item {i}
); describe('Collapsible', function () { it('collapses items', function () { const wrapper = mountWithTheme({items}); expect(wrapper.find('div').length).toBe(5); expect(wrapper.find('div').at(2).text()).toBe('Item 3'); expect(wrapper.find('button[aria-label="Show 2 hidden items"]').exists()).toBe(true); expect(wrapper.find('button[aria-label="Collapse"]').exists()).toBeFalsy(); }); it('expands items', function () { const wrapper = mountWithTheme({items}); // expand wrapper.find('button[aria-label="Show 2 hidden items"]').simulate('click'); expect(wrapper.find('div').length).toBe(7); // collapse back wrapper.find('button[aria-label="Collapse"]').simulate('click'); expect(wrapper.find('div').length).toBe(5); }); it('respects maxVisibleItems prop', function () { const wrapper = mountWithTheme( {items} ); expect(wrapper.find('div').length).toBe(2); }); it('does not collapse items below threshold', function () { const wrapper = mountWithTheme( {items} ); expect(wrapper.find('div').length).toBe(7); expect(wrapper.find('button').exists()).toBeFalsy(); }); it('takes custom buttons', function () { const wrapper = mountWithTheme( ( )} expandButton={({onExpand, numberOfCollapsedItems}) => ( )} > {items} ); expect(wrapper.find('button').length).toBe(1); // custom expand wrapper.find('button[aria-label="Expand"]').simulate('click'); expect(wrapper.find('div').length).toBe(7); // custom collapse back wrapper.find('button[aria-label="Custom Collapse"]').simulate('click'); expect(wrapper.find('div').length).toBe(5); }); });