/
test-router.js
207 lines (194 loc) · 7.24 KB
/
test-router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
'use strict';
var path = require('path');
var assert = require('yeoman-generator').assert;
var helpers = require('yeoman-generator').test;
var os = require('os');
var sinon = require('sinon');
var existTest = require('../generators/utils');
var stub;
describe('mario:router', function() {
describe('without options', function() {
before(function(done) {
stub = sinon.stub(existTest, 'verifyPath', function() {
return true;
});
helpers.run(path.join(__dirname, '../generators/router'))
.withArguments(['some_feature'])
.withGenerators([path.join(__dirname, '../generators/controller')])
.inDir(path.join(os.tmpdir(), './temp_test'))
.on('end', done);
});
it('create file', function() {
assert.file([
'app/scripts/apps/some_feature/some_feature_router.js',
'app/scripts/apps/some_feature/some_feature_controller.js'
]);
});
it('contains AMD dependency', function() {
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /'.\/some_feature_controller'/);
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /, SomeFeatureController/);
});
it('contains controller class', function() {
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /new SomeFeatureController/);
});
afterEach(function(done) {
stub.restore();
done();
});
});
describe('without options ES6', function() {
before(function(done) {
stub = sinon.stub(existTest, 'verifyPath', function() {
return true;
});
helpers.run(path.join(__dirname, '../generators/router'))
.withArguments(['some_feature'])
.withGenerators([path.join(__dirname, '../generators/controller')])
.inDir(path.join(os.tmpdir(), './temp_test'))
.withLocalConfig({preferences: {ecma: 6}})
.on('end', done);
});
it('create file', function() {
assert.file([
'app/scripts/apps/some_feature/some_feature_router.js',
'app/scripts/apps/some_feature/some_feature_controller.js'
]);
});
it('contains controller module dependency', function() {
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /import SomeFeatureController from '.\/some_feature_controller'/);
});
it('contains controller class', function() {
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /new SomeFeatureController/);
});
afterEach(function(done) {
stub.restore();
done();
});
});
describe('with existing controller', function() {
before(function(done) {
stub = sinon.stub(existTest, 'verifyPath', function() {
return true;
});
helpers.run(path.join(__dirname, '../generators/router'))
.inDir(path.join(os.tmpdir(), './temp_test'))
.withArguments(['some_feature'])
.withOptions({
directory: 'some_feature',
controller: 'some_controller'
})
.on('end', done);
});
it('creates files', function() {
assert.file([
'app/scripts/apps/some_feature/some_feature_router.js'
]);
});
it('contains AMD dependency', function() {
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /'.\/some_controller'/);
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /, SomeController/);
});
it('contains controller class', function() {
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /new SomeController/);
});
afterEach(function(done) {
stub.restore();
done();
});
});
describe('with existing controller ES6', function() {
before(function(done) {
stub = sinon.stub(existTest, 'verifyPath', function() {
return true;
});
helpers.run(path.join(__dirname, '../generators/router'))
.inDir(path.join(os.tmpdir(), './temp_test'))
.withArguments(['some_feature'])
.withOptions({
directory: 'some_feature',
controller: 'some_controller'
})
.withLocalConfig({preferences: {ecma: 6}})
.on('end', done);
});
it('creates files', function() {
assert.file([
'app/scripts/apps/some_feature/some_feature_router.js'
]);
});
it('contains controller module dependency', function() {
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /import SomeController from '.\/some_controller'/);
});
it('contains controller class', function() {
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /new SomeController/);
});
afterEach(function(done) {
stub.restore();
done();
});
});
describe('with existing controller expanded dirs', function() {
before(function(done) {
stub = sinon.stub(existTest, 'verifyPath', function() {
return true;
});
helpers.run(path.join(__dirname, '../generators/router'))
.inDir(path.join(os.tmpdir(), './temp_test'))
.withArguments(['some_feature'])
.withGenerators([path.join(__dirname, '../generators/controller')])
.withOptions({
directory: 'app/scripts/apps/some_feature',
controller: 'app/scripts/apps/vegetables/broccoli_controller.js'
})
.on('end', done);
});
afterEach(function(done) {
stub.restore();
done();
});
it('creates files', function() {
assert.file([
'app/scripts/apps/some_feature/some_feature_router.js'
]);
});
it('contains AMD dependency', function() {
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /'apps\/vegetables\/broccoli_controller'/);
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /, BroccoliController/);
});
it('contains controller class', function() {
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /new BroccoliController/);
});
});
describe('with existing controller expanded dirs ES6', function() {
before(function(done) {
stub = sinon.stub(existTest, 'verifyPath', function() {
return true;
});
helpers.run(path.join(__dirname, '../generators/router'))
.inDir(path.join(os.tmpdir(), './temp_test'))
.withArguments(['some_feature'])
.withGenerators([path.join(__dirname, '../generators/controller')])
.withOptions({
directory: 'app/scripts/apps/some_feature',
controller: 'app/scripts/apps/vegetables/broccoli_controller.js'
})
.withLocalConfig({preferences: {ecma: 6}})
.on('end', done);
});
afterEach(function(done) {
stub.restore();
done();
});
it('creates files', function() {
assert.file([
'app/scripts/apps/some_feature/some_feature_router.js'
]);
});
it('contains module dependency', function() {
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /import BroccoliController from 'apps\/vegetables\/broccoli_controller'/);
});
it('contains route', function() {
assert.fileContent('app/scripts/apps/some_feature/some_feature_router.js', /'some_feature': 'default'/);
});
});
});