~bac/juju-gui/1103207

« back to all changes in this revision

Viewing changes to test/test_panzoom.js

  • Committer: Matthew Scott
  • Date: 2013-01-09 17:23:33 UTC
  • mfrom: (307 juju-gui)
  • mto: This revision was merged to the branch mainline in revision 312.
  • Revision ID: matthew.scott@canonical.com-20130109172333-ad6ndevmn5p44dz0
Merging with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    db = new models.Database();
27
27
    var view = new views.environment({container: viewContainer, db: db});
28
28
    view.render();
29
 
    view.postRender();
 
29
    view.rendered();
30
30
    pz = view.topo.modules.PanZoomModule;
31
31
    topo = pz.get('component');
32
32
    vis = topo.vis;
33
33
  });
34
34
 
35
35
  afterEach(function() {
36
 
    viewContainer.remove(true);
 
36
    if (viewContainer) {
 
37
      viewContainer.remove(true);
 
38
    }
37
39
  });
38
40
 
39
 
  it('should set initial values',
40
 
      function() {
41
 
        pz._translate.should.eql([0, 0]);
42
 
        pz._scale.should.equal(1.0);
43
 
      });
44
 
 
45
41
  // Test the zoom handler calculations.
46
42
  it('should handle fractional values properly in zoom scale',
47
43
     function() {
52
48
         rescaleCalled = true;
53
49
       };
54
50
       pz.zoomHandler(evt);
55
 
       pz.slider.get('value').should.equal(60);
 
51
       pz.slider.get('value').should.equal(61);
56
52
       assert.isTrue(rescaleCalled);
57
53
     });
58
54
 
82
78
 
83
79
  // Test the zoom calculations.
84
80
  it('should handle fractional values within the limit for rescale',
85
 
     function(done) {
 
81
     function() {
86
82
       // Floor is used so the scale will round down.
87
83
       var evt =
88
84
           { scale: 0.609,
89
 
             translate: 't'};
 
85
             translate: [0, 0]};
90
86
       var rescaled = false;
91
87
       topo.once('rescaled', function() {
92
88
         rescaled = true;
93
 
         done();
94
89
       });
95
 
       pz.rescale(vis, evt);
96
 
       pz._scale.should.equal(0.609);
 
90
       pz.rescale(evt);
 
91
       topo.get('scale').should.equal(0.609);
97
92
       var expected = 'translate(' + evt.translate + ') scale(0.609)';
98
93
       vis.attr('transform').should.equal(expected);
99
94
       assert.isTrue(rescaled);
100
95
     });
101
96
 
102
97
  it('should set an upper limit for rescale',
103
 
     function(done) {
 
98
     function() {
104
99
       var evt =
105
100
           { scale: 2.1,
106
 
             translate: 'u'};
 
101
             translate: [0, 0]};
107
102
       var rescaled = false;
108
103
       topo.once('rescaled', function() {
109
104
         rescaled = true;
110
 
         done();
111
105
       });
112
 
       topo.set('scale', 2.0);
113
 
       pz.rescale(vis, evt);
114
 
       pz._scale.should.equal(2.0);
 
106
       pz.rescale(evt);
 
107
       topo.get('scale').should.equal(2.0);
115
108
       var expected = 'translate(' + evt.translate + ') scale(2)';
116
109
       vis.attr('transform').should.equal(expected);
117
110
       assert.isTrue(rescaled);
118
111
     });
119
112
 
120
113
  it('should set a lower limit for rescale',
121
 
     function(done) {
 
114
     function() {
122
115
       var evt =
123
116
           { scale: 0.2,
124
 
             translate: 'v'};
 
117
             translate: [0, 0]};
125
118
       var rescaled = false;
126
119
       topo.once('rescaled', function() {
127
120
         rescaled = true;
128
 
         done();
129
121
       });
130
 
       topo.set('scale', 0.25);
131
 
       pz.rescale(vis, evt);
132
 
       pz._scale.should.equal(0.25);
 
122
       pz.rescale(evt);
 
123
       topo.get('scale').should.equal(0.25);
133
124
       var expected = 'translate(' + evt.translate + ') scale(0.25)';
134
125
       vis.attr('transform').should.equal(expected);
135
126
       assert.isTrue(rescaled);