@@ -3,6 +3,7 @@ var assert = require('assert');
33var proxyquire = require ( 'proxyquire' ) ;
44var sinon = require ( 'sinon' ) ;
55var _ = require ( 'lodash' ) ;
6+ var Promise = require ( 'pinkie-promise' ) ;
67var inquirer = require ( 'inquirer' ) ;
78var Router = require ( '../lib/router' ) ;
89var helpers = require ( './helpers' ) ;
@@ -56,56 +57,59 @@ describe('clear config route', function () {
5657 } ) ;
5758
5859 it ( 'allow returning home' , function ( ) {
59- this . sandbox . stub ( inquirer , 'prompt' , function ( arg , cb ) {
60- cb ( { whereTo : 'home' } ) ;
61- } ) ;
62- this . router . navigate ( 'clearConfig' ) ;
63- sinon . assert . calledOnce ( this . homeRoute ) ;
60+ this . sandbox . stub ( inquirer , 'prompt' ) . returns ( Promise . resolve ( { whatNext : 'home' } ) ) ;
61+ return this . router . navigate ( 'clearConfig' ) . then ( function ( ) {
62+ sinon . assert . calledOnce ( this . homeRoute ) ;
63+ } . bind ( this ) ) ;
6464 } ) ;
6565
6666 it ( 'track page and answer' , function ( ) {
67- this . sandbox . stub ( inquirer , 'prompt' , function ( arg , cb ) {
68- cb ( { whatNext : 'generator-angular:0.0.0' } ) ;
69- } ) ;
70- this . router . navigate ( 'clearConfig' ) ;
71- sinon . assert . calledWith ( this . insight . track , 'yoyo' , 'clearGlobalConfig' ) ;
72- sinon . assert . calledWith ( this . insight . track , 'yoyo' , 'clearGlobalConfig' , { whatNext : 'generator-angular:0.0.0' } ) ;
67+ this . sandbox . stub ( inquirer , 'prompt' ) . returns (
68+ Promise . resolve ( { whatNext : 'generator-angular:0.0.0' } )
69+ ) ;
70+ return this . router . navigate ( 'clearConfig' ) . then ( function ( ) {
71+ sinon . assert . calledWith ( this . insight . track , 'yoyo' , 'clearGlobalConfig' ) ;
72+ sinon . assert . calledWith (
73+ this . insight . track ,
74+ 'yoyo' ,
75+ 'clearGlobalConfig' ,
76+ { whatNext : 'generator-angular:0.0.0' }
77+ ) ;
78+ } . bind ( this ) ) ;
7379 } ) ;
7480
7581 it ( 'allows clearing a generator and return user to home screen' , function ( ) {
76- this . sandbox . stub ( inquirer , 'prompt' , function ( arg , cb ) {
77- cb ( { whatNext : 'foo' } ) ;
78- } ) ;
79- this . router . navigate ( 'clearConfig' ) ;
80- sinon . assert . calledOnce ( this . globalConfig . remove ) ;
81- sinon . assert . calledWith ( this . globalConfig . remove , 'foo' ) ;
82- sinon . assert . calledOnce ( this . homeRoute ) ;
82+ this . sandbox . stub ( inquirer , 'prompt' ) . returns ( Promise . resolve ( { whatNext : 'foo' } ) ) ;
83+ this . router . navigate ( 'clearConfig' ) . then ( function ( ) {
84+ sinon . assert . calledOnce ( this . globalConfig . remove ) ;
85+ sinon . assert . calledWith ( this . globalConfig . remove , 'foo' ) ;
86+ sinon . assert . calledOnce ( this . homeRoute ) ;
87+ } . bind ( this ) ) ;
8388 } ) ;
8489
8590 it ( 'allows clearing all generators and return user to home screen' , function ( ) {
86- this . sandbox . stub ( inquirer , 'prompt' , function ( arg , cb ) {
87- cb ( { whatNext : '*' } ) ;
88- } ) ;
89- this . router . navigate ( 'clearConfig' ) ;
90- sinon . assert . calledOnce ( this . globalConfig . removeAll ) ;
91- sinon . assert . calledOnce ( this . homeRoute ) ;
91+ this . sandbox . stub ( inquirer , 'prompt' ) . returns ( Promise . resolve ( { whatNext : '*' } ) ) ;
92+ return this . router . navigate ( 'clearConfig' ) . then ( function ( ) {
93+ sinon . assert . calledOnce ( this . globalConfig . removeAll ) ;
94+ sinon . assert . calledOnce ( this . homeRoute ) ;
95+ } . bind ( this ) ) ;
9296 } ) ;
9397
9498 it ( 'shows generator with global config entry' , function ( ) {
9599 var choices = [ ] ;
96100
97- this . sandbox . stub ( inquirer , 'prompt' , function ( arg , cb ) {
101+ this . sandbox . stub ( inquirer , 'prompt' , function ( arg ) {
98102 choices = arg [ 0 ] . choices ;
99- cb ( { whatNext : 'foo' } ) ;
103+ return Promise . resolve ( { whatNext : 'foo' } ) ;
100104 } ) ;
101- this . router . navigate ( 'clearConfig' ) ;
102-
103- // Clear all generators entry is present
104- assert . ok ( _ . find ( choices , { value : '*' } ) ) ;
105+ return this . router . navigate ( 'clearConfig' ) . then ( function ( ) {
106+ // Clear all generators entry is present
107+ assert . ok ( _ . find ( choices , { value : '*' } ) ) ;
105108
106- assert . ok ( _ . find ( choices , { value : 'generator-unicorn' } ) ) ;
107- assert . ok ( _ . find ( choices , { value : 'generator-phoenix' } ) ) ;
108- assert . ok ( _ . find ( choices , { name : 'Unicorn' } ) ) ;
109- assert . ok ( _ . find ( choices , { name : 'phoenix\u001b[31m (not installed anymore)\u001b[39m' } ) ) ;
109+ assert . ok ( _ . find ( choices , { value : 'generator-unicorn' } ) ) ;
110+ assert . ok ( _ . find ( choices , { value : 'generator-phoenix' } ) ) ;
111+ assert . ok ( _ . find ( choices , { name : 'Unicorn' } ) ) ;
112+ assert . ok ( _ . find ( choices , { name : 'phoenix\u001b[31m (not installed anymore)\u001b[39m' } ) ) ;
113+ } ) ;
110114 } ) ;
111115} ) ;
0 commit comments