<commit_before>/* global jest, describe, beforeEach, it, expect */

jest.dontMock('reflux');
jest.dontMock('../../actions/actions.js');
jest.dontMock('../../utils/api-requests');
jest.dontMock('../../components/notification.js');
jest.dontMock('../../stores/auth.js');
jest.dontMock('../../stores/notifications.js');
jest.dontMock('../../stores/settings.js');

var React = require('react/addons');
var TestUtils = React.addons.TestUtils;

describe('Test for Notification Component', function () {

  var apiRequests, Actions, AuthStore, SingleNotification, NotificationsStore;

  beforeEach(function () {
    // Mock Electron's window.require
    // and remote.require('shell')
    window.require = function () {
      return {
        require: function () {
          return {
            openExternal: function () {
              return {};
            }
          };
        },
        sendChannel: function () {
          return;
        }
      };
    };

    // Mock localStorage
    window.localStorage = {
      item: false,
      getItem: function () {
        return this.item;
      },
      setItem: function (item) {
        this.item = item;
      }
    };

    apiRequests = require('../../utils/api-requests.js');
    Actions = require('../../actions/actions.js');
    AuthStore = require('../../stores/auth.js');
    SingleNotification = require('../../components/notification.js');
    NotificationsStore = require('../../stores/notifications.js');
    SettingsStore = require('../../stores/settings.js');
  });

  it('Should render a notification component (Issue)', function () {

    var notification = {
      'id': '123123123',
      'repository': {
        'full_name': 'ekonstantinidis/gitify',
        'owner': {
          'avatar_url': 'http://avatar.url'
        }
      },
      'subject': {
        'type': 'Issue',
        'url': 'http://www.github.com/ekonstantinidis/gitify/pulls/26/'
      }
    };

    var instance = TestUtils.renderIntoDocument(
      <SingleNotification
        notification={notification}
        key={notification.id} />);

    expect(instance.state.isRead).toBeFalsy();
    expect(instance.pressTitle).toBeDefined();
    expect(instance.openBrowser).toBeDefined();
    expect(instance.markAsRead).toBeDefined();

    spyOn(instance, 'openBrowser');
    spyOn(instance, 'markAsRead');

    instance.pressTitle();
    expect(instance.openBrowser).toHaveBeenCalled();

    // Open Browser
    instance.openBrowser();

    // If 'markOnClick' is ON
    SettingsStore.onSetSetting('markOnClick', true);

    instance.pressTitle();

    expect(instance.openBrowser).toHaveBeenCalled();
    expect(instance.markAsRead).toHaveBeenCalled();
    jest.runAllTimers();

  });

  it('Should render a notification component (PullRequest)', function () {

    var notification = {
      'id': '123123123',
      'repository': {
        'full_name': 'ekonstantinidis/gitify',
        'owner': {
          'avatar_url': 'http://avatar.url'
        }
      },
      'subject': {
        'type': 'PullRequest',
        'url': 'http://www.github.com/ekonstantinidis/gitify/pulls/26/'
      }
    };

    var instance = TestUtils.renderIntoDocument(
      <SingleNotification
        notification={notification}
        key={notification.id} />);

    expect(instance.state.isRead).toBeFalsy();
    expect(instance.openBrowser).toBeDefined();
    expect(instance.markAsRead).toBeDefined();

  });

  it('Should render a notification component (OtherType)', function () {

    var notification = {
      'id': '123123123',
      'repository': {
        'full_name': 'ekonstantinidis/gitify',
        'owner': {
          'avatar_url': 'http://avatar.url'
        }
      },
      'subject': {
        'type': 'OtherType',
        'url': 'http://www.github.com/ekonstantinidis/gitify/pulls/26/'
      }
    };

    var instance = TestUtils.renderIntoDocument(
      <SingleNotification
        notification={notification}
        key={notification.id} />);

    expect(instance.state.isRead).toBeFalsy();
    expect(instance.openBrowser).toBeDefined();
    expect(instance.markAsRead).toBeDefined();

  });
<commit_msg>Coverage<commit_after>/* global jest, describe, beforeEach, it, expect */

jest.dontMock('reflux');
jest.dontMock('../../actions/actions.js');
jest.dontMock('../../utils/api-requests');
jest.dontMock('../../components/notification.js');
jest.dontMock('../../stores/auth.js');
jest.dontMock('../../stores/notifications.js');
jest.dontMock('../../stores/settings.js');

var React = require('react/addons');
var TestUtils = React.addons.TestUtils;

describe('Test for Notification Component', function () {

  var apiRequests, Actions, AuthStore, SingleNotification, NotificationsStore;

  beforeEach(function () {
    // Mock Electron's window.require
    // and remote.require('shell')
    window.require = function () {
      return {
        require: function () {
          return {
            openExternal: function () {
              return {};
            }
          };
        },
        sendChannel: function () {
          return;
        }
      };
    };

    // Mock localStorage
    window.localStorage = {
      item: false,
      getItem: function () {
        return this.item;
      },
      setItem: function (item) {
        this.item = item;
      }
    };

    apiRequests = require('../../utils/api-requests.js');
    Actions = require('../../actions/actions.js');
    AuthStore = require('../../stores/auth.js');
    SingleNotification = require('../../components/notification.js');
    NotificationsStore = require('../../stores/notifications.js');
    SettingsStore = require('../../stores/settings.js');
  });

  it('Should render a notification component (Issue)', function () {

    var notification = {
      'id': '123123123',
      'repository': {
        'full_name': 'ekonstantinidis/gitify',
        'owner': {
          'avatar_url': 'http://avatar.url'
        }
      },
      'subject': {
        'type': 'Issue',
        'url': 'http://www.github.com/ekonstantinidis/gitify/pulls/26/'
      }
    };

    var instance = TestUtils.renderIntoDocument(
      <SingleNotification
        notification={notification}
        key={notification.id} />);

    expect(instance.state.isRead).toBeFalsy();
    expect(instance.pressTitle).toBeDefined();
    expect(instance.openBrowser).toBeDefined();
    expect(instance.markAsRead).toBeDefined();

    spyOn(instance, 'openBrowser');
    spyOn(instance, 'markAsRead');

    instance.pressTitle();
    expect(instance.openBrowser).toHaveBeenCalled();

    // Open Browser
    instance.openBrowser();

    // If 'markOnClick' is ON
    SettingsStore.onSetSetting('markOnClick', true);

    instance.pressTitle();

    expect(instance.openBrowser).toHaveBeenCalled();
    expect(instance.markAsRead).toHaveBeenCalled();
    jest.runAllTimers();

  });

  it('Should render a notification component (PullRequest)', function () {

    var notification = {
      'id': '123123123',
      'repository': {
        'full_name': 'ekonstantinidis/gitify',
        'owner': {
          'avatar_url': 'http://avatar.url'
        }
      },
      'subject': {
        'type': 'PullRequest',
        'url': 'http://www.github.com/ekonstantinidis/gitify/pulls/26/'
      }
    };

    var instance = TestUtils.renderIntoDocument(
      <SingleNotification
        notification={notification}
        key={notification.id} />);

    expect(instance.state.isRead).toBeFalsy();
    expect(instance.openBrowser).toBeDefined();
    expect(instance.markAsRead).toBeDefined();

    // Open Browser
    instance.openBrowser();

  });

  it('Should render a notification component (OtherType)', function () {

    var notification = {
      'id': '123123123',
      'repository': {
        'full_name': 'ekonstantinidis/gitify',
        'owner': {
          'avatar_url': 'http://avatar.url'
        }
      },
      'subject': {
        'type': 'OtherType',
        'url': 'http://www.github.com/ekonstantinidis/gitify/pulls/26/'
      }
    };

    var instance = TestUtils.renderIntoDocument(
      <SingleNotification
        notification={notification}
        key={notification.id} />);

    expect(instance.state.isRead).toBeFalsy();
    expect(instance.openBrowser).toBeDefined();
    expect(instance.markAsRead).toBeDefined();

  });

{'fraction_non_alphanumeric': 0.16594827586206898, 'fraction_numerical': 0.007902298850574713, 'mean_word_length': 2.5469214437367302, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6976581', 'n_tokens_mistral': 2549, 'n_tokens_neox': 2429, 'n_words': 379}