Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: port lib/user tests to single runner #4609

Merged
merged 5 commits into from
Apr 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/lib/people/test/log-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var assert = require( 'chai' ).assert;

var site = require( './lib/mock-site' ),
actions = require( './lib/mock-actions' ),
userActions = require( 'lib/users/test/lib/mock-actions' );
userActions = require( 'lib/users/test/fixtures/actions' );

require( 'lib/react-test-env-setup' )();

Expand Down
12 changes: 0 additions & 12 deletions client/lib/user-settings/Makefile

This file was deleted.

24 changes: 18 additions & 6 deletions client/lib/user-settings/test/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
/**
* External dependencies
*/
var assert = require( 'chai' ).assert;
import { assert } from 'chai';

/**
* Internal dependencies
*/
var userSettings = require( '../index.js' );
import useFakeDom from 'test/helpers/use-fake-dom';
import useMockery from 'test/helpers/use-mockery';
import wpMock from './mocks/wp';
import userUtilsMock from './mocks/user-utils';

describe( 'User Settings', function() {
before( function() {
describe( 'User Settings', () => {
let userSettings;

useMockery( mockery => {
mockery.registerMock( 'lib/wp', wpMock );
mockery.registerMock( 'lib/user/utils', userUtilsMock );
} );

useFakeDom();

before( () => {
userSettings = require( '..' );
userSettings.fetchSettings();
} );

it( 'should consider overridden settings as saved', function( done ) {
it( 'should consider overridden settings as saved', done => {
assert.isTrue( userSettings.updateSetting( 'test', true ) );
assert.isTrue( userSettings.updateSetting( 'lang_id', true ) );

Expand All @@ -25,7 +38,6 @@ describe( 'User Settings', function() {
function assertCorrectSettingIsRemoved() {
assert.isUndefined( userSettings.unsavedSettings.test );
assert.isTrue( userSettings.unsavedSettings.lang_id );

done();
}
} );
Expand Down
6 changes: 0 additions & 6 deletions client/lib/user-settings/test/lib/user.js

This file was deleted.

25 changes: 0 additions & 25 deletions client/lib/user-settings/test/lib/wp.js

This file was deleted.

5 changes: 5 additions & 0 deletions client/lib/user-settings/test/mocks/user-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
isLoggedIn() {
return true;
}
};
25 changes: 25 additions & 0 deletions client/lib/user-settings/test/mocks/wp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const me = function() {
return {
get() {},
settings() {
return {
get( callback ) {
callback( false, {
test: false,
lang_id: false
} );
},
update( settings, callback ) {
setTimeout( () => callback( null, settings ) );
}
};
}
};
}

export default {
me,
undocumented() {
return { me };
}
};
12 changes: 0 additions & 12 deletions client/lib/user/Makefile

This file was deleted.

112 changes: 42 additions & 70 deletions client/lib/user/test/utils.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,69 @@
/* eslint-disable vars-on-top */
require( 'lib/react-test-env-setup' )();

/**
* External dependencies
*/

var expect = require( 'chai' ).expect,
mockery = require( 'mockery' ),
sinon = require( 'sinon' );
import { expect } from 'chai';
import sinon from 'sinon';

/**
* Internal dependencies
*/
import useMockery from 'test/helpers/use-mockery';
import useFakeDom from 'test/helpers/use-fake-dom';

const LOGOUT_WITH_DOMAIN = '/url-with-|subdomain|';
const LOGOUT_WITHOUT_DOMAIN = '/url-without-domain';

describe( 'UserUtils', function() {
var user, UserUtils;
var logout_URL;
var always_use_logout_url = false;
var mockedConfig = function() {
return logout_URL;
};
mockedConfig.isEnabled = function( feature ) {
if ( feature === 'desktop' ) {
return false;
}

if ( feature === 'always_use_logout_url' ) {
return always_use_logout_url;
}

return true;
};
describe( 'UserUtils', () => {
let UserUtils, user, configMock;

this.timeout( 10 * 1000 );
useFakeDom();

beforeEach( function() {
mockery.enable( {
warnOnReplace: false,
warnOnUnregistered: false
} );

mockery.registerMock( 'config', mockedConfig );
useMockery( mockery => {
configMock = sinon.stub();
configMock.isEnabled = sinon.stub();
mockery.registerMock( 'config', configMock );
} );

before( () => {
user = require( 'lib/user' )();
UserUtils = require( '../utils' );
} );

afterEach( function() {
mockery.disable();
mockery.deregisterMock( 'config' );
beforeEach( () => {
configMock.returns( '/url-with-|subdomain|' );
} );

it( 'uses userData.logout_URL when available', function() {
sinon.stub( user, 'get', function() {
return {
logout_URL: '/userdata'
};
context( 'without logout url', () => {
before( () => {
configMock.isEnabled
.withArgs( 'always_use_logout_url' )
.returns( false );
} );

always_use_logout_url = false;
logout_URL = LOGOUT_WITH_DOMAIN;
expect( UserUtils.getLogoutUrl() ).to.be.equals( '/userdata' );

user.get.restore();
} );

it( 'works when |subdomain| is not present', function() {
always_use_logout_url = true;
logout_URL = LOGOUT_WITHOUT_DOMAIN;
expect( UserUtils.getLogoutUrl() ).to.be.equals( '/url-without-domain' );
it( 'uses userData.logout_URL when available', () => {
sinon.stub( user, 'get' ).returns( { logout_URL: '/userdata' } );
expect( UserUtils.getLogoutUrl() ).to.equal( '/userdata' );
user.get.restore();
} );
} );

it( 'replaces |subdomain| when present and have domain', function() {
sinon.stub( user, 'get', function() {
return {
localeSlug: 'es'
};
context( 'with logout url', () => {
before( () => {
configMock.isEnabled
.withArgs( 'always_use_logout_url' )
.returns( true );
} );

always_use_logout_url = true;
logout_URL = LOGOUT_WITH_DOMAIN;
expect( UserUtils.getLogoutUrl() ).to.be.equals( '/url-with-es.' );

user.get.restore();
} );
it( 'works when |subdomain| is not present', () => {
configMock.returns( '/url-without-domain' );
expect( UserUtils.getLogoutUrl() ).to.equal( '/url-without-domain' );
} );

it( 'replaces |subdomain| when present but no domain', function() {
always_use_logout_url = true;
logout_URL = LOGOUT_WITH_DOMAIN;
it( 'replaces |subdomain| when present and have domain', () => {
sinon.stub( user, 'get' ).returns( { localeSlug: 'es' } );
expect( UserUtils.getLogoutUrl() ).to.equal( '/url-with-es.' );
user.get.restore();
} );

expect( UserUtils.getLogoutUrl() ).to.be.equals( '/url-with-' );
it( 'replaces |subdomain| when present but no domain', () => {
expect( UserUtils.getLogoutUrl() ).to.equal( '/url-with-' );
} );
} );
} );
13 changes: 0 additions & 13 deletions client/lib/users/Makefile

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var site = require( './mock-site' ),
usersData = require( './mock-users-data' ),
moreUsersData = require( './mock-more-users-data' ),
deletedUserData = require( './mock-deleted-user-data' ),
updatedUserData = require( './mock-updated-single-user' ),
singleUserData = require( './mock-single-user' ),
pollingUsersData = require( './mock-polling-users-data' );
const site = require( './site' ),
usersData = require( './users' ),
moreUsersData = require( './more-users' ),
deletedUserData = require( './deleted-user' ),
updatedUserData = require( './updated-single-user' ),
singleUserData = require( './single-user' ),
pollingUsersData = require( './polling-users' );

module.exports = {
fetched: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import cloneDeep from 'lodash/cloneDeep';
/**
* Internal dependencies
*/
import usersData from './mock-users-data';
import moreUsersData from './mock-more-users-data';
import usersData from './users';
import moreUsersData from './more-users';

const clonedMoreUsers = cloneDeep( moreUsersData.users );
const updatedUsers = clonedMoreUsers.map( ( user ) => {
Expand Down
Loading