import Form from '../../../common/auth/form';
import Login from '../Login.react';

import {
  expect,
  React,
  sinon,
  TestUtils
} from '../../../../test/mochaTestHelper';

describe('Login component', () => {
  const msg = {
    auth: {
      form: {
        button: {
          login: 'Login'
        },
        placeholder: {
          email: 'your@email.com'
        }
      }
    }
  };

  const loginAction = sinon.stub().resolves({});
  const replaceState = sinon.spy();

  const data = {
    actions: {
      login: loginAction
    },
    history: {
      replaceState
    },
    location: {},
    msg: msg,
    auth: {form: new Form()}
  };

  let sandbox, loginComponent, inputs, button;

  beforeEach(() => {
    sandbox = sinon.sandbox.create();
    loginComponent = TestUtils.renderIntoDocument(<Login {...data} />);
    inputs = TestUtils.scryRenderedDOMComponentsWithTag(loginComponent, 'input');
    button = TestUtils.findRenderedDOMComponentWithTag(loginComponent, 'button');
    form = TestUtils.findRenderedDOMComponentWithTag(loginComponent, 'form');
  });

  afterEach(() => {
    sandbox.restore();
  });

  it('should generate a login form', () => {
    expect(inputs.length).to.equal(2);
    expect(button).to.not.equal(null);
  });

  it('should fire login action and redirect', (done) => {
    TestUtils.Simulate.submit(form);

    expect(loginAction.calledOnce).to.be.true;
    loginAction().then(() => {
      expect(replaceState.calledOnce).to.be.true;
      expect(replaceState.calledWithExactly(null, '/')).to.be.true;
      done();
    })
  });
});

@@ -394,109 +394,132 @@
 %0A%0A  
-const loginAction = sinon.stub().resolves(%7B%7D);%0A  const replaceState = sinon.spy();%0A%0A  const data =
+let sandbox, loginComponent, inputs, button, loginAction, replaceState, form;%0A%0A  function componentProps() %7B%0A    return
  %7B%0A
+  
     
@@ -531,24 +531,26 @@
 ns: %7B%0A      
+  
 login: login
@@ -560,23 +560,27 @@
 ion%0A    
+  
 %7D,%0A    
+ 
+ 
 history:
@@ -578,24 +578,26 @@
  history: %7B%0A
+  
       replac
@@ -603,27 +603,31 @@
 ceState%0A    
+ 
+ 
 %7D,%0A
+  
     location
@@ -632,16 +632,18 @@
 on: %7B%7D,%0A
+  
     msg:
@@ -648,24 +648,26 @@
 g: msg,%0A    
+  
 auth: %7Bform:
@@ -683,59 +683,18 @@
 ()%7D%0A
+  
   %7D;%0A
-%0A
   
-let sandbox, loginComponent, inputs, button
+%7D
 ;%0A%0A 
@@ -747,24 +747,106 @@
 x.create();%0A
+    loginAction = sandbox.stub().resolves(%7B%7D);%0A    replaceState = sandbox.spy();%0A%0A
     loginCom
@@ -898,12 +898,24 @@
 %7B...
-data
+componentProps()
 %7D /%3E
@@ -1381,28 +1381,26 @@
 ion 
-and redirec
+on form submi
 t', (
-done
 ) =%3E
@@ -1483,24 +1483,131 @@
 to.be.true;%0A
+  %7D);%0A%0A  it('should redirect to home on successful login', done =%3E %7B%0A    TestUtils.Simulate.submit(form);%0A%0A
     loginAct
@@ -1763,16 +1763,17 @@
 ;%0A    %7D)
+;
 %0A  %7D);%0A%7D

Use sinon sandbox for spys/stubs in example test