-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_index.js
251 lines (221 loc) · 8.8 KB
/
test_index.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*global casper:false */
/*functional testing for the basic functionality of opentaba home page (without specific plan displaying)
runs with casperjs test filename (or casperjs.bat on windows)
*/
//Some setup //TODO: move this to a global casper config
var url = '../index.html';
casper.options.clientScripts.push('./sinon-1.7.3.js');
casper.options.clientScripts.push('./fixture.js');
casper.options.logLevel = "debug";
casper.options.verbose = true;
casper.options.viewportSize = {width:1024, height:768};
//initializing phantomcss
//Starting the tests
casper.test.begin('Basic index.html elements test',48, function suite(test){
casper.on('remote.message',log).
start(url, function(){
//casper.options.clientScripts.push('../testlibs/sinon-1.7.3.js');
test.assertTitle('תב"ע פתוחה: ירושלים',"The title is what we expected");
test.assertExists('form[id="search-form"]', 'The search form exists');
test.assertExists('#right-bar','The right bar exists');
test.assertVisible('#right-bar');
test.assertExists('#header', 'The header div exists');
test.assertVisible('#header');
test.assertExists('#info', 'The info div exists');
test.assertVisible('#info');
test.assertExists('#info-modal','The info modal exists');
test.assertNotVisible('#info-modal');
//this.wait(5000);
test.assertExists('#map.leaflet-container.leaflet-fade-anim','The map div exists with leaflet class');
test.assertExists('.icon-twitter', 'The twitter icon exists');
test.assertVisible('.icon-twitter');
test.assertExists('.icon-facebook', 'The facebook icon exists');
test.assertVisible('.icon-facebook');
test.assertExists('.icon-rss', 'The rss icon exists');
test.assertVisible('.icon-rss');
//very tied to implentation should think about this
//test.assertResourceExists('lib/pdfobject.js');
test.assertResourceExists('lib/path.js');
test.assertResourceExists('munis.js');
test.assertResourceExists('jerusalem.topojson');
test.assertResourceExists('app.js');
test.assertResourceExists('lib/bootstrap/js/bootstrap.min.js');
test.assertResourceExists('handlebars.min.js');
test.assertResourceExists('lib/template-renderer.js');
// make sure the toggle button exists and is not visible
test.assertExists('#toggle-button', 'The toggle button exists');
test.assertNotVisible('#toggle-button', 'The toggle button is not visible');
// search note should be hidden until a search is successfuly made
test.assertNotVisible('#search-note-p');
//TODO: phantomcss check map rendering
});
casper.thenClick('a[href="#info-modal"]',function(){
this.echo('clicked info-modal');
this.waitUntilVisible('#info-modal');
});
casper.then(function(){
test.assertVisible('#info-modal');
});
casper.then(function(){
this.click('button[id="close-info-modal"]');
this.echo('clicked to close info-modal');
});
casper.then(function(){
test.assertNotVisible('info-modal');
});
// init mocked data
casper.then(function(){
initMock();
});
// Address search tests
casper.then(function(){
// make sure an invalid address returns an error
casper.waitFor(function check() {
this.fill("form#search-form", {
'search-value' : 'רחובשלאקיים'
}, true);
return true;
}, function then() {
this.wait(3000, function() {
test.assertSelectorHasText('#search-error-p', 'לא נמצאו תוצאות עבור השאילתה', 'Search for an invalid address');
test.assertNotVisible('#search-note-p');
});
});
// make sure an address found in a different city (not in the current gushim file) displays the right message
casper.waitFor(function check() {
this.fill("form#search-form", {
'search-value' : 'שדרות מוריה חיפה'
}, true);
return true;
}, function then() {
this.wait(3000, function() {
test.assertSelectorHasText('#search-error-p', 'לא נמצאו תוצאות עבור השאילתה', 'Search for an address in a differenct city (no gush will be found)');
test.assertNotVisible('#search-note-p');
});
});
// make sure we do find a good jerusalem address
casper.waitFor(function check() {
this.fill("form#search-form", {
'search-value' : 'ברנר 9'
}, true);
return true;
}, function then() {
this.wait(3000, function() {
test.assertNotVisible('#search-error-p', 'Search for a good address');
test.assertVisible('#search-note-p');
});
});
});
// Gush number search test
casper.then(function(){
// make sure a non-existing gush number returns an error
casper.waitFor(function check() {
this.fill("form#search-form", {
'search-value' : '11111'
}, true);
return true;
}, function then() {
this.wait(1000, function() {
test.assertSelectorHasText('#search-error-p', 'לא נמצאו תוצאות עבור השאילתה', 'Search for an invalid gush number');
test.assertNotVisible('#search-note-p');
});
});
// make sure we do find a good gush number
casper.waitFor(function check() {
this.fill("form#search-form", {
'search-value' : '30035'
}, true);
return true;
}, function then() {
this.wait(1000, function() {
test.assertSelectorDoesntHaveText('#search-error-p', 'גוש', 'Search for a good gush number');
test.assertNotVisible('#search-note-p');
});
});
});
// Plan number search test
casper.then(function(){
// make sure a non-existing plan number returns an error
casper.waitFor(function check() {
this.fill("form#search-form", {
'search-value' : '12345'
}, true);
return true;
}, function then() {
this.wait(1000, function() {
test.assertVisible('#search-error-p');
test.assertSelectorHasText('#search-error-p', 'לא נמצאו תוצאות עבור השאילתה', 'Search for a non-existing plan number');
test.assertNotVisible('#search-plan-suggestions');
});
});
// make sure part of a number returns multiple suggestions
casper.waitFor(function check() {
this.fill("form#search-form", {
'search-value' : '12'
}, true);
return true;
}, function then() {
this.wait(1000, function() {
test.assertNotVisible('#search-error-p');
test.assertVisible('#search-plan-suggestions');
test.assertSelectorHasText('#search-plan-suggestions', 'האם התכוונת ל:', 'Search for a partial plan number and get suggestions');
});
});
// make sure an exact plan number takes us to it
casper.waitFor(function check() {
this.fill("form#search-form", {
'search-value' : '12222'
}, true);
return true;
}, function then() {
this.wait(1000, function() {
test.assertNotVisible('#search-error-p');
test.assertNotVisible('#search-plan-suggestions');
test.assertEval(function() {
return location.hash === '#/gush/28107/plan/12222';
});
});
});
});
//TODO: basic form testing (needs sinon injections and mocking
casper.run(function(){
this.echo(phantom.casperEngine,'debug');
test.done();
});
});
function initMock(){
casper.evaluate(function(){
var server = sinon.fakeServer.create();
server.autoRespond = true;
// filter in only requests made to our server
server.xhr.useFilters = true;
server.xhr.addFilter(function(method, url) {
// if we return true the request will not faked
return !url.match(/0.0.0.0:5000/);
});
var answer_12345 = JSON.stringify(planSearchFixture_12345);
var answer_12 = JSON.stringify(planSearchFixture_12);
var answer_12222 = JSON.stringify(planSearchFixture_12222);
var content = {'content-type':'application/json'};
// good search feedbacks
server.respondWith('GET', 'http://0.0.0.0:5000/plans/search/12345',
[200, content, answer_12345]);
server.respondWith('GET', 'http://0.0.0.0:5000/plans/search/12',
[200, content, answer_12]);
server.respondWith('GET', 'http://0.0.0.0:5000/plans/search/12222',
[200, content, answer_12222]);
// bad search feedbacks
server.respondWith('GET', 'http://0.0.0.0:5000/plans/search/%D7%A8%D7%97%D7%95%D7%91%D7%A9%D7%9C%D7%90%D7%A7%D7%99%D7%99%D7%9D',
[200, content, '[]']);
server.respondWith('GET', 'http://0.0.0.0:5000/plans/search/%D7%A9%D7%93%D7%A8%D7%95%D7%AA%20%D7%9E%D7%95%D7%A8%D7%99%D7%94%20%D7%97%D7%99%D7%A4%D7%94',
[200, content, '[]']);
server.respondWith('GET', 'http://0.0.0.0:5000/plans/search/11111',
[200, content, '[]']);
server.respond();
console.log('injected sinon');
});
casper.log('injected sinon fakeserver now', 'debug');
}
function log(msg){
console.log(msg);
}