Blame view

frontend/web/js/raty-2.7.0/spec/stars_spec.js 2.11 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
92
  describe('stars', function() {
    beforeEach(function() {
      $.fn.raty.defaults.path = '../lib/images';
  
      this.el = Helper.create('#el');
    });
  
    afterEach(function() {
      Helper.clear();
    });
  
    it ('starts all off', function() {
      // given
      var self = this.el;
  
      // when
      self.raty();
  
      // then
      expect(self.children('img')).toHaveAttr('src', '../lib/images/star-off.png');
    });
  
    context('on click', function() {
      it ('changes the score', function() {
        // given
        var self  = this.el.raty(),
            stars = self.children('img');
  
        // when
        stars.last().trigger('click');
  
        // then
        expect(self.children('input')).toHaveValue('5');
      });
    });
  
    context('on mouseover', function() {
      it ('turns on the stars', function() {
        // given
        var self  = this.el.raty(),
            stars = self.children('img');
  
        // when
        stars.last().trigger('mouseover');
  
        // then
        expect(stars).toHaveAttr('src', '../lib/images/star-on.png');
      });
  
      context('and mouseout', function() {
        it ('turns off all stars', function() {
          // given
          var self  = this.el.raty(),
              stars = self.children('img');
  
          // when
          stars.last().trigger('mouseover').trigger('mouseout');
  
          // then
          expect(stars).toHaveAttr('src', '../lib/images/star-off.png');
        });
      });
  
      context('and click', function() {
        it ('changes the score', function() {
          // given
          var self  = this.el.raty(),
              stars = self.children('img');
  
          // when
          stars.last().trigger('mouseover').trigger('click');
  
          // then
          expect(self.children('input')).toHaveValue('5');
        });
  
        context('and mouseout', function() {
          it ('keeps the stars on', function() {
            // given
            var self  = this.el.raty(),
                stars = self.children('img');
  
            // when
            stars.last().trigger('mouseover').trigger('click').trigger('mouseout');
  
            // then
            expect(stars).toHaveAttr('src', '../lib/images/star-on.png');
          });
        });
      });
    });
  });