Skip to content

Commit

Permalink
Tests: port user settings test to single runner
Browse files Browse the repository at this point in the history
update test doubles

refactor test

register test with runner
  • Loading branch information
Jason Johnston committed Apr 15, 2016
1 parent 95fae6b commit ceb0425
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 49 deletions.
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 };
}
};
9 changes: 9 additions & 0 deletions client/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,15 @@
"user": {
"test": [ "utils" ]
},
"user-settings": {
"test": [ "index" ]
},
"users": {
"test": [ "store" ]
},
"viewers": {
"test": [ "store" ]
},
"wp": {
"localization": {
"test": [ "index" ]
Expand Down

0 comments on commit ceb0425

Please sign in to comment.