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/tracking / src / helpers / getTrackingAttributes.spec.js
Size: Mime:
import getTrackingAttributes from './getTrackingAttributes';

// set multiple element attributes at once
const setAttributes = (element, attrs) => {
  Object.keys(attrs).forEach(key => {
    element.setAttribute(key, attrs[key]);
  });
};

describe('getTrackingAttributes', () => {
  it('should return an object with all the tracking attributes mapped from a DOM element', () => {
    const element = document.createElement('div');

    setAttributes(element, {
      href: '/dashboard',
      'data-tracking': true,
      // ga
      'data-ga-page': 'Page',
      'data-ga-category': 'Category',
      'data-ga-action': 'Action',
      'data-ga-label': 'Label',
      // amplitude
      'data-amplitude-type': 'Type',
      'data-amplitude-name': 'Name',
      'data-amplitude-properties': JSON.stringify({ 'Some-Props': 'Its a string' }),
    });

    const trackingObjeckt = getTrackingAttributes(element);

    expect(trackingObjeckt).toEqual({
      href: '/dashboard',
      isSameTabLink: true,
      valuesToTrack: {
        ga: {
          eventAction: 'Action',
          eventCategory: 'Category',
          eventLabel: 'Label',
          eventPage: 'Page',
        },
        amplitude: {
          eventName: 'Name',
          eventProperties: { 'Some-Props': 'Its a string' },
          eventType: 'Type',
        },
      },
    });
  });

  it('it should set isSameTabLink to false if the target of a href is _blank', () => {
    const element = document.createElement('div');

    setAttributes(element, {
      href: '/dashboard',
      target: '_blank',
      'data-tracking': true,
      // ga
      'data-ga-page': 'Page',
      'data-ga-category': 'Category',
      'data-ga-action': 'Action',
      'data-ga-label': 'Label',
      // amplitude
      'data-amplitude-type': 'Type',
      'data-amplitude-name': 'Name',
      'data-amplitude-properties': JSON.stringify({ 'Some-Props': 'Its a string' }),
    });

    const trackingObjeckt = getTrackingAttributes(element);

    expect(trackingObjeckt.isSameTabLink).toEqual(false);
  });
});