Blame view

frontend/web/js/raty-2.7.0/spec/staron_spec.js 2.24 KB
c7f222e2   Artem   first
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
  describe('#starOn', function() {
    beforeEach(function() {
      $.fn.raty.defaults.path = '../lib/images';
  
      this.el = Helper.create('#el');
    });
  
    afterEach(function() {
      Helper.clear();
    });
  
    context('on mouseover', function() {
      it ('changes the stars on', function() {
        // given
        var self  = this.el.raty({ starOn: 'star-half.png' }),
            stars = self.children('img');
  
        // when
        stars.last().trigger('mouseover');
  
        // then
        expect(stars).toHaveAttr('src', '../lib/images/star-half.png');
      });
  
      context('with :starType', function() {
        it ('uses the given element', function() {
          // given
          var self  = this.el.raty({ starType: 'i' }),
              stars = self.children('i');
  
          // when
          stars.last().trigger('mouseover');
  
          // then
          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.raty({ starType: 'i' }),
              stars = self.children('i');
  
          // when
          stars.last().trigger('mouseover');
  
          // then
          expect(stars).toHaveClass('star-on-png');
        });
  
        it ('does not create "src" attribute', function() {
          // given
          var self  = this.el.raty({ starType: 'i' }),
              stars = self.children('i');
  
          // when
          stars.last().trigger('mouseover');
  
          // then
          expect(stars).not.toHaveAttr('src');
        });
  
        it ('creates "data-alt" attribute', function() {
          // given
          var self  = this.el.raty({ starType: 'i' }),
              stars = self.children('i');
  
          // when
          stars.last().trigger('mouseover');
  
          // then
          expect(stars).toHaveAttr('data-alt');
        });
  
        it ('does not create "alt" attribute', function() {
          // given
          var self  = this.el.raty({ starType: 'i' }),
              stars = self.children('i');
  
          // when
          stars.last().trigger('mouseover');
  
          // then
          expect(stars).not.toHaveAttr('alt');
        });
      });
    });
  });