Skip to content
Snippets Groups Projects
Select Git revision
  • 9a50ea86d67feb0f2d196c33bef127001941e47f
  • 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

AnnotationSettings.test.js

Blame
  • AnnotationSettings.test.js 2.49 KiB
    import React from 'react';
    import { shallow } from 'enzyme';
    import { AnnotationSettings } from '../../../src/components/AnnotationSettings';
    
    /** */
    function createWrapper(props) {
      return shallow(
        <AnnotationSettings
          displayAll={false}
          displayAllDisabled={false}
          t={k => k}
          toggleAnnotationDisplay={() => {}}
          windowId="abc123"
          {...props}
        />,
      );
    }
    
    describe('AnnotationSettings', () => {
      let control;
      let wrapper;
      const toggleAnnotationDisplayMock = jest.fn();
    
    
      it('renders a FormControlLabel and a Switch', () => {
        wrapper = createWrapper();
        control = shallow(
          wrapper.find('WithStyles(WithFormControlContext(FormControlLabel))').props().control,
        );
        expect(wrapper.find('WithStyles(WithFormControlContext(FormControlLabel))').length).toBe(1);
        expect(control.find('Switch').length).toBe(1);
      });
    
      describe('control', () => {
        it('is not checked when the displayAll prop is false', () => {
          wrapper = createWrapper();
          control = shallow(
            wrapper.find('WithStyles(WithFormControlContext(FormControlLabel))').props().control,
          );
    
          expect(control.find('Switch').props().checked).toBe(false);
        });
    
        it('is checked when the displayAll prop is true', () => {
          wrapper = createWrapper({ displayAll: true });
          control = shallow(
            wrapper.find('WithStyles(WithFormControlContext(FormControlLabel))').props().control,
          );
    
          expect(control.find('Switch').props().checked).toBe(true);
        });
    
        it('is disabled based on the displayAllDisabled prop', () => {
          wrapper = createWrapper();
          control = shallow(
            wrapper.find('WithStyles(WithFormControlContext(FormControlLabel))').props().control,
          );
          expect(control.find('Switch').props().disabled).toBe(false);
    
          wrapper = createWrapper({ displayAllDisabled: true });
          control = shallow(
            wrapper.find('WithStyles(WithFormControlContext(FormControlLabel))').props().control,
          );
          expect(control.find('Switch').props().disabled).toBe(true);
        });
    
        it('calls the toggleAnnotationDisplay prop function on change', () => {
          wrapper = createWrapper({ toggleAnnotationDisplay: toggleAnnotationDisplayMock });
          control = shallow(
            wrapper.find('WithStyles(WithFormControlContext(FormControlLabel))').props().control,
          );
    
          control.find('Switch').props().onChange(); // trigger the onChange prop
    
          expect(toggleAnnotationDisplayMock).toHaveBeenCalledTimes(1);
        });
      });
    });