-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-run.js
81 lines (78 loc) · 2.45 KB
/
test-run.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
// Generated by CoffeeScript 1.6.2
(function() {
define(['backbone', 'socketio', 'collections/tests'], function(Backbone, io, Tests) {
return Backbone.Model.extend({
defaults: {
'webPage': 'http://www.tingtun.no/',
'state': 'loading',
'tests': [],
'currentTest': 0
},
initialize: function(socket) {
var that;
_.extend(this, Backbone.Events);
this.set('socket', socket);
socket.emit('get tests', this.get('webPage'));
that = this;
socket.on('tests', function(data) {
if (data === null) {
return that.set('state', 'error');
} else {
that.set('tests', new Tests(data));
return that.set('state', 'loaded');
}
});
return this.bind('change:webPage', this.fetchTests, this);
},
verifyTests: function() {
return this.get('tests').where({
category: 'verify'
});
},
nextTest: function() {
return this.set('currentTest', this.get('currentTest') + 1);
},
previousTest: function() {
return this.set('currentTest', this.get('currentTest') - 1);
},
getCurrentTest: function() {
if (this.get('tests').length === 0) {
return null;
} else {
return this.verifyTests()[this.get('currentTest')];
}
},
fetchTests: function() {
this.set('state', 'loading');
return this.get('socket').emit('get tests', this.get('webPage'));
},
testCount: function() {
return Math.min(this.verifyTests().length, 10);
},
progress: function() {
return parseInt((this.get('currentTest') / (this.testCount() - 1)) * 100);
},
isAtLast: function() {
return this.get('currentTest') === (this.testCount() - 1);
},
isAtFirst: function() {
return this.get('currentTest') === 0;
},
setAnswer: function(answer) {
this.verifyTests()[this.get('currentTest')].set('answer', answer);
return this.trigger('change:answer');
},
setWebPage: function(url) {
var addProtocol;
addProtocol = function(url) {
if (url.substring(0, 7) !== 'http://' && url.substring(0, 8) !== 'https://') {
return 'http://' + url;
} else {
return url;
}
};
return this.set('webPage', addProtocol(url));
}
});
});
}).call(this);