{"size": 2274, "ext": "js", "max_stars_repo_path": "src/components/CookieBannerContent.spec.js", "max_stars_repo_name": "etage4/react-cookie-law", "max_stars_repo_stars_event_min_datetime": "2020-12-01T19:05:41.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-01T19:05:41.000Z", "max_issues_repo_path": "src/components/CookieBannerContent.spec.js", "max_issues_repo_name": "etage4/react-cookie-law", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/CookieBannerContent.spec.js", "max_forks_repo_name": "etage4/react-cookie-law", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.32, "max_line_length": 92, "alphanum_fraction": 0.6517150396}
import React from 'react';
import { mount, shallow } from 'enzyme';
import CookieBannerContent from './CookieBannerContent';
import CookieBannerPreferences from './CookieBannerPreferences';
import bannerStyle from './bannerStyle';

describe('CookieBannerContent component', () => {
  test('should be rendered', () => {
    const component = shallow(
      <CookieBannerContent message="Custom text" />,
    );

    expect(component).toMatchSnapshot();
  });

  test('should be rendered with elements', () => {
    const props = {
      styles: bannerStyle,
      message: 'Custom text',
      policyLink: '/url-to-policy',
      privacyPolicyLinkText: 'Privacy Policy',
      necessaryOptionText: 'Necessary',
      preferencesOptionText: 'Preferences',
      statisticsOptionText: 'Statistics',
      marketingOptionText: 'Marketing',
      //acceptButtonText: 'Accept all',
      managePreferencesButtonText: 'Mange my cookies',
      savePreferencesButtonText: 'Save and close',
      acceptButtonText: 'Accept',
      acceptAllButtonText: 'Accept All',
      declineButtonText: 'Decline',
      showBanner: true
    };

    const component = mount(
      <CookieBannerContent {...props} />,
    );

    expect(component.find('.react-cookie-law-msg').text()).toBe('Custom text');
    expect(component.find('a.react-cookie-law-policy').prop('href')).toBe('/url-to-policy');
    expect(component.find('.react-cookie-law-policy').text()).toBe('Privacy Policy');
    expect(component.contains(<CookieBannerPreferences {...props} />)).toBeFalsy();
  });

  test('should click manage preferences button', () => {
    const props = {
      onConfirm: jest.fn(),
      showBanner: true
    };

    const component = mount(
      <CookieBannerContent {...props} />,
    );

    component.find('.react-cookie-law-manage-btn').simulate('click');

    expect(component.contains(<CookieBannerPreferences {...props} />)).toBeTruthy();
  });

  test('should click confirm button', () => {
    const props = {
      onAcceptAll: jest.fn(),
      showBanner: true
    };

    const component = mount(
      <CookieBannerContent {...props} />,
    );

    component.find('.react-cookie-law-accept-btn').simulate('click');

    expect(props.onAcceptAll).toHaveBeenCalledTimes(1);
  });
});
