Repository URL to install this package:
|
Version:
5.4.5-rc.0 ▾
|
import React from 'react';
import { mount } from 'enzyme';
import CreatePollMenu from './CreatePollMenu';
const userData = {
data: {
name: 'Rebecca Black',
email: 'rebecca.black@friday.com',
avatarSmallUrl:
'https://i.auto-bild.de/ir_img/2/4/6/9/0/2/3/FRIDAY-Kfz-Versicherung-Logo-474x316-505dbcedca2fd865.jpg',
accessToken: 'abc123',
premium: {
active: {
domain: 'myCustomDomain',
},
},
},
loading: false,
isEligibleForFreeTrial: true,
};
describe('CreatePollMenu', () => {
it('should match the snapshot', () => {
const component = mount(<CreatePollMenu />);
expect(component.getElement()).toMatchSnapshot();
});
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' }));
});
it('should call the function passed into onClickCreatePoll', () => {
const mockFunction = jest.fn();
const component = mount(<CreatePollMenu onClickCreatePoll={mockFunction} user={userData} />);
const button = component.find('.Menu span.Button');
button.simulate('click');
const menuItem = component.find(`span.Menu-item[data-testid='navigation-menu-create-date-poll']`);
menuItem.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} />);
const button = component.find('.Menu span.Button');
button.simulate('click');
const menuItem = component.find(`span.Menu-item[data-testid='navigation-menu-create-d11']`);
menuItem.simulate('click');
expect(mockFunction).toHaveBeenCalled();
});
it('should call the function passed into onClickCreateSurvey', () => {
const mockFunction = jest.fn();
const component = mount(<CreatePollMenu onClickCreateSurvey={mockFunction} user={userData} />);
const button = component.find('.Menu span.Button');
button.simulate('click');
const menuItem = component.find(`span.Menu-item[data-testid='navigation-menu-create-text-poll']`);
menuItem.simulate('click');
expect(mockFunction).toHaveBeenCalled();
});
it('should call the function passed into onClickCreateBookableCalendar', () => {
const mockFunction = jest.fn();
const component = mount(<CreatePollMenu onClickCreateBookableCalendar={mockFunction} user={userData} />);
const button = component.find('.Menu span.Button');
button.simulate('click');
const menuItem = component.find(`span.Menu-item[data-testid='navigation-menu-create-bookable-calendar']`);
menuItem.simulate('click');
expect(mockFunction).toHaveBeenCalled();
});
});