Repository URL to install this package:
|
Version:
8.1.0-rc.5 ▾
|
import React from 'react';
import { shallow } from 'enzyme';
import LogoLink from '../LogoLink';
import { PAGE, LINKS } from '../../../constants/logo';
describe('LogoLink', () => {
const logoUrl = '/some/logo/link';
describe('when logoUrl is provided', () => {
it('should match a snapshot', () => {
const component = shallow(<LogoLink logoUrl={logoUrl} />);
expect(component.getElement()).toMatchSnapshot();
});
});
describe('when logoUrl is not provided', () => {
beforeEach(() => {
const component = shallow(<LogoLink logoUrl={logoUrl} />);
component.setProps({
logoUrl: '',
});
});
it('should match a snapshot', () => {
const component = shallow(<LogoLink logoUrl={logoUrl} />);
expect(component.getElement()).toMatchSnapshot();
});
});
describe('LogoLink redirects', () => {
const user = {
data: {
name: 'Tom Tom',
email: 'tom@example.com',
avatarSmallUrl:
'https://6a5edc300520d4037dd6-0732807511066685711db213ddc1d2df.ssl.cf2.rackcdn.com/snw8ceng29ch3zbs4pvro3t2jxswf8yk',
accessToken: 'abc123',
},
loading: false,
isEligibleForFreeTrial: true,
};
it('should redirect the page to a Dashboard if user is logged in on product page with a custom URL passed in', () => {
const component = shallow(
<LogoLink user={user} currentPageType={PAGE.PRODUCT} customUrl="somewebsite.doodle.com" />
);
expect(component.find({ href: LINKS.DASHBOARD }).length).toBe(1);
});
it('should redirect the page to the homepage if the user is logged in on the site with a custom URL', () => {
const component = shallow(
<LogoLink currentPageType={PAGE.SITE} user={user} customUrl="somewebsite.doodle.com" />
);
expect(component.find({ href: LINKS.HOMEPAGE }).length).toBe(1);
});
it('should redirect the page to the homepage if the user is logged in on the site without a custom domain', () => {
const component = shallow(<LogoLink currentPageType={PAGE.SITE} user={user} />);
expect(component.find({ href: LINKS.HOMEPAGE }).length).toBe(1);
});
it('should redirect the page to the Homepage if user is not logged in while on the site page with a custom URL', () => {
const component = shallow(<LogoLink currentPageType={PAGE.SITE} customUrl="areallycoolwebsite.doodle.com" />);
expect(component.find({ href: LINKS.HOMEPAGE }).length).toBe(1);
});
it('should redirect the page to the Homepage if user is not logged in while on the site page without a custom URL', () => {
const component = shallow(<LogoLink currentPageType={PAGE.SITE} />);
expect(component.find({ href: LINKS.HOMEPAGE }).length).toBe(1);
});
it('should redirect the page to a custom URL if user is logged out on product page with a custom URL passed in', () => {
const component = shallow(<LogoLink currentPageType={PAGE.PRODUCT} customUrl="somewebsite.doodle.com" />);
expect(component.find({ href: 'somewebsite.doodle.com' }).length).toBe(1);
});
it('should redirect the page to the homepage if the user is logged out on the product page without a custom URL', () => {
const component = shallow(<LogoLink currentPageType={PAGE.PRODUCT} />);
expect(component.find({ href: LINKS.HOMEPAGE }).length).toBe(1);
});
});
});