/* 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();

  });

});

@@ -3070,12 +3070,442 @@
 %0A  %7D);%0A%0A
+  it('Should test the interval on componentDidMount', function () %7B%0A%0A    spyOn(Actions, 'getNotifications');%0A%0A    AuthStore.authStatus = function () %7B%0A      return true;%0A    %7D;%0A%0A    var instance = TestUtils.renderIntoDocument(%3CNavigation /%3E);%0A    expect(instance.componentDidMount).toBeDefined();%0A%0A    // Should refresh on interval%0A    jest.runOnlyPendingTimers();%0A    expect(Actions.getNotifications).toHaveBeenCalled();%0A%0A  %7D);%0A%0A
 %7D);%0A

Complete navigation comp. tests (100%)