summaryrefslogtreecommitdiff
path: root/tests/frontend/specs/redo.js
blob: caa32feec7d4bca4a9466de425d8278cb25e9d73 (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
describe("undo button then redo button", function(){
  beforeEach(function(cb){
    helper.newPad(cb); // creates a new pad
    this.timeout(60000);
  });

  it("redo some typing with button", function(done){
    var inner$ = helper.padInner$;
    var chrome$ = helper.padChrome$;
    
    // get the first text element inside the editable space
    var $firstTextElement = inner$("div span").first();
    var originalValue = $firstTextElement.text(); // get the original value
    var newString = "Foo";

    $firstTextElement.sendkeys(newString); // send line 1 to the pad
    var modifiedValue = $firstTextElement.text(); // get the modified value
    expect(modifiedValue).not.to.be(originalValue); // expect the value to change

    // get undo and redo buttons
    var $undoButton = chrome$(".buttonicon-undo");
    var $redoButton = chrome$(".buttonicon-redo");
    // click the buttons
    $undoButton.click(); // removes foo
    $redoButton.click(); // resends foo

    helper.waitFor(function(){
      console.log(inner$("div span").first().text());
      return inner$("div span").first().text() === newString;
    }).done(function(){
      var finalValue = inner$("div").first().text();
      expect(finalValue).to.be(modifiedValue); // expect the value to change
      done();
    });
  });

  it("redo some typing with keypress", function(done){
    var inner$ = helper.padInner$;
    var chrome$ = helper.padChrome$;

    // get the first text element inside the editable space
    var $firstTextElement = inner$("div span").first();
    var originalValue = $firstTextElement.text(); // get the original value
    var newString = "Foo";

    $firstTextElement.sendkeys(newString); // send line 1 to the pad
    var modifiedValue = $firstTextElement.text(); // get the modified value
    expect(modifiedValue).not.to.be(originalValue); // expect the value to change

    if(inner$(window)[0].bowser.firefox || inner$(window)[0].bowser.modernIE){ // if it's a mozilla or IE  
      var evtType = "keypress";
    }else{
      var evtType = "keydown";
    }

    var e = inner$.Event(evtType);
    e.ctrlKey = true; // Control key
    e.which = 90; // z
    inner$("#innerdocbody").trigger(e);

    var e = inner$.Event(evtType);
    e.ctrlKey = true; // Control key
    e.which = 121; // y
    inner$("#innerdocbody").trigger(e);

    helper.waitFor(function(){
      console.log(inner$("div span").first().text());
      return inner$("div span").first().text() === newString;
    }).done(function(){
      var finalValue = inner$("div").first().text();
      expect(finalValue).to.be(modifiedValue); // expect the value to change
      done();
    });
  });
});