Skip to content
Snippets Groups Projects
Select Git revision
  • a9b9b6d1c6878a1fab968cb30e6d31ddc0aa94fc
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

CollapsibleSection.test.js

Blame
  • user avatar
    Chris Beer authored
    54b4fa20
    History
    CollapsibleSection.test.js 2.36 KiB
    import { shallow } from 'enzyme';
    import Typography from '@material-ui/core/Typography';
    import MiradorMenuButton from '../../../src/containers/MiradorMenuButton';
    import { CollapsibleSection } from '../../../src/components/CollapsibleSection';
    
    /**
     * Helper function to create a shallow wrapper around CollapsibleSection
     */
    function createWrapper(props) {
      return shallow(
        <CollapsibleSection
          classes={{}}
          id="abc123"
          label="The Section Label"
          t={k => k}
          {...props}
        >
          <span>Child content</span>
        </CollapsibleSection>,
      );
    }
    
    describe('CollapsibleSection', () => {
      let wrapper;
      beforeEach(() => {
        wrapper = createWrapper();
      });
    
      it('renders the passed in label is a Typography', () => {
        expect(wrapper.find(Typography).props().children).toEqual('The Section Label');
      });
    
      it('renders a mirador button with an icon dependent on the open state', () => {
        expect(wrapper.state().open).toBe(true);
        expect(wrapper.find('pure(KeyboardArrowUpSharpIcon)'));
        wrapper.setState({ open: false });
        expect(wrapper.find('pure(KeyboardArrowDownSharpIcon)'));
      });
    
      it('renders the appropriate i18n label based on open state', () => {
        expect(wrapper.state().open).toBe(true);
        expect(wrapper.find(MiradorMenuButton).props()['aria-label']).toEqual('collapseSection');
        expect(wrapper.find(MiradorMenuButton).prop('aria-expanded')).toEqual(true);
        wrapper.setState({ open: false });
        expect(wrapper.find(MiradorMenuButton).props()['aria-label']).toEqual('expandSection');
        expect(wrapper.find(MiradorMenuButton).prop('aria-expanded')).toEqual(false);
      });
    
      it('renders children based on the open state', () => {
        expect(wrapper.state().open).toBe(true);
        expect(wrapper.find('Fragment').props().children[1]).toEqual(<span>Child content</span>);
        wrapper.setState({ open: false });
        expect(wrapper.find('Fragment').props().children[1]).toBe(false);
      });
    
      it('toggles the children based on MiradorMenuButton/Typography click', () => {
        expect(wrapper.find('Fragment').props().children[1]).toEqual(<span>Child content</span>);
        wrapper.find(Typography).simulate('click');
        expect(wrapper.find('Fragment').props().children[1]).toBe(false);
        wrapper.find(MiradorMenuButton).simulate('click');
        expect(wrapper.find('Fragment').props().children[1]).toEqual(<span>Child content</span>);
      });
    });