summaryrefslogtreecommitdiff
path: root/tests/frontend/specs/timeslider_revisions.js
blob: de8ca52f8fcb5d0e853c07e008ab00dd0d7c02c6 (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
describe("timeslider", function(){
  //create a new pad before each test run
  beforeEach(function(cb){
    helper.newPad(cb);
    this.timeout(6000);
  });

  xit("loads adds a hundred revisions", function(done) {
    var inner$ = helper.padInner$; 
    var chrome$ = helper.padChrome$; 
    
    // make some changes to produce 100 revisions
    var timePerRev = 900
      , revs = 100;
    this.timeout(revs*timePerRev+10000);
    for(var i=0; i < revs; i++) {
      setTimeout(function() {
        // enter 'a' in the first text element
        inner$("div").first().sendkeys('a');
      }, timePerRev*i);
    }
    
    setTimeout(function() {
      // go to timeslider
      $('#iframe-container iframe').attr('src', $('#iframe-container iframe').attr('src')+'/timeslider');
      
      setTimeout(function() {
        var timeslider$ = $('#iframe-container iframe')[0].contentWindow.$;
        var $sliderBar = timeslider$('#ui-slider-bar');
        
        var latestContents = timeslider$('#padcontent').text();

        // Click somewhere on the timeslider
        var e = new jQuery.Event('mousedown');
        e.clientX = e.pageX = 150;
        e.clientY = e.pageY = 45;
        $sliderBar.trigger(e);
        
        e = new jQuery.Event('mousedown');
        e.clientX = e.pageX = 150;
        e.clientY = e.pageY = 40;
        $sliderBar.trigger(e);
        
        e = new jQuery.Event('mousedown');
        e.clientX = e.pageX = 150;
        e.clientY = e.pageY = 50;
        $sliderBar.trigger(e);
        
        $sliderBar.trigger('mouseup')

        setTimeout(function() {
          //make sure the text has changed
          expect( timeslider$('#padcontent').text() ).not.to.eql( latestContents );
          done();
        }, 1000);
        
      }, 6000);
    }, revs*timePerRev);
  });
  
  it("changes the url when clicking on the timeslider", function(done) {
    var inner$ = helper.padInner$; 
    var chrome$ = helper.padChrome$; 
    
    // make some changes to produce 7 revisions
    var timePerRev = 900
      , revs = 7;
    this.timeout(revs*timePerRev+10000);
    for(var i=0; i < revs; i++) {
      setTimeout(function() {
        // enter 'a' in the first text element
        inner$("div").first().sendkeys('a');
      }, timePerRev*i);
    }
    
    setTimeout(function() {
      // go to timeslider
      $('#iframe-container iframe').attr('src', $('#iframe-container iframe').attr('src')+'/timeslider');
      
      setTimeout(function() {
        var timeslider$ = $('#iframe-container iframe')[0].contentWindow.$;
        var $sliderBar = timeslider$('#ui-slider-bar');
        
        var latestContents = timeslider$('#padcontent').text();
        
        var oldUrl = $('#iframe-container iframe')[0].contentWindow.location.hash;
        
        // Click somewhere on the timeslider
        var e = new jQuery.Event('mousedown');
        e.clientX = e.pageX = 150;
        e.clientY = e.pageY = 60;
        $sliderBar.trigger(e);
        
        helper.waitFor(function(){
          return $('#iframe-container iframe')[0].contentWindow.location.hash != oldUrl;
        }, 6000).always(function(){
          expect( $('#iframe-container iframe')[0].contentWindow.location.hash ).not.to.eql( oldUrl );
          done();
        });
      }, 6000);
    }, revs*timePerRev);
  });
  
  it("jumps to a revision given in the url", function(done) {
    var inner$ = helper.padInner$; 
    var chrome$ = helper.padChrome$; 
    this.timeout(11000);
    inner$("div").first().sendkeys('a');
    
    setTimeout(function() {
      // go to timeslider
      $('#iframe-container iframe').attr('src', $('#iframe-container iframe').attr('src')+'/timeslider#0');
      var timeslider$;
      
      helper.waitFor(function(){
        timeslider$ = $('#iframe-container iframe')[0].contentWindow.$;
        return timeslider$ && timeslider$('#padcontent').text().length == 230;
      }, 6000).always(function(){
        expect( timeslider$('#padcontent').text().length ).to.eql( 230 );
        done();
      });
    }, 2500);
  });
});