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

Testing: Refactor signup tests to remove rewire dependency #5811

Merged
merged 1 commit into from
Jun 6, 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
12 changes: 10 additions & 2 deletions client/signup/config/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,25 @@ function getGuidedToursDestination( destination, dependencies, flowName ) {
return getVariantUrl( guidedToursVariant );
}

export default {
const Flows = {
filterFlowName,
filterDestination,

defaultFlowName: 'main',

getFlow( flowName ) {
return user.get() ? removeUserStepFromFlow( flows[ flowName ] ) : flows[ flowName ];
let flow = Flows.getFlows()[ flowName ];

if ( user.get() ) {
flow = removeUserStepFromFlow( flow );
}

return flow;
},

getFlows() {
return flows;
}
};

export default Flows;
21 changes: 21 additions & 0 deletions client/signup/test/fixtures/flows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default {
main: {
steps: [ 'user', 'site' ],
destination: '/'
},

account: {
steps: [ 'user', 'site' ],
destination: '/'
},

other: {
steps: [ 'user', 'site' ],
destination: '/'
},

filtered: {
steps: [ 'user', 'site' ],
destination: '/'
}
};
16 changes: 13 additions & 3 deletions client/signup/test/flows.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
/**
* External dependencies
*/
var assert = require( 'assert' );
import assert from 'assert';
import sinon from 'sinon';

/**
* Internal dependencies
*/
import useFilesystemMocks from 'test/helpers/use-filesystem-mocks';
import useI18n from 'test/helpers/use-i18n';
import useMockery from 'test/helpers/use-mockery';
import useFakeDom from 'test/helpers/use-fake-dom';
import mockedFlows from './fixtures/flows';

describe( 'flows', function() {
var flows, user;
let flows, user;

useFakeDom();
useFilesystemMocks( __dirname );
useI18n();

useMockery( ( mockery ) => {
mockery.registerMock( 'lib/abtest', {
abtest: () => ''
} );
flows = require( 'signup/config/flows' );
} );

before( () => {
user = require( 'lib/user' )();

flows = require( 'signup/config/flows' );
sinon.stub( flows, 'getFlows' ).returns( mockedFlows );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one :)

} );

it( 'should return the full flow when the user is not logged in', function() {
Expand Down
34 changes: 0 additions & 34 deletions client/signup/test/signup/config/flows.js

This file was deleted.

25 changes: 19 additions & 6 deletions client/signup/test/utils.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
/**
* External dependencies
*/
var debug = require( 'debug' )( 'calypso:client:signup:controller-utils:test' ), // eslint-disable-line no-unused-vars
sinon = require( 'sinon' ),
assert = require( 'assert' );
import debugModule from 'debug';
import sinon from 'sinon';
import assert from 'assert';

/**
* Internal dependencies
*/
import useFilesystemMocks from 'test/helpers/use-filesystem-mocks';
import useI18n from 'test/helpers/use-i18n';
import useMockery from 'test/helpers/use-mockery';
import useFakeDom from 'test/helpers/use-fake-dom';
import mockedFlows from './fixtures/flows';

/**
* Module variables
*/
const debug = debugModule( 'calypso:client:signup:controller-utils:test' );

debug( 'start utils test' );

describe( 'utils', function() {
var flows, utils;
let flows, utils;

useFilesystemMocks( __dirname );
useI18n();
useFakeDom();

useMockery( ( mockery ) => {
mockery.registerMock( 'lib/abtest', {
abtest: () => ''
} );
} );

before( () => {
flows = require( 'signup/config/flows' );
sinon.stub( flows, 'getFlows' ).returns( mockedFlows );
utils = require( '../utils' );
} );

Expand Down Expand Up @@ -143,7 +156,7 @@ describe( 'utils', function() {
} );

it( 'should handle arbitrary step section names', function() {
var randomStepSectionName = 'random-step-section-' + Math.random();
const randomStepSectionName = 'random-step-section-' + Math.random();

assert.equal( utils.getValidPath( {
flowName: 'account',
Expand All @@ -154,7 +167,7 @@ describe( 'utils', function() {
} );

it( 'should handle arbitrary step section names in the default flow', function() {
var randomStepSectionName = 'random-step-section-' + Math.random();
const randomStepSectionName = 'random-step-section-' + Math.random();

assert.equal( utils.getValidPath( {
stepName: 'user',
Expand Down