/* eslint-disable no-unused-expressions */

import React from 'react';
import chai from 'chai';
import { mount } from 'enzyme';
import sinon from 'sinon';

import WindowContainer from '../../../build/renderer/ui/components/generic/WindowContainer';

import mockSettings, { fakeSettings, getVars, mockEvent } from './_mockSettings';

chai.should();

describe('<WindowContainer />', () => {
  let fired;
  let hooks;
  let unhooks;

  beforeEach(() => {
    mockSettings();
    fired = getVars().fired;
    hooks = getVars().hooks;
    unhooks = getVars().unhooks;
  });

  it('should not render a title when being the main window', () => {
    fakeSettings('theme', false);
    const component = mount(<WindowContainer isMainWindow title="Test Title" />);
    component.find('.window-title').length.should.be.equal(0);
  });

  it('should render a title when not the main window', () => {
    const component = mount(<WindowContainer title="Test Title" />);
    component.find('.window-title').length.should.be.equal(1);
  });

  it('should hook into theme settings change events on mount', () => {
    mount(<WindowContainer isMainWindow title="Test Title" />);
    hooks['settings:change:theme'].should.be.ok;
    hooks['settings:change:themeColor'].should.be.ok;
    hooks['settings:change:themeType'].should.be.ok;
  });

  it('should unhook from theme settings change events on unmount', () => {
    mount(<WindowContainer isMainWindow title="Test Title" />).unmount();
    unhooks['settings:change:theme'].should.be.ok;
    unhooks['settings:change:themeColor'].should.be.ok;
    unhooks['settings:change:themeType'].should.be.ok;
  });

  it('should update the theme state when theme event is fired', () => {
    const component = mount(<WindowContainer isMainWindow title="Test Title" />);
    component.state().theme.should.be.equal('theme');
    mockEvent('settings:change:theme', true);
    component.state().theme.should.be.equal(true);
  });

  it('should update the themeType state when themeType event is fired', () => {
    const component = mount(<WindowContainer isMainWindow title="Test Title" />);
    component.state().themeType.should.be.equal('FULL');
    mockEvent('settings:change:themeType', 'FULL');
    component.state().themeType.should.be.equal('FULL');
  });

  it('should update the themeColor state when themeColor event is fired', () => {
    const component = mount(<WindowContainer isMainWindow title="Test Title" />);
    component.state().themeColor.should.be.equal('themeColor');
    mockEvent('settings:change:themeColor', 'red');
    component.state().themeColor.should.be.equal('red');
  });

  it('should render the window controls', () => {
    const component = mount(<WindowContainer isMainWindow title="Test Title" />);
    component.find('.control').length.should.be.equal(3);

    fired.should.not.have.property('window:minimize');
    component.find('.control').at(0).props()
      .onClick();
    fired.should.have.property('window:minimize');
  });

  it('should fire the window control events when the controls are used', () => {
    const component = mount(<WindowContainer title="Test Title" />);

    fired.should.not.have.property('window:minimize');
    component.find('.control').at(0).props()
      .onClick();
    fired.should.have.property('window:minimize');

    fired.should.not.have.property('window:maximize');
    component.find('.control').at(1).props()
      .onClick();
    fired.should.have.property('window:maximize');

    fired.should.not.have.property('window:close');
    component.find('.control').at(2).props()
      .onClick();
    fired.should.have.property('window:close');
  });

  it('should confirm close when on the main page and a function is provided', () => {
    const spy = sinon.spy();
    const component = mount(<WindowContainer isMainWindow title="Test Title" confirmClose={spy} />);
    spy.callCount.should.be.equal(0);
    component.find('.control').at(2).props()
      .onClick();
    spy.callCount.should.be.equal(1);
  });
});

@@ -36,16 +36,50 @@
 ions */%0A
+import %7B remote %7D from 'electron';
 %0Aimport 
@@ -4049,13 +4049,1452 @@
 );%0A  %7D);
+%0A%0A  it('should attempt to minimize on darwin when double clicking the titlebar and the user config is minimize', () =%3E %7B%0A    const _orig = remote.systemPreferences.getUserDefault;%0A    remote.systemPreferences.getUserDefault = () =%3E 'Minimize';%0A    const component = mount(%3CWindowContainer isMainWindow title=%22Test Title%22 /%3E);%0A    component.instance()._darwinExpand();%0A    fired.should.have.property('window:minimize');%0A    remote.systemPreferences.getUserDefault = _orig;%0A  %7D);%0A%0A  it('should attempt to maximize on darwin when double clicking the titlebar and the user config is maximize', () =%3E %7B%0A    const _orig = remote.systemPreferences.getUserDefault;%0A    remote.systemPreferences.getUserDefault = () =%3E 'Maximize';%0A    const component = mount(%3CWindowContainer isMainWindow title=%22Test Title%22 /%3E);%0A    component.instance()._darwinExpand();%0A    fired.should.have.property('window:maximize');%0A    remote.systemPreferences.getUserDefault = _orig;%0A  %7D);%0A%0A  it('should not attempt to perform a window actions on darwin when double clicking the titlebar and the user config is unknown', () =%3E %7B%0A    const _orig = remote.systemPreferences.getUserDefault;%0A    remote.systemPreferences.getUserDefault = () =%3E 'RandomString';%0A    const component = mount(%3CWindowContainer isMainWindow title=%22Test Title%22 /%3E);%0A    component.instance()._darwinExpand();%0A    fired.should.be.deep.equal(%7B%7D);%0A    remote.systemPreferences.getUserDefault = _orig;%0A  %7D);
 %0A%7D);%0A

Add tests for the new double click to min/max methods on darwin