-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_index_get_gush.js
151 lines (126 loc) · 5.86 KB
/
test_index_get_gush.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
/*global casper:false */
/*functional testing for the basic functionality of opentaba home page - The part displayed when showing specific plan
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};
var phantomcss = require('./PhantomCSS/phantomcss.js');
phantomcss.init({
libraryRoot:'./PhantomCSS',
screenshotRoot:'./img',
failedComparisonsRoot:'./fail_img',
threshold: 0.08
});
//var delay = 10;
//Starting the tests
casper.test.begin('Testing a specific gush plans display',22, function suite(test){
casper.on('page.init',initMock).
on('remote.message',log).
start(url, function(){
});
var hashpath = '/gush/30338';
var gushurl = url +'#'+ hashpath;
casper.thenOpen(gushurl).on('url.changed', initMock).wait(3000).
then(function(){
test.assertExists('#info h3','the info h3 exists now');
test.assertSelectorHasText('#info h3','גוש 30338');
//casper.log('The info h3 contains the expected text');
test.assertElementCount('div#info div.item',31,"31 items exists in info div as expected");
test.assertElementCount('div#info a',87, "87 'a' links should exists in info div");
test.assertSelectorHasText('div#info', 'תוספת גלריית עזרת נשים בבית כנסת קיים','Info div has some sampled expected text');
test.assertSelectorHasText('div#info', 'קביעת הוראות לאיחוד חלוקה חדשה','Info div has some sampled expected text');
test.assertSelectorHasText('div#info', 'אחוד וחלוקה מחדש במורדות צפון מזרח השכונה','Info div has some sampled expected text');
test.assertSelectorHasText('div#info', 'השלמ סעיף 3 שטח התוכנית ומקומה ע"י הוספת גושי','Info div has some sampled expected text');
test.assertSelectorHasText('div#info', 'הפיכת השכונה ממגורים 1 למגורים 5','Info div has some sampled expected text');
});
casper.thenOpen(gushurl + '/plan/12345').on('url.changed', initMock).wait(10000)
.then(function() {
// make sure the page still behaves the same data-wise
test.assertExists('#info h3','the info h3 exists now');
test.assertSelectorHasText('#info h3','גוש 30338');
test.assertElementCount('div#info div.item',31,"31 items exists in info div as expected");
test.assertElementCount('div#info a',87, "87 'a' links should exists in info div");
// make sure the plan was not found
test.assertDoesntExist('#selected-plan', "no plan was selected");
test.assertSelectorHasText('#search-error-p', 'לא נמצאה', 'got error for plan selection');
});
casper.thenOpen(gushurl + '/plan/9457').on('url.changed', initMock).wait(10000)
.then(function() {
// make sure the page still behaves the same data-wise
test.assertExists('#info h3','the info h3 exists now');
test.assertSelectorHasText('#info h3','גוש 30338');
test.assertElementCount('div#info div.item',31,"31 items exists in info div as expected");
test.assertElementCount('div#info a',87, "87 'a' links should exists in info div");
// make sure the plan was found
test.assertExists('#selected-plan', "the plan was selected");
test.assertSelectorDoesntHaveText('#search-error-p', 'לא נמצאה', 'no error for plan selection');
});
casper.then(function(){
phantomcss.screenshot("#map.leaflet-container.leaflet-fade-anim","mapon_gush_30338.png");
});
var href;
casper.then(function(){
href = casper.evaluate(function(){
//implement a test for specific link href
});
});
casper.then(function(){
//implement a test for icons
});
/* casper.then(function(){
phantomcss.screenshot('#info','info_div.png');
//implement gush picture
});
*/
casper.then(function compare_map_gush(){
phantomcss.compareMatched(".mapon_gush_30338");
});
casper.then(function check_phantomcss_map_gush(){
test.assertEqual(phantomcss.getExitStatus(),0,'map gush div should look according to predefined pictures');
});
//TODO: find out how to solve the font kerning problem failing this test
/* casper.then(function check_info_screenshot(){
phantomcss.compareMatched(".info_div");
});
casper.then(function check_phantomcss_info_div(){
test.assertEqual(phantomcss.getExitStatus(),0,'info div should look according to predefined picture');});
*/
casper.run(function(){
test.done();
});
});
function initMock(){
// load the plans' template from file
var fs = require('fs');
var template = '';
var f = null;
try {
f = fs.open('../templates/plans.html', 'r');
template = f.read();
} catch (e) {
console.log(e);
}
if (f) {
f.close();
}
casper.evaluate(function(template){
var server = sinon.fakeServer.create();
server.autoRespond = true;
var gush_answer = JSON.stringify(planFixture_30338);
server.respondWith('GET', 'http://0.0.0.0:5000/gush/30154,30159,30163,30164,30166,30167,30337,30338,30340,30540,30868/plans.json',
[200, {'content-type':'application/json'}, gush_answer]);
server.respondWith('GET', '/templates/plans.html',
[200, {'content-type':'text/html'}, template]);
server.respond();
console.log('injected sinon with test fixture');
}, { template: template });
casper.log('injected sinon fakeserver now', 'debug');
}
function log(msg){
console.log(msg);
}