1
1
import { Yok } from "../lib/common/yok" ;
2
2
import * as stubs from "./stubs" ;
3
3
import { CreateProjectCommand } from "../lib/commands/create-project" ;
4
- import { StringParameterBuilder } from "../lib/common/command-params" ;
4
+ import { StringCommandParameter } from "../lib/common/command-params" ;
5
+ import helpers = require( "../lib/common/helpers" ) ;
5
6
import * as constants from "../lib/constants" ;
6
7
import { assert } from "chai" ;
8
+ import { PrompterStub } from "./stubs" ;
9
+
10
+ const NgFlavor = "Angular" ;
11
+ const VueFlavor = "Vue.js" ;
12
+ const TsFlavor = "Plain TypeScript" ;
13
+ const JsFlavor = "Plain JavaScript" ;
7
14
8
15
let selectedTemplateName : string ;
9
16
let isProjectCreated : boolean ;
10
17
const dummyArgs = [ "dummyArgsString" ] ;
11
18
12
19
class ProjectServiceMock implements IProjectService {
13
- async validateProjectName ( opts : { projectName : string , force : boolean , pathToProject : string } ) : Promise < string > {
20
+ async validateProjectName ( opts : { projectName : string , force : boolean , pathToProject : string } ) : Promise < string > {
14
21
return null ;
15
22
}
16
23
@@ -45,7 +52,8 @@ function createTestInjector() {
45
52
template : undefined
46
53
} ) ;
47
54
testInjector . register ( "createCommand" , CreateProjectCommand ) ;
48
- testInjector . register ( "stringParameterBuilder" , StringParameterBuilder ) ;
55
+ testInjector . register ( "stringParameter" , StringCommandParameter ) ;
56
+ testInjector . register ( "prompter" , PrompterStub ) ;
49
57
50
58
return testInjector ;
51
59
}
@@ -55,8 +63,31 @@ describe("Project commands tests", () => {
55
63
let options : IOptions ;
56
64
let createProjectCommand : ICommand ;
57
65
66
+ function setupAnswers ( opts : {
67
+ projectNameAnswer ?: string ,
68
+ flavorAnswer ?: string ,
69
+ templateAnswer ?: string ,
70
+ } ) {
71
+ const prompterStub = < stubs . PrompterStub > testInjector . resolve ( "$prompter" ) ;
72
+ const choices : IDictionary < string > = { } ;
73
+ if ( opts . projectNameAnswer ) {
74
+ choices [ "First, what will be the name of your app?" ] = opts . projectNameAnswer ;
75
+ }
76
+ if ( opts . flavorAnswer ) {
77
+ choices [ opts . projectNameAnswer ? "Next" : "First" + ", which flavor would you like to use?" ] = opts . flavorAnswer ;
78
+ }
79
+ if ( opts . templateAnswer ) {
80
+ choices [ opts . projectNameAnswer ? "Finally" : "Next" + ", which template would you like to start from?" ] = opts . templateAnswer ;
81
+ }
82
+
83
+ prompterStub . expect ( {
84
+ choices
85
+ } ) ;
86
+ }
87
+
58
88
beforeEach ( ( ) => {
59
89
testInjector = createTestInjector ( ) ;
90
+ helpers . isInteractive = ( ) => true ;
60
91
isProjectCreated = false ;
61
92
selectedTemplateName = undefined ;
62
93
options = testInjector . resolve ( "$options" ) ;
@@ -104,34 +135,50 @@ describe("Project commands tests", () => {
104
135
assert . deepEqual ( selectedTemplateName , constants . TYPESCRIPT_NAME ) ;
105
136
} ) ;
106
137
107
- it ( "should not set the template name when --ng is not used." , async ( ) => {
108
- options . ng = false ;
138
+ it ( "should fail when --ng and --template are used simultaneously." , async ( ) => {
139
+ options . ng = true ;
140
+ options . template = "ng" ;
141
+
142
+ await assert . isRejected ( createProjectCommand . execute ( dummyArgs ) ) ;
143
+ } ) ;
144
+
145
+ it ( "should fail when --tsc and --template are used simultaneously." , async ( ) => {
146
+ options . tsc = true ;
147
+ options . template = "tsc" ;
148
+
149
+ await assert . isRejected ( createProjectCommand . execute ( dummyArgs ) ) ;
150
+ } ) ;
151
+
152
+ it ( "should ask for a template when ng flavor is selected." , async ( ) => {
153
+ setupAnswers ( { flavorAnswer : NgFlavor , templateAnswer : "Hello World" } ) ;
109
154
110
155
await createProjectCommand . execute ( dummyArgs ) ;
111
156
112
- assert . isUndefined ( selectedTemplateName ) ;
157
+ assert . deepEqual ( selectedTemplateName , "tns-template-hello-world-ng" ) ;
113
158
} ) ;
114
159
115
- it ( "should not set the template name when --tsc is not used ." , async ( ) => {
116
- options . tsc = false ;
160
+ it ( "should ask for a template when ts flavor is selected ." , async ( ) => {
161
+ setupAnswers ( { flavorAnswer : TsFlavor , templateAnswer : "Hello World" } ) ;
117
162
118
163
await createProjectCommand . execute ( dummyArgs ) ;
119
164
120
- assert . isUndefined ( selectedTemplateName ) ;
165
+ assert . deepEqual ( selectedTemplateName , "tns-template-hello-world-ts" ) ;
121
166
} ) ;
122
167
123
- it ( "should fail when --ng and --template are used simultaneously." , async ( ) => {
124
- options . ng = true ;
125
- options . template = "ng" ;
168
+ it ( "should ask for a template when js flavor is selected." , async ( ) => {
169
+ setupAnswers ( { flavorAnswer : JsFlavor , templateAnswer : "Hello World" } ) ;
126
170
127
- await assert . isRejected ( createProjectCommand . execute ( dummyArgs ) ) ;
171
+ await createProjectCommand . execute ( dummyArgs ) ;
172
+
173
+ assert . deepEqual ( selectedTemplateName , "tns-template-hello-world" ) ;
128
174
} ) ;
129
175
130
- it ( "should fail when --tsc and --template are used simultaneously." , async ( ) => {
131
- options . tsc = true ;
132
- options . template = "tsc" ;
176
+ it ( "should select the default vue template when the vue flavor is selected." , async ( ) => {
177
+ setupAnswers ( { flavorAnswer : VueFlavor } ) ;
133
178
134
- await assert . isRejected ( createProjectCommand . execute ( dummyArgs ) ) ;
179
+ await createProjectCommand . execute ( dummyArgs ) ;
180
+
181
+ assert . deepEqual ( selectedTemplateName , "https://github.com/NativeScript/template-blank-vue/tarball/0.9.0" ) ;
135
182
} ) ;
136
183
} ) ;
137
184
} ) ;
0 commit comments