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

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

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

describe('Test for Navigation', function () {

  var apiRequests, Actions, Navigation, AuthStore, Router;

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

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

    apiRequests = require('../../utils/api-requests.js');
    Actions = require('../../actions/actions.js');
    AuthStore = require('../../stores/auth.js');
    Navigation = require('../../components/navigation.js');
    Router = require('react-router');
  });

  it('Should load the navigation component for logged out users', function () {

    AuthStore.authStatus = function () {
      return false;
    };

    var instance = TestUtils.renderIntoDocument(<Navigation />);
    expect(instance.state.loading).toBeFalsy();
    expect(instance.refreshNotifications).toBeDefined();
    expect(instance.refreshDone).toBeDefined();
    expect(instance.logOut).toBeDefined();
    expect(instance.appQuit).toBeDefined();

    var logoutIcon = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'fa-sign-out');
    expect(logoutIcon.length).toBe(0);

  });

  it('Should load the navigation component for logged in users', function () {

    AuthStore.authStatus = function () {
      return true;
    };

    var instance;
    React.withContext({router: new Router()}, function () {
      instance = TestUtils.renderIntoDocument(<Navigation />);
    });

    expect(instance.state.loading).toBeFalsy();
    expect(instance.refreshNotifications).toBeDefined();
    expect(instance.refreshDone).toBeDefined();
    expect(instance.logOut).toBeDefined();
    expect(instance.appQuit).toBeDefined();

    var logoutIcon = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'fa-sign-out');
    expect(logoutIcon.length).toBe(1);

    // Now Logout
    instance.logOut();
    AuthStore.trigger();
    logoutIcon = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'fa-sign-out');
    expect(logoutIcon.length).toBe(0);

    // Refresh Completed
    instance.state.loading = true;
    instance.refreshDone();
    expect(instance.state.loading).toBeFalsy();

    // Quit Application
    instance.appQuit();

  });

  it('Should test the refreshNotifications method', function () {

    spyOn(Actions, 'getNotifications');

    AuthStore.authStatus = function () {
      return true;
    };

    var instance = TestUtils.renderIntoDocument(<Navigation />);
    instance.refreshNotifications();
    expect(Actions.getNotifications).toHaveBeenCalled();

  });

});<commit_msg>Complete navigation comp. tests (100%)<commit_after>/* global jest, describe, beforeEach, it, expect, spyOn */

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

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

describe('Test for Navigation', function () {

  var apiRequests, Actions, Navigation, AuthStore, Router;

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

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

    apiRequests = require('../../utils/api-requests.js');
    Actions = require('../../actions/actions.js');
    AuthStore = require('../../stores/auth.js');
    Navigation = require('../../components/navigation.js');
    Router = require('react-router');
  });

  it('Should load the navigation component for logged out users', function () {

    AuthStore.authStatus = function () {
      return false;
    };

    var instance = TestUtils.renderIntoDocument(<Navigation />);
    expect(instance.state.loading).toBeFalsy();
    expect(instance.refreshNotifications).toBeDefined();
    expect(instance.refreshDone).toBeDefined();
    expect(instance.logOut).toBeDefined();
    expect(instance.appQuit).toBeDefined();

    var logoutIcon = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'fa-sign-out');
    expect(logoutIcon.length).toBe(0);

  });

  it('Should load the navigation component for logged in users', function () {

    AuthStore.authStatus = function () {
      return true;
    };

    var instance;
    React.withContext({router: new Router()}, function () {
      instance = TestUtils.renderIntoDocument(<Navigation />);
    });

    expect(instance.state.loading).toBeFalsy();
    expect(instance.refreshNotifications).toBeDefined();
    expect(instance.refreshDone).toBeDefined();
    expect(instance.logOut).toBeDefined();
    expect(instance.appQuit).toBeDefined();

    var logoutIcon = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'fa-sign-out');
    expect(logoutIcon.length).toBe(1);

    // Now Logout
    instance.logOut();
    AuthStore.trigger();
    logoutIcon = TestUtils.scryRenderedDOMComponentsWithClass(instance, 'fa-sign-out');
    expect(logoutIcon.length).toBe(0);

    // Refresh Completed
    instance.state.loading = true;
    instance.refreshDone();
    expect(instance.state.loading).toBeFalsy();

    // Quit Application
    instance.appQuit();

  });

  it('Should test the refreshNotifications method', function () {

    spyOn(Actions, 'getNotifications');

    AuthStore.authStatus = function () {
      return true;
    };

    var instance = TestUtils.renderIntoDocument(<Navigation />);
    instance.refreshNotifications();
    expect(Actions.getNotifications).toHaveBeenCalled();

  });

  it('Should test the interval on componentDidMount', function () {

    spyOn(Actions, 'getNotifications');

    AuthStore.authStatus = function () {
      return true;
    };

    var instance = TestUtils.renderIntoDocument(<Navigation />);
    expect(instance.componentDidMount).toBeDefined();

    // Should refresh on interval
    jest.runOnlyPendingTimers();
    expect(Actions.getNotifications).toHaveBeenCalled();

  });

});
{'fraction_non_alphanumeric': 0.15264657369920528, 'fraction_numerical': 0.001349527665317139, 'mean_word_length': 3.396835860250494, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2638077', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1879, 'n_words': 333}