From ceb0425b06c24aa5c93efb8a4a602d1724df9385 Mon Sep 17 00:00:00 2001 From: Jason Johnston Date: Fri, 8 Apr 2016 11:43:24 -0700 Subject: [PATCH] Tests: port user settings test to single runner update test doubles refactor test register test with runner --- client/lib/user-settings/Makefile | 12 --------- client/lib/user-settings/test/index.js | 24 +++++++++++++----- client/lib/user-settings/test/lib/user.js | 6 ----- client/lib/user-settings/test/lib/wp.js | 25 ------------------- .../user-settings/test/mocks/user-utils.js | 5 ++++ client/lib/user-settings/test/mocks/wp.js | 25 +++++++++++++++++++ client/tests.json | 9 +++++++ 7 files changed, 57 insertions(+), 49 deletions(-) delete mode 100644 client/lib/user-settings/Makefile delete mode 100644 client/lib/user-settings/test/lib/user.js delete mode 100644 client/lib/user-settings/test/lib/wp.js create mode 100644 client/lib/user-settings/test/mocks/user-utils.js create mode 100644 client/lib/user-settings/test/mocks/wp.js diff --git a/client/lib/user-settings/Makefile b/client/lib/user-settings/Makefile deleted file mode 100644 index d2f7959da8161..0000000000000 --- a/client/lib/user-settings/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -NODE_BIN := $(shell npm bin) -MOCHA ?= $(NODE_BIN)/mocha -BASE_DIR := $(NODE_BIN)/../.. -NODE_PATH := test:$(BASE_DIR)/client -COMPILERS ?= js:babel/register-without-polyfill -REPORTER ?= spec -UI ?= bdd - -test: - @NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers $(COMPILERS) --reporter $(REPORTER) --ui $(UI) - -.PHONY: test diff --git a/client/lib/user-settings/test/index.js b/client/lib/user-settings/test/index.js index e4c39277ef1c5..98c99a763d5d0 100644 --- a/client/lib/user-settings/test/index.js +++ b/client/lib/user-settings/test/index.js @@ -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 ) ); @@ -25,7 +38,6 @@ describe( 'User Settings', function() { function assertCorrectSettingIsRemoved() { assert.isUndefined( userSettings.unsavedSettings.test ); assert.isTrue( userSettings.unsavedSettings.lang_id ); - done(); } } ); diff --git a/client/lib/user-settings/test/lib/user.js b/client/lib/user-settings/test/lib/user.js deleted file mode 100644 index 3c040ddda4d35..0000000000000 --- a/client/lib/user-settings/test/lib/user.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function() { - return { - data: {}, - fetch: function() {} - }; -}; diff --git a/client/lib/user-settings/test/lib/wp.js b/client/lib/user-settings/test/lib/wp.js deleted file mode 100644 index 0fe3982941b0d..0000000000000 --- a/client/lib/user-settings/test/lib/wp.js +++ /dev/null @@ -1,25 +0,0 @@ -module.exports = { - undocumented: function() { - return { - me: function() { - return { - settings: function() { - return { - get: function( callback ) { - callback( false, { - test: false, - lang_id: false - } ); - }, - update: function( settings, callback ) { - setTimeout( function() { - callback( null, settings ); - } ); - } - }; - } - }; - } - }; - } -}; diff --git a/client/lib/user-settings/test/mocks/user-utils.js b/client/lib/user-settings/test/mocks/user-utils.js new file mode 100644 index 0000000000000..5235d2f5f678e --- /dev/null +++ b/client/lib/user-settings/test/mocks/user-utils.js @@ -0,0 +1,5 @@ +export default { + isLoggedIn() { + return true; + } +}; diff --git a/client/lib/user-settings/test/mocks/wp.js b/client/lib/user-settings/test/mocks/wp.js new file mode 100644 index 0000000000000..7f7b329357280 --- /dev/null +++ b/client/lib/user-settings/test/mocks/wp.js @@ -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 }; + } +}; diff --git a/client/tests.json b/client/tests.json index 6be23339444d4..1c7d103e2ee6d 100644 --- a/client/tests.json +++ b/client/tests.json @@ -377,6 +377,15 @@ "user": { "test": [ "utils" ] }, + "user-settings": { + "test": [ "index" ] + }, + "users": { + "test": [ "store" ] + }, + "viewers": { + "test": [ "store" ] + }, "wp": { "localization": { "test": [ "index" ]