This repository was archived by the owner on Dec 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpegman.space-casper_tests.js
88 lines (66 loc) · 2.72 KB
/
pegman.space-casper_tests.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
var xpath = require('casper').selectXPath
casper.test.begin('Home page loads successfully.', 3, function(){
casper.start('http://pegman.space/');
casper.then(function() {
casper.test.assertTitle("Home - Pegman.Space", "Title correct.")
//check that message was included properly
casper.test.assertExists( xpath('/html/body/div[@class="container body-content"]/figure'), "Content included." )
//check footer is in correct place, won't be if I miss a closing tag
casper.test.assertExists(xpath('/html/body/div/footer'), "Footer in correct place.")
}
);
casper.run(function(){ casper.test.done()});
});
casper.test.begin('CV loads successfully.', 2, function(){
casper.start('http://pegman.space/cv');
casper.then(function() {
casper.test.assertTitle("CV - Pegman.Space", "Title correct.")
//check sections show up
casper.test.assertElementCount('.panel-default', 7)
}
);
casper.run(function(){ casper.test.done()});
});
casper.test.begin('IP checker works.', 3, function(){
casper.start('http://pegman.space/ip');
casper.then(function() {
casper.test.assertTitle("Home - Pegman.Space", "Title correct.")
//The ip address checker uses flask's flash feature to include a message in the next page loaded
//then redirects you to the home page. This test checks that the message actually gets included.
var flashed_message_xpath = xpath('/html/body/div[@class="container body-content"]/ul/li/span')
casper.test.assertExists(
flashed_message_xpath,
"A message was flashed."
)
casper.test.assertMatch(
casper.fetchText(flashed_message_xpath),
/[0-9]{1,4}(.[0-9]{1,4}){3}/,
"Flashed message roughly looks like an ip address."
);
}
);
casper.run(function(){ casper.test.done()});
});
casper.test.begin('DCU lab checker works.', 11, function(){
casper.start('http://pegman.space/dcu_rooms');
casper.then(function() {
casper.test.assertTitle("DCU Lab Bookings - Pegman.Space", "Title correct.")
//check all the rooms show up
casper.test.assertElementCount('.room_status', 9)
//Get the text from the room entries,
//needs casper.evaluate because the dom isn't directly accessible from this context.
var rooms = casper.evaluate( function(){
return __utils__.findAll('div.room_status')
.map(function(room){return room.innerHTML})
});
//Check the room messages match up and the timetables successfully fetch
rooms.forEach( function(room){
casper.test.assertMatch(
room,
/(L|C)(G|0|1|2)[0-9]{1,3}: ((Booked)|(Free)|(Closed))/,
"Matches normal pattern: " + room.trim()
)
});
});
casper.run(function(){ casper.test.done()});
});