~bcsaller/juju-gui/viewmodel-improvements

« back to all changes in this revision

Viewing changes to test/test_environment_view.js

  • Committer: Benjamin Saller
  • Author(s): Benjamin Saller
  • Date: 2013-01-21 17:08:41 UTC
  • mfrom: (328.2.9 persistent-layout)
  • Revision ID: bcsaller@gmail.com-20130121170841-v93vkqfxgtgyfwuu
Tags: 0.1.5
Support for service positions from server

Provides support for loading initial and updated position 
from annotations stored on the server. Updates occur
via a shared codepath with the drag event handler
to ensure proper updates are applied over time.

There is still an issue with deltas interrupting the drag.

R=gary.poster, frankban
CC=
https://codereview.appspot.com/7132061

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
        ['service', 'add', {
12
12
          'charm': 'cs:precise/wordpress-6',
13
13
          'id': 'wordpress',
14
 
          'exposed': false
 
14
          'exposed': false,
 
15
          'annotations': {'gui.x': 100, 'gui.y': 200}
15
16
        }],
16
17
        ['service', 'add', {
17
18
          'charm': 'cs:precise/mediawiki-3',
92
93
        env = new juju.Environment({conn: conn});
93
94
        env.connect();
94
95
        conn.open();
95
 
        env.dispatch_result(environment_delta);
96
96
        done();
97
97
      });
98
98
    });
102
102
      done();
103
103
    });
104
104
 
105
 
    beforeEach(function(done) {
 
105
    beforeEach(function() {
106
106
      container = Y.Node.create('<div />').setStyle('visibility', 'hidden');
107
107
      Y.one('body').prepend(container);
108
108
      db = new models.Database();
109
 
      db.on_delta({data: environment_delta});
110
 
      done();
 
109
      // Use a clone to avoid any mutation
 
110
      // to the input set (as happens with processed
 
111
      // annotations, its a direct reference).
 
112
      db.on_delta({data: Y.clone(environment_delta)});
111
113
    });
112
114
 
113
115
    afterEach(function(done) {
396
398
      });
397
399
    });
398
400
 
 
401
    it('must be able to use position annotations',
 
402
       function() {
 
403
         var view = new views.environment({
 
404
           container: container,
 
405
           db: db,
 
406
           env: env
 
407
         });
 
408
         var tmp_data = {
 
409
           op: 'delta',
 
410
           result: [
 
411
             ['service', 'add',
 
412
               {
 
413
                 'subordinate': true,
 
414
                 'charm': 'cs:precise/wordpress-6',
 
415
                 'id': 'wordpress',
 
416
                 'annotations': {'gui.x': 374.1, 'gui.y': 211.2}
 
417
               }]]};
 
418
         var properTransform = /translate\((\d+\.?\d*),(\d+\.?\d*)\)/;
 
419
         var node, match;
 
420
 
 
421
         view.render();
 
422
 
 
423
         // Test values from initial load.
 
424
         node = view.topo.modules.ServiceModule.getServiceNode('wordpress');
 
425
         match = node.getAttribute('transform').match(properTransform);
 
426
         match[1].should.eql('100');
 
427
         match[2].should.eql('200');
 
428
 
 
429
         db.on_delta({ data: tmp_data });
 
430
         view.update();
 
431
 
 
432
         //On annotation change  position should be updated.
 
433
         match = node.getAttribute('transform').match(properTransform);
 
434
         match[1].should.eql('374.1');
 
435
         match[2].should.eql('211.2');
 
436
       });
 
437
 
399
438
    it('must be able to render subordinate relation indicators',
400
439
       function() {
401
440
         var view = new views.environment({