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

WindowTopMenuButton.test.js

Blame
  • withPlugins.js 3.46 KiB
    import React from 'react';
    import { shallow } from 'enzyme';
    import { withPlugins } from '../../../src/extend';
    import { pluginStore } from '../../../src/extend/pluginStore';
    
    
    jest.mock('../../../src/extend/pluginStore');
    
    /** */
    const Target = props => <div>Hello</div>;
    
    /** create wrapper  */
    function createWrapper(plugins) {
      pluginStore.getPlugins = () => plugins;
      const props = {
        bar: 2,
        foo: 1,
      };
      const PluginWrapper = withPlugins('Target', Target);
      return shallow(<PluginWrapper {...props} />);
    }
    
    describe('withPlugins', () => {
      it('should return a function (normal function call)', () => {
        expect(withPlugins('Target', Target)).toBeInstanceOf(Function);
      });
    
      it('should return a function (curry function call)', () => {
        expect(withPlugins('Target')(Target)).toBeInstanceOf(Function);
      });
    
      it('displayName prop of returned function is based on target name argument', () => {
        expect(withPlugins('Bubu', Target).displayName)
          .toBe('WithPlugins(Bubu)');
      });
    });
    
    describe('PluginHoc: if no plugin exists for the target', () => {
      it('renders the target component', () => {
        const wrapper = createWrapper([]);
        expect(wrapper.find(Target).length).toBe(1);
        expect(wrapper.find(Target).props().foo).toBe(1);
        expect(wrapper.find(Target).props().bar).toBe(2);
      });
    });
    
    describe('PluginHoc: if a delete plugin exists for the target', () => {
      it('renders nothing', () => {
        const plugin = {
          mode: 'delete',
          target: 'Target',
        };
        const wrapper = createWrapper([plugin]);
        expect(wrapper.find('*').length).toBe(0);
      });
    });
    
    describe('PluginHoc: if a replace plugin exists for the target', () => {
      it('renders the plugin component', () => {
        /** */
        const PluginComponent = props => <div>look i am a plugin</div>;
        const plugin = {
          component: PluginComponent,
          mode: 'replace',
          target: 'Target',
        };
        const wrapper = createWrapper([plugin]);
        const selector = 'Connect(PluginComponent)';
        expect(wrapper.find(selector).length).toBe(1);
        expect(wrapper.find(selector).props().foo).toBe(1);
        expect(wrapper.find(selector).props().bar).toBe(2);
      });
    });
    
    describe('PluginHoc: if a add plugin exists for the target', () => {
      it('renders the target component and passes the plugin component as a prop', () => {
        /** */
        const PluginComponent = props => <div>look i am a plugin</div>;
        const plugin = {
          component: PluginComponent,
          mode: 'add',
          target: 'Target',
        };
        const wrapper = createWrapper([plugin]);
        expect(wrapper.find(Target).length).toBe(1);
        expect(wrapper.find(Target).props().foo).toBe(1);
        expect(wrapper.find(Target).props().bar).toBe(2);
        expect(wrapper.find(Target).props().PluginComponent.WrappedComponent)
          .toBe(PluginComponent);
      });
    });
    
    describe('PluginHoc: if a wrap plugin extists for the target', () => {
      it('renders the plugin component and passes the target component as a prop', () => {
        /** */
        const PluginComponent = props => <div>look i am a plugin</div>;
        const plugin = {
          component: PluginComponent,
          mode: 'wrap',
          target: 'Target',
        };
        const wrapper = createWrapper([plugin]);
        const selector = 'Connect(PluginComponent)';
        expect(wrapper.find(selector).length).toBe(1);
        expect(wrapper.find(selector).props().foo).toBe(1);
        expect(wrapper.find(selector).props().bar).toBe(2);
        expect(wrapper.find(selector).props().TargetComponent)
          .toBe(Target);
      });
    });