Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/components / structure / Navigation / CreatePollMenu / CreatePollMenu.spec.js
Size: Mime:
import React from 'react';
import { mount } from 'enzyme';
import CreatePollMenu from './CreatePollMenu';
import userData, { userWhitelistedForSchedEx } from '../fixture';
import navigateToUrl from '../../../utils/helper';

jest.mock('../../../utils/helper', () => ({
  __esModule: true,
  default: jest.fn(),
}));

const clickNavigateCreateButton = componentWrapper => {
  const navigationCreateButton = componentWrapper.find(`[data-testid='navigation-create-button']`).last();
  navigationCreateButton.simulate('click');
};

describe('CreatePollMenu', () => {
  it('should only render a create button (no dropdown menu) if the user is not logged in', () => {
    const component = mount(<CreatePollMenu />);
    expect(component.find({ href: '/create' }));
  });

  describe('when user is logged ', () => {
    it('should call the function passed into onClickCreatePoll', () => {
      const mockFunction = jest.fn();
      const component = mount(<CreatePollMenu onClickCreatePoll={mockFunction} user={userData} />);
      clickNavigateCreateButton(component);

      const createPollButton = component.find(`[data-testid='create-group-poll-button']`).last();
      createPollButton.simulate('click');

      expect(mockFunction).toHaveBeenCalled();
    });

    it('should call the function passed into onClickCreateOneOnOne', () => {
      const mockFunction = jest.fn();
      const component = mount(<CreatePollMenu onClickCreateOneOnOne={mockFunction} user={userData} />);
      clickNavigateCreateButton(component);

      const createOneToOneButton = component.find(`[data-testid='create-one-on-one-button']`).last();
      createOneToOneButton.simulate('click');

      expect(mockFunction).toHaveBeenCalled();
    });

    it('should call the function passed into onClickCreateBookingPage', () => {
      const mockFunction = jest.fn();
      const component = mount(<CreatePollMenu onClickCreateBookingPage={mockFunction} user={userData} />);
      clickNavigateCreateButton(component);

      const createBookingPage = component.find(`[data-testid='create-booking-page-button']`).last();
      createBookingPage.simulate('click');

      expect(mockFunction).toHaveBeenCalled();
    });

    it('should call the function passed into onClickSurvey', () => {
      const mockFunction = jest.fn();
      const component = mount(<CreatePollMenu onClickCreateSurvey={mockFunction} user={userData} />);
      clickNavigateCreateButton(component);

      const createSurvey = component.find(`[data-testid='create-survey-button']`).last();
      createSurvey.simulate('click');

      expect(mockFunction).toHaveBeenCalled();
    });

    describe('redirection URLs', () => {
      it('navigates to the monolith frontend when the user is not whitelisted for SchedEx', () => {
        const component = mount(<CreatePollMenu user={userData} />);
        clickNavigateCreateButton(component);

        const createPollButton = component.find(`[data-testid='create-group-poll-button']`).last();
        createPollButton.simulate('click');

        expect(navigateToUrl).toHaveBeenCalledWith('/create');
      });

      it('navigates to SchedEx Groups when the user is whitelisted for SchedEx', () => {
        const component = mount(<CreatePollMenu user={userWhitelistedForSchedEx} />);
        clickNavigateCreateButton(component);

        const createPollButton = component.find(`[data-testid='create-group-poll-button']`).last();
        createPollButton.simulate('click');

        expect(navigateToUrl).toHaveBeenCalledWith('/meeting/organize/groups');
      });

      it('navigates to meetme when the user is not whitelisted for SchedEx', () => {
        const component = mount(<CreatePollMenu user={userData} />);
        clickNavigateCreateButton(component);

        const createOneToOneButton = component.find(`[data-testid='create-one-on-one-button']`).last();
        createOneToOneButton.simulate('click');

        expect(navigateToUrl).toHaveBeenCalledWith('/meetme/qc/new');
      });

      it('navigates to SchedEx 1:1 when the user is whitelisted for SchedEx', () => {
        const component = mount(<CreatePollMenu user={userWhitelistedForSchedEx} />);
        clickNavigateCreateButton(component);

        const createOneToOneButton = component.find(`[data-testid='create-one-on-one-button']`).last();
        createOneToOneButton.simulate('click');

        expect(navigateToUrl).toHaveBeenCalledWith('/meeting/organize/1-1');
      });

      it('navigates to classic BC when the user is not whitelisted for SchedEx', () => {
        const component = mount(<CreatePollMenu user={userData} />);
        clickNavigateCreateButton(component);

        const createBookableCalendarButton = component.find(`[data-testid='create-booking-page-button']`).last();
        createBookableCalendarButton.simulate('click');

        expect(navigateToUrl).toHaveBeenCalledWith('/mm/new');
      });

      it('navigates to SchedEx BC when the user is whitelisted for SchedEx', () => {
        const component = mount(<CreatePollMenu user={userWhitelistedForSchedEx} />);
        clickNavigateCreateButton(component);

        const createBookingPageButton = component.find(`[data-testid='create-booking-page-button']`).last();
        createBookingPageButton.simulate('click');

        expect(navigateToUrl).toHaveBeenCalledWith('/meeting/organize/booking-page');
      });
    });
  });
});