Skip to content

Commit

Permalink
Merge pull request #4886 from Automattic/test/move-auth
Browse files Browse the repository at this point in the history
Test: Move client/auth test to single test runner
  • Loading branch information
gziolo committed Apr 20, 2016
2 parents 3f8254b + 2ad0bbc commit 9821447
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
7 changes: 0 additions & 7 deletions client/auth/Makefile

This file was deleted.

50 changes: 26 additions & 24 deletions client/auth/test/login.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
/* eslint-disable vars-on-top */
require( 'lib/react-test-env-setup' )();

/**
* External dependencies
*/

const ReactDom = require( 'react-dom' ),
React = require( 'react' ),
i18n = require( 'lib/mixins/i18n' ),
expect = require( 'chai' ).expect,
sinon = require( 'sinon' ),
ReactInjection = require( 'react/lib/ReactInjection' ),
TestUtils = require( 'react-addons-test-utils' );
import { expect } from 'chai';
import identity from 'lodash/identity';
import { stub } from 'sinon';

/**
* Internal dependencies
*/
const AuthActions = require( 'lib/oauth-store/actions' );
import useFakeDom from 'test/helpers/use-fake-dom';
import useMockery from 'test/helpers/use-mockery';

// Handle initialization here instead of in `before()` to avoid timeouts. See client/post-editor/test/post-editor.jsx
i18n.initialize();
ReactInjection.Class.injectMixin( i18n.mixin );
describe( 'LoginTest', function() {
let Login, loginStub, page, React, ReactDom, ReactInjection, TestUtils;

useFakeDom.withContainer();
useMockery( ( mockery ) => {
loginStub = stub();
mockery.registerMock( 'lib/oauth-store/actions', {
login: loginStub
} );
} );

let Login = require( '../login.jsx' );
const page = ReactDom.render( <Login />, document.body );
before( () => {
React = require( 'react' );
ReactDom = require( 'react-dom' );
ReactInjection = require( 'react/lib/ReactInjection' );
TestUtils = require( 'react-addons-test-utils' );
ReactInjection.Class.injectMixin( { translate: identity } );
Login = require( '../login.jsx' );
page = ReactDom.render( <Login />, useFakeDom.getContainer() );
} );

describe( 'LoginTest', function() {
it( 'OTP is not present on first render', function( done ) {
page.setState( { requires2fa: false }, function() {
expect( page.refs.auth_code ).to.be.undefined;
Expand Down Expand Up @@ -60,15 +66,11 @@ describe( 'LoginTest', function() {
it( 'submits login form', function( done ) {
var submit = TestUtils.findRenderedDOMComponentWithTag( page, 'form' );

sinon.stub( AuthActions, 'login' );

page.setState( { login: 'user', password: 'pass', auth_code: 'otp' }, function() {
TestUtils.Simulate.submit( submit );

expect( AuthActions.login ).to.have.been.calledOnce;
expect( AuthActions.login.calledWith( 'user', 'pass', 'otp' ) ).to.be.true;

AuthActions.login.restore();
expect( loginStub ).to.have.been.calledOnce;
expect( loginStub.calledWith( 'user', 'pass', 'otp' ) ).to.be.true;
done();
} );
} );
Expand Down
3 changes: 3 additions & 0 deletions client/tests.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"auth": {
"test": [ "login" ]
},
"components": {
"count": {
"test": [ "index" ]
Expand Down

0 comments on commit 9821447

Please sign in to comment.