staroff_spec.js
2.29 KB
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
describe('#numberMax', function() {
beforeEach(function() {
$.fn.raty.defaults.path = '../lib/images';
this.el = Helper.create('#el');
});
afterEach(function() {
Helper.clear();
});
it ('changes the stars off', function() {
// given
var self = this.el;
// when
self.raty({ starOff: 'star-half.png' });
// then
expect(self.children('img')).toHaveAttr('src', '../lib/images/star-half.png');
});
context('with :starType', function() {
it ('uses the given element', function() {
// given
var self = this.el;
// when
self.raty({ starType: 'i' });
// then
var stars = self.children('i');
expect(stars[0].tagName).toEqual('I');
expect(stars[1].tagName).toEqual('I');
expect(stars[2].tagName).toEqual('I');
expect(stars[3].tagName).toEqual('I');
expect(stars[4].tagName).toEqual('I');
});
it ('normalizes the class name', function() {
// given
var self = this.el;
// when
self.raty({ starType: 'i' });
// then
expect(self.children('i')).toHaveClass('star-off-png');
});
it ('does not create the "src" attribute', function() {
// given
var self = this.el;
// when
self.raty({ starType: 'i' });
// then
var stars = self.children('i');
expect(stars[0].src).toBeUndefined();
expect(stars[1].src).toBeUndefined();
expect(stars[2].src).toBeUndefined();
expect(stars[3].src).toBeUndefined();
expect(stars[4].src).toBeUndefined();
});
it ('creates the "data-alt" attribute', function() {
// given
var self = this.el;
// when
self.raty({ starType: 'i' });
// then
var stars = self.children('i');
expect(stars[0].getAttribute('data-alt')).toEqual('1');
expect(stars[1].getAttribute('data-alt')).toEqual('2');
expect(stars[2].getAttribute('data-alt')).toEqual('3');
expect(stars[3].getAttribute('data-alt')).toEqual('4');
expect(stars[4].getAttribute('data-alt')).toEqual('5');
});
it ('does not create the "alt" attribute', function() {
// given
var self = this.el;
// when
self.raty({ starType: 'i' });
// then
expect(self.children('i')).not.toHaveAttr('alt');
});
});
});