forked from ludofischer/mocha-chai-browser-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
109 lines (94 loc) · 3.7 KB
/
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var expect = chai.expect;
var formMarkup = '<div id="fixture"><form id="testForm"> <select id="testSelect">' +
'<option> Hello </option> </select>' +
'<input type="hidden" name="contest.question1" value="some bad question"/>' +
'<input type="text" id="contestInput" name="contest.answer1"/>' +
'<input type="hidden" name="contest.question2" value="some bad question"/>' +
'<select name="contest.answer2"> <option>Good</option>' +
'<option id="contestOption">Great</option> </select>' +
'<input type="hidden" name="contest.question3" value="some bad question"/>' +
'<input type="text" id="badQuizAnswer" name="contest.answer3"/></form></div>';
describe('Utilities', function() {
'use strict';
var ourQuiz;
var contestData = {
question1: 'How Are you?',
answer1: 'Fine, thanks.',
question2: 'Status',
answer2: 'Great',
question3: 'Who is the greatest painter?',
answer3: 'Raphael'
};
before(function() {
ourQuiz = new Quiz(contestData);
jQuery('body').append(formMarkup);
});
after(function() {
jQuery('#fixture').remove();
});
it('should correctly list data', function() {
expect(ourQuiz.isSelect('select')).to.be.true;
expect(ourQuiz.isSelect('input')).to.be.false;
expect(ourQuiz.isInput('input')).to.be.true;
expect(ourQuiz.isSelect('input')).to.be.false;
});
it('should select the correct option', function() {
var select = document.getElementById('testSelect');
ourQuiz.prefillSelect(select, 'Hello');
expect(select.children[0].selected).to.be.true;
});
it('should identify matching questions', function() {
expect(ourQuiz.questionMatches(1, contestData.question1)).to.be.true;
});
it('should identify non-matching questions', function() {
expect(ourQuiz.questionMatches(1, contestData.question1 + 'blah')).to.be.false;
});
});
describe('Main function', function() {
'use strict';
var ourQuiz, form;
var contestData = {
question1: 'How Are you?',
answer1: 'Fine, thanks.',
question2: 'Status',
answer2: 'Great',
question3: 'Who is the greatest painter?',
answer3: 'Raphael'
};
before(function() {
ourQuiz = new Quiz(contestData);
form = jQuery('body').append(formMarkup);
});
after(function() {
jQuery('#fixture').remove();
});
beforeEach(function() {
document.getElementById('contestOption').value = contestData.answer2;
jQuery('input[name="contest.question1"]').val(contestData.question1);
jQuery('input[name="contest.question2"]').val(contestData.question2);
ourQuiz.prefillQuizForm(form);
});
it('should fill the text fields that correspond to an answer', function() {
expect(document.getElementById('contestInput').value).to.equal(contestData.answer1);
});
it('should select the options that correspond to an answer', function() {
expect(document.getElementById('contestOption').selected).to.be.true;
});
it('should skip fields where the question has changed', function() {
expect(document.getElementById('badQuizAnswer').value).to.be.empty;
});
});
describe('Initialization', function() {
'use strict';
it('should initialize the main object', function() {
var contestData = {
question1: 'How Are you?',
answer1: 'Fine, thanks.',
question2: 'Status',
answer2: 'Great',
question3: 'Who is the greatest painter?',
answer3: 'Raphael'
};
var contest = new Quiz(contestData);
});
});