<commit_before>
var http = require('http').Server;
var io = require('..');
var ioc = require('socket.io-client');
var request = require('supertest');
var expect = require('expect.js');

// creates a socket.io client for the given server
function client(srv, nsp){
  var addr = srv.address();
  if (!addr) addr = srv.listen().address();
  return ioc('ws://' + addr.address + ':' + addr.port + (nsp || ''));
}

describe('socket.io', function(){
  describe('server attachment', function(){
    describe('http.Server', function(){
      it('should serve static files', function(done){
        var srv = http();
        io(srv);
        request(srv)
        .get('/socket.io/socket.io.js')
        .buffer(true)
        .end(function(err, res){
          if (err) return done(err);
          var ctype = res.headers['content-type'];
          expect(ctype).to.be('application/javascript');
          expect(res.text).to.match(/engine\.io/);
          expect(res.status).to.be(200);
          done();
        });
      });

      it('should not serve static files', function(done){
        var srv = http();
        io(srv, { static: false });
        request(srv)
        .get('/socket.io/socket.io.js')
        .expect(400, done);
      });

      it('should work with #attach', function(done){
        var srv = http(function(req, res){
          res.writeHead(404);
          res.end();
        });
        var sockets = io();
        sockets.attach(srv);
        request(srv)
        .get('/socket.io/socket.io.js')
        .end(function(err, res){
          if (err) return done(err);
          expect(res.status).to.be(200);
          done();
        });
      });
    });

    describe('port', function(done){
      it('should be bound', function(done){
        var sockets = io(54010);
        request('http://localhost:54010')
        .get('/socket.io/socket.io.js')
        .expect(200, done);
      });
    });
  });

  describe('namespaces', function(){
    var Socket = require('../lib/socket');
    var Namespace = require('../lib/namespace');

    describe('default', function(){
      it('should be accessible through .sockets', function(){
        var sio = io();
        expect(sio.sockets).to.be.a(Namespace);
      });

      it('should be aliased', function(){
        var sio = io();
        expect(sio.use).to.be.a('function');
        expect(sio.to).to.be.a('function');
        expect(sio.in).to.be.a('function');
        expect(sio.emit).to.be.a('function');
        expect(sio.send).to.be.a('function');
        expect(sio.write).to.be.a('function');
      });

      it('should automatically connect', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var socket = client(srv);
          socket.on('connect', function(){
            done();
          });
        });
      });

      it('should fire a `connection` event', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var socket = client(srv);
          sio.on('connection', function(socket){
            expect(socket).to.be.a(Socket);
            done();
          });
        });
      });

      it('should fire a `connect` event', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var socket = client(srv);
          sio.on('connect', function(socket){
            expect(socket).to.be.a(Socket);
            done();
          });
        });
      });

      it('should work with many sockets', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var chat = client(srv, '/chat');
          var news = client(srv, '/news');
          var total = 2;
          chat.on('connect', function(){
            --total || done();
          });
          news.on('connect', function(){
            --total || done();
          });
        });
      });

      it('should work with `of` and many sockets', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var chat = client(srv, '/chat');
          var news = client(srv, '/news');
          var total = 2;
          sio.of('/news').on('connection', function(socket){
            expect(socket).to.be.a(Socket);
            --total || done();
          });
          sio.of('/news').on('connection', function(socket){
            expect(socket).to.be.a(Socket);
            --total || done();
          });
        });
      });

      it('should work with `of` second param', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var chat = client(srv, '/chat');
          var news = client(srv, '/news');
          var total = 2;
          sio.of('/news', function(socket){
            expect(socket).to.be.a(Socket);
            --total || done();
          });
          sio.of('/news', function(socket){
            expect(socket).to.be.a(Socket);
            --total || done();
          });
        });
      });

      it('should disconnect upon transport disconnection', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var chat = client(srv, '/chat');
          var news = client(srv, '/news');
          var total = 2;
          var totald = 2;
          var s;
          sio.of('/news', function(socket){
            socket.on('disconnect', function(reason){
              --totald || done();
            });
            --total || close();
          });
          sio.of('/chat', function(socket){
            s = socket;
            socket.on('disconnect', function(reason){
              --totald || done();
            });
            --total || close();
          });
          function close(){
            s.disconnect(true);
          }
        });
      });
    });
  });

  describe('socket', function(){
    it('should receive events', function(done){
      var srv = http();
      var sio = io(srv);
      srv.listen(function(){
        var socket = client(srv);
        sio.on('connection', function(s){
          s.on('random', function(a, b, c){
            expect(a).to.be(1);
            expect(b).to.be('2');
            expect(c).to.eql([3]);
            done();
          });
          socket.emit('random', 1, '2', [3]);
        });
      });
    });

    it('should receive message events through `send`', function(done){
      var srv = http();
      var sio = io(srv);
      srv.listen(function(){
        var socket = client(srv);
        sio.on('connection', function(s){
          s.on('message', function(a){
            expect(a).to.be(1337);
            done();
          });
          socket.send(1337);
        });
      });
    });

    it('should emit events', function(done){
      var srv = http();
      var sio = io(srv);
      srv.listen(function(){
        var socket = client(srv);
        socket.on('woot', function(a){
          expect(a).to.be('tobi');
          done();
        });
        sio.on('connection', function(s){
          s.emit('woot', 'tobi');
        });
      });
    });
  });
});
<commit_msg>test: added test for event emitting with `send`<commit_after>
var http = require('http').Server;
var io = require('..');
var ioc = require('socket.io-client');
var request = require('supertest');
var expect = require('expect.js');

// creates a socket.io client for the given server
function client(srv, nsp){
  var addr = srv.address();
  if (!addr) addr = srv.listen().address();
  return ioc('ws://' + addr.address + ':' + addr.port + (nsp || ''));
}

describe('socket.io', function(){
  describe('server attachment', function(){
    describe('http.Server', function(){
      it('should serve static files', function(done){
        var srv = http();
        io(srv);
        request(srv)
        .get('/socket.io/socket.io.js')
        .buffer(true)
        .end(function(err, res){
          if (err) return done(err);
          var ctype = res.headers['content-type'];
          expect(ctype).to.be('application/javascript');
          expect(res.text).to.match(/engine\.io/);
          expect(res.status).to.be(200);
          done();
        });
      });

      it('should not serve static files', function(done){
        var srv = http();
        io(srv, { static: false });
        request(srv)
        .get('/socket.io/socket.io.js')
        .expect(400, done);
      });

      it('should work with #attach', function(done){
        var srv = http(function(req, res){
          res.writeHead(404);
          res.end();
        });
        var sockets = io();
        sockets.attach(srv);
        request(srv)
        .get('/socket.io/socket.io.js')
        .end(function(err, res){
          if (err) return done(err);
          expect(res.status).to.be(200);
          done();
        });
      });
    });

    describe('port', function(done){
      it('should be bound', function(done){
        var sockets = io(54010);
        request('http://localhost:54010')
        .get('/socket.io/socket.io.js')
        .expect(200, done);
      });
    });
  });

  describe('namespaces', function(){
    var Socket = require('../lib/socket');
    var Namespace = require('../lib/namespace');

    describe('default', function(){
      it('should be accessible through .sockets', function(){
        var sio = io();
        expect(sio.sockets).to.be.a(Namespace);
      });

      it('should be aliased', function(){
        var sio = io();
        expect(sio.use).to.be.a('function');
        expect(sio.to).to.be.a('function');
        expect(sio.in).to.be.a('function');
        expect(sio.emit).to.be.a('function');
        expect(sio.send).to.be.a('function');
        expect(sio.write).to.be.a('function');
      });

      it('should automatically connect', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var socket = client(srv);
          socket.on('connect', function(){
            done();
          });
        });
      });

      it('should fire a `connection` event', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var socket = client(srv);
          sio.on('connection', function(socket){
            expect(socket).to.be.a(Socket);
            done();
          });
        });
      });

      it('should fire a `connect` event', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var socket = client(srv);
          sio.on('connect', function(socket){
            expect(socket).to.be.a(Socket);
            done();
          });
        });
      });

      it('should work with many sockets', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var chat = client(srv, '/chat');
          var news = client(srv, '/news');
          var total = 2;
          chat.on('connect', function(){
            --total || done();
          });
          news.on('connect', function(){
            --total || done();
          });
        });
      });

      it('should work with `of` and many sockets', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var chat = client(srv, '/chat');
          var news = client(srv, '/news');
          var total = 2;
          sio.of('/news').on('connection', function(socket){
            expect(socket).to.be.a(Socket);
            --total || done();
          });
          sio.of('/news').on('connection', function(socket){
            expect(socket).to.be.a(Socket);
            --total || done();
          });
        });
      });

      it('should work with `of` second param', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var chat = client(srv, '/chat');
          var news = client(srv, '/news');
          var total = 2;
          sio.of('/news', function(socket){
            expect(socket).to.be.a(Socket);
            --total || done();
          });
          sio.of('/news', function(socket){
            expect(socket).to.be.a(Socket);
            --total || done();
          });
        });
      });

      it('should disconnect upon transport disconnection', function(done){
        var srv = http();
        var sio = io(srv);
        srv.listen(function(){
          var chat = client(srv, '/chat');
          var news = client(srv, '/news');
          var total = 2;
          var totald = 2;
          var s;
          sio.of('/news', function(socket){
            socket.on('disconnect', function(reason){
              --totald || done();
            });
            --total || close();
          });
          sio.of('/chat', function(socket){
            s = socket;
            socket.on('disconnect', function(reason){
              --totald || done();
            });
            --total || close();
          });
          function close(){
            s.disconnect(true);
          }
        });
      });
    });
  });

  describe('socket', function(){
    it('should receive events', function(done){
      var srv = http();
      var sio = io(srv);
      srv.listen(function(){
        var socket = client(srv);
        sio.on('connection', function(s){
          s.on('random', function(a, b, c){
            expect(a).to.be(1);
            expect(b).to.be('2');
            expect(c).to.eql([3]);
            done();
          });
          socket.emit('random', 1, '2', [3]);
        });
      });
    });

    it('should receive message events through `send`', function(done){
      var srv = http();
      var sio = io(srv);
      srv.listen(function(){
        var socket = client(srv);
        sio.on('connection', function(s){
          s.on('message', function(a){
            expect(a).to.be(1337);
            done();
          });
          socket.send(1337);
        });
      });
    });

    it('should emit events', function(done){
      var srv = http();
      var sio = io(srv);
      srv.listen(function(){
        var socket = client(srv);
        socket.on('woot', function(a){
          expect(a).to.be('tobi');
          done();
        });
        sio.on('connection', function(s){
          s.emit('woot', 'tobi');
        });
      });
    });

    it('should emit message events through `send`', function(done){
      var srv = http();
      var sio = io(srv);
      srv.listen(function(){
        var socket = client(srv);
        socket.on('message', function(a){
          expect(a).to.be('a');
          done();
        });
        sio.on('connection', function(s){
          s.send('a');
        });
      });
    });
  });
});
<|endoftext|>


<commit_before>define('spec/math', ['lyria/math'], function(Math) {

  describe('lyria/math', function() {

    it('is an object', function() {
      expect(Math).to.be.a('object');
    });

    it('.random', function() {
      expect(Math).to.have.property('random');
      expect(Math.random).to.be.a('function');
    });

    it('.clamp', function() {
      expect(Math).to.have.property('clamp');
      expect(Math.clamp).to.be.a('function');
    });

    it('.fisherYates', function() {
      expect(Math).to.have.property('fisherYates');
      expect(Math.fisherYates).to.be.a('function');
    });

  });

});
<commit_msg>Deleted lyria/math unit test<commit_after><|endoftext|>


<commit_before>describe('type', () => {

  afterEach(() => {
    fixture.cleanup();
  });

  describe('labels', () => {

    beforeEach(() => {
      fixture.load('type/labels.html');
    });

    describe('default', () => {

      it('should match the design spec', () => {
        assertCssPropertiesAreEqual(getElementById('label'), [
          ['color', 'rgb(35, 31, 32)'],
          ['font-size', '14px'],
          ['line-height', '16px'],
          ['font-weight', ['normal', '400']]
        ]);
      });
    });

    describe('secondary', () => {

      it('should match the design spec', () => {
        assertCssPropertiesAreEqual(getElementById('label-secondary'), [
          ['color', 'rgb(86, 86, 86)'],
          ['font-size', '14px'],
          ['line-height', '16px'],
          ['font-weight', ['normal', '400']]
        ]);
      });
    });

    describe('sizes', () => {

      it('should match the design spec when the label is small', () => {
        assertCssPropertiesAreEqual(getElementById('label-small'), [
          ['font-size', ['13px', '13.008px']],
          ['line-height', '15px']
        ]);
      });

      it('should match the design spec when the label is large', () => {
        assertCssPropertiesAreEqual(getElementById('label-large'), [
          ['font-size', '16px'],
          ['line-height', '18px']
        ]);
      });
    });

    describe('weights', () => {

      it('should match the design spec when the weight is bold', () => {
        assertCssPropertiesAreEqual(getElementById('label-bold'), [
          ['font-weight', ['bold', '700']]
        ]);
      });
    });

    describe('inverse', () => {

      it('should match the design spec', () => {
        assertCssPropertiesAreEqual(getElementById('label-inverse'), [
          ['color', 'rgb(255, 255, 255)']
        ]);
      });

      it('should match the design spec when it is a secondary label', () => {
        assertCssPropertiesAreEqual(getElementById('label-secondary-inverse'), [
          ['color', 'rgb(174, 174, 174)']
        ]);
      });

      it('should match the design spec with inverse weight it light', () => {
        assertCssPropertiesAreEqual(getElementById('label-inverse-weight'),[
          ['font-weight',['light','300']]
          ]);
      });
    });
  });

  //Titles
  describe('titles', () => {

    beforeEach(() => {
      fixture.load('type/titles.html');
    });

    describe('sizes and height',() => {

      it('should match the design spec where it is a default title',() => {
        assertCssPropertiesAreEqual(getElementById('default-title'),[
          ['font-size','18px'],
          ['line-height','22px']
          ]);
      });

      it('should match the design spec where it is a large title',() => {
        assertCssPropertiesAreEqual(getElementById('large-title'),[
          ['font-size','20px'],
          ['line-height','24px']
          ]);
      });

      it('should match the design spec where it is a XLarge title',() => {
        assertCssPropertiesAreEqual(getElementById('XLarge-title'),[
          ['font-size','22px'],
          ['line-height','28px']
          ]);
      });
      //Tests to be added: for  @media (min-width)
    });
  });

  //Copy
  describe('copy',() => {

    beforeEach(() => {
      fixture.load('type/copy.html');
    });

    describe('copy',() => {

      it('should match the design spec where it is a copy',() => {
        assertCssPropertiesAreEqual(getElementById('copy'),[
          ['font-size','16px'],
          ['line-height','22px'],
          ['color','rgb(35, 31, 32)']
          ]);
      });
    });
  });

  //Lead
  describe('leads',() => {

    beforeEach(() => {
      fixture.load('type/lead.html');
    });

    describe('lead',() => {

      it('should match the design spec where it is a lead',() => {
        assertCssPropertiesAreEqual(getElementById('lead'),[
          ['font-size','18px'],
          ['line-height','24px'],
          ['color','rgb(35, 31, 32)'],
          ['font-weight','200']
          ]);
      });
      //Tests to be added: for  @media (min-width)
    });
  });

  //Inline Elements
  describe('Inline Elements',() => {

    beforeEach(() => {
      fixture.load('type/inline.html');
    });

    describe('mark',() => {

      it('should match the design spec where it is mark',() => {
        assertCssPropertiesAreEqual(getElementById('inline-mark'),[
          ['background-color','rgb(253, 236, 46)']
          ]);
      });
    });

    it('should match the design spec where it is subscript',() => {
      assertCssPropertiesAreEqual(getElementById('subscript'),[
        ['font-size',['14px','14.4px']],
        ['top',['3px','3.2px']],
        ['position','relative']
        ]);
    });

    it('should match the design spec where it is superscript',() => {
      assertCssPropertiesAreEqual(getElementById('supscript'),[
        ['font-size',['14px','14.4px']],
        ['top',['-3px','-3.2px']],
        ['position','relative']
        ]);
    });

    it('should match the design spec where it is abbr', () => {
      assertCssPropertiesAreEqual(getElementById('abbr'),[
        ['border-bottom-width','1px'],
        ['border-bottom-style','dotted']
        ]);
      });

    it('should match the design spec where it is strikethrough',() => {
       assertCssPropertiesAreEqual(getElementById('strikethrough'),[
        ['color','rgb(86, 86, 86)']
        ]);
    });

    it('should match the design spec where it is smallTag',() => {
      assertCssPropertiesAreEqual(getElementById('smallTag'),[
        ['font-size','16px']
        ]);
    });

    it('should match the design spec where it is timeTag',() => {
      assertCssPropertiesAreEqual(getElementById('timeTag'),[
        ['font-size','16px'],
        ['line-height','22px'],
        ['color','rgb(35, 31, 32)']
        ]);
    });

    it('should match the design spec where it is emTag',() => {
      assertCssPropertiesAreEqual(getElementById('emTag'),[
        ['font-style','italic'],
        ['font-size','16px'],
        ['line-height','22px'],
        ['color','rgb(35, 31, 32)']
        ]);
    });

    it('should match the design spec where it is iTag',() => {
      assertCssPropertiesAreEqual(getElementById('iTag'),[
        ['font-style','italic'],
        ['font-size','16px'],
        ['line-height','22px'],
        ['color','rgb(35, 31, 32)']
        ]);
    });

    it('should match the design spec where it is bTag',() => {
      assertCssPropertiesAreEqual(getElementById('bTag'),[
        ['font-weight','bold'],
        ]);
    });

    it('should match the design spec where it is strongTag',() => {
      assertCssPropertiesAreEqual(getElementById('strongTag'),[
        ['font-weight','bold'],
        ]);
    });

    it('should match the design spec where it is delTag',() => {
      assertCssPropertiesAreEqual(getElementById('delTag'),[
        ['text-decoration','line-through'],
        ]);
    });

    it('should match the design spec where it is insTag',() => {
      assertCssPropertiesAreEqual(getElementById('insTag'),[
        ['text-decoration','underline'],
        ]);
    });

    it('should match the design spec where it is insTag: before',() => {
      //did not want to disturb the common library(assertCssPropertiesAreEqual)
      var symb = window.getComputedStyle(document.querySelector('ins'),':before').getPropertyValue('content');
      expect(symb).to.equal('\'+\'');
    });

    it('should match the design spec where it is insTag: after',() => {
      //did not want to disturb the common library(assertCssPropertiesAreEqual)
      var symb = window.getComputedStyle(document.querySelector('ins'),':after').getPropertyValue('content');
      expect(symb).to.equal('\'+\'');
    });

    it('should match the design spec where it is quote',() => {
      assertCssPropertiesAreEqual(getElementById('qTag'),[
        ['display','inline']
        ]);
    });
  });

  //Lists
  describe('Lists',() => {

    beforeEach(() => {
      fixture.load('type/lists.html');
    });

    it('should match the design spec where it is unstyled lists',() => {
      assertCssPropertiesAreEqual(getElementById('unstyled-lists'),[
        ['padding-left','0px'],
        ['list-style-type','none']
        ]);
      });

    it('should match the design spec where it is nested unstyled lists',() => {
      assertCssPropertiesAreEqual(getElementById('nested-unstyled-lists'),[
        ['padding-left','0px'],
        ['list-style-type','none']
        ]);
      });

    it('should match the design spec where it is Inline lists',() => {
      assertCssPropertiesAreEqual(getElementById('inline-lists'),[
        ['padding-left','0px'],
        ['list-style-type','none'],
        ['margin-left','-5px']
        ]);
      });
    //one more test to add for inline list pe-list--inline > li
  });

  //Code
  describe('Lists',() => {

    beforeEach(() => {
      fixture.load('type/code.html');
    });

    it('should match the design spec where it is inline code',() => {
      assertCssPropertiesAreEqual(getElementById('inline-code'),[
        ['color','rgb(84, 84, 84)'],
        ['font-size','16px'],
        ['font-family','\'Lucida Sans Typewriter\', \'Lucida Console\', monaco, \'Bitstream Vera Sans Mono\', monospace']
        ]);
      });

    it('should match the design spec where it is Block code',() => {
      assertCssPropertiesAreEqual(getElementById('block-code'),[
        ['display','block'],
        ['overflow-x','auto'],
        ['overflow-y','auto'],
        ['font-size','16px'],
        ['font-family','\'Lucida Sans Typewriter\', \'Lucida Console\', monaco, \'Bitstream Vera Sans Mono\', monospace']
        ]);
      });

    it('should match the design spec where it is user input',() => {
      assertCssPropertiesAreEqual(getElementById('user-input'),[
        ['background-color','rgb(51, 51, 51)'],
        ['color','rgb(255, 255, 255)'],
        ['border-bottom-left-radius','3px'],
        ['border-bottom-right-radius','3px'],
        ['border-top-left-radius','3px'],
        ['border-top-right-radius','3px'],
        ['box-sizing','border-box'],
        ['padding-bottom','2px'],
        ['padding-top','2px'],
        ['padding-left','4px'],
        ['padding-right','4px'],
        ['font-family','\'Lucida Sans Typewriter\', \'Lucida Console\', monaco, \'Bitstream Vera Sans Mono\', monospace']
        ]);
      });
  });
});<commit_msg>Eajaz' fix image line<commit_after>describe('type', () => {

  afterEach(() => {
    fixture.cleanup();
  });

  describe('labels', () => {

    beforeEach(() => {
      fixture.load('type/labels.html');
    });

    describe('default', () => {

      it('should match the design spec', () => {
        assertCssPropertiesAreEqual(getElementById('label'), [
          ['color', 'rgb(35, 31, 32)'],
          ['font-size', '14px'],
          ['line-height', '16px'],
          ['font-weight', ['normal', '400']]
        ]);
      });
    });

    describe('secondary', () => {

      it('should match the design spec', () => {
        assertCssPropertiesAreEqual(getElementById('label-secondary'), [
          ['color', 'rgb(86, 86, 86)'],
          ['font-size', '14px'],
          ['line-height', '16px'],
          ['font-weight', ['normal', '400']]
        ]);
      });
    });

    describe('sizes', () => {

      it('should match the design spec when the label is small', () => {
        assertCssPropertiesAreEqual(getElementById('label-small'), [
          ['font-size', ['13px', '13.008px']],
          ['line-height', '15px']
        ]);
      });

      it('should match the design spec when the label is large', () => {
        assertCssPropertiesAreEqual(getElementById('label-large'), [
          ['font-size', '16px'],
          ['line-height', '18px']
        ]);
      });
    });

    describe('weights', () => {

      it('should match the design spec when the weight is bold', () => {
        assertCssPropertiesAreEqual(getElementById('label-bold'), [
          ['font-weight', ['bold', '700']]
        ]);
      });
    });

    describe('inverse', () => {

      it('should match the design spec', () => {
        assertCssPropertiesAreEqual(getElementById('label-inverse'), [
          ['color', 'rgb(255, 255, 255)']
        ]);
      });

      it('should match the design spec when it is a secondary label', () => {
        assertCssPropertiesAreEqual(getElementById('label-secondary-inverse'), [
          ['color', 'rgb(174, 174, 174)']
        ]);
      });

      it('should match the design spec with inverse weight it light', () => {
        assertCssPropertiesAreEqual(getElementById('label-inverse-weight'),[
          ['font-weight',['light','300']]
          ]);
      });
    });
  });

  //Titles
  describe('titles', () => {

    beforeEach(() => {
      fixture.load('type/titles.html');
    });

    describe('sizes and height',() => {

      it('should match the design spec where it is a default title',() => {
        assertCssPropertiesAreEqual(getElementById('default-title'),[
          ['font-size','18px'],
          ['line-height','22px']
          ]);
      });

      it('should match the design spec where it is a large title',() => {
        assertCssPropertiesAreEqual(getElementById('large-title'),[
          ['font-size','20px'],
          ['line-height','24px']
          ]);
      });

      it('should match the design spec where it is a XLarge title',() => {
        assertCssPropertiesAreEqual(getElementById('XLarge-title'),[
          ['font-size','22px'],
          ['line-height','28px']
          ]);
      });
      //Tests to be added: for  @media (min-width)
    });
  });

  //Copy
  describe('copy',() => {

    beforeEach(() => {
      fixture.load('type/copy.html');
    });

    describe('copy',() => {

      it('should match the design spec where it is a copy',() => {
        assertCssPropertiesAreEqual(getElementById('copy'),[
          ['font-size','16px'],
          ['line-height','22px'],
          ['color','rgb(35, 31, 32)']
          ]);
      });
    });
  });

  //Lead
  describe('leads',() => {

    beforeEach(() => {
      fixture.load('type/lead.html');
    });

    describe('lead',() => {

      it('should match the design spec where it is a lead',() => {
        assertCssPropertiesAreEqual(getElementById('lead'),[
          ['font-size','18px'],
          ['line-height','24px'],
          ['color','rgb(35, 31, 32)'],
          ['font-weight','200']
          ]);
      });
      //Tests to be added: for  @media (min-width)
    });
  });

  //Inline Elements
  describe('inline elements',() => {

    beforeEach(() => {
      fixture.load('type/inline.html');
    });

    describe('mark',() => {

      it('should match the design spec where it is mark',() => {
        assertCssPropertiesAreEqual(getElementById('inline-mark'),[
          ['background-color','rgb(253, 236, 46)']
          ]);
      });
    });

    it('should match the design spec where it is subscript',() => {
      assertCssPropertiesAreEqual(getElementById('subscript'),[
        ['font-size',['14px','14.4px']],
        ['top',['3px','3.2px']],
        ['position','relative']
        ]);
    });

    it('should match the design spec where it is superscript',() => {
      assertCssPropertiesAreEqual(getElementById('supscript'),[
        ['font-size',['14px','14.4px']],
        ['top',['-3px','-3.2px']],
        ['position','relative']
        ]);
    });

    it('should match the design spec where it is abbr', () => {
      assertCssPropertiesAreEqual(getElementById('abbr'),[
        ['border-bottom-width','1px'],
        ['border-bottom-style','dotted']
        ]);
      });

    it('should match the design spec where it is strikethrough',() => {
       assertCssPropertiesAreEqual(getElementById('strikethrough'),[
        ['color','rgb(86, 86, 86)']
        ]);
    });

    it('should match the design spec where it is smallTag',() => {
      assertCssPropertiesAreEqual(getElementById('smallTag'),[
        ['font-size','16px']
        ]);
    });

    it('should match the design spec where it is timeTag',() => {
      assertCssPropertiesAreEqual(getElementById('timeTag'),[
        ['font-size','16px'],
        ['line-height','22px'],
        ['color','rgb(35, 31, 32)']
        ]);
    });

    it('should match the design spec where it is emTag',() => {
      assertCssPropertiesAreEqual(getElementById('emTag'),[
        ['font-style','italic'],
        ['font-size','16px'],
        ['line-height','22px'],
        ['color','rgb(35, 31, 32)']
        ]);
    });

    it('should match the design spec where it is iTag',() => {
      assertCssPropertiesAreEqual(getElementById('iTag'),[
        ['font-style','italic'],
        ['font-size','16px'],
        ['line-height','22px'],
        ['color','rgb(35, 31, 32)']
        ]);
    });

    it('should match the design spec where it is bTag',() => {
      assertCssPropertiesAreEqual(getElementById('bTag'),[
        ['font-weight','bold'],
        ]);
    });

    it('should match the design spec where it is strongTag',() => {
      assertCssPropertiesAreEqual(getElementById('strongTag'),[
        ['font-weight','bold'],
        ]);
    });

    it('should match the design spec where it is delTag',() => {
      assertCssPropertiesAreEqual(getElementById('delTag'),[
        ['text-decoration','line-through'],
        ]);
    });

    it('should match the design spec where it is insTag',() => {
      assertCssPropertiesAreEqual(getElementById('insTag'),[
        ['text-decoration','underline'],
        ]);
    });

    it('should match the design spec where it is insTag: before',() => {
      //did not want to disturb the common library(assertCssPropertiesAreEqual)
      var symb = window.getComputedStyle(document.querySelector('ins'),':before').getPropertyValue('content');
      expect(symb).to.equal('\'+\'');
    });

    it('should match the design spec where it is insTag: after',() => {
      //did not want to disturb the common library(assertCssPropertiesAreEqual)
      var symb = window.getComputedStyle(document.querySelector('ins'),':after').getPropertyValue('content');
      expect(symb).to.equal('\'+\'');
    });

    it('should match the design spec where it is quote',() => {
      assertCssPropertiesAreEqual(getElementById('qTag'),[
        ['display','inline']
        ]);
    });
  });

  //Lists
  describe('lists',() => {

    beforeEach(() => {
      fixture.load('type/lists.html');
    });

    it('should match the design spec where it is unstyled lists',() => {
      assertCssPropertiesAreEqual(getElementById('unstyled-lists'),[
        ['padding-left','0px'],
        ['list-style-type','none']
        ]);
      });

    it('should match the design spec where it is nested unstyled lists',() => {
      assertCssPropertiesAreEqual(getElementById('nested-unstyled-lists'),[
        ['padding-left','0px'],
        ['list-style-type','none']
        ]);
      });

    it('should match the design spec where it is Inline lists',() => {
      assertCssPropertiesAreEqual(getElementById('inline-lists'),[
        ['padding-left','0px'],
        ['list-style-type','none'],
        ['margin-left','-5px']
        ]);
      });
    //one more test to add for inline list pe-list--inline > li
  });

  //Code
  describe('code',() => {

    beforeEach(() => {
      fixture.load('type/code.html');
    });

    it('should match the design spec where it is inline code',() => {
      assertCssPropertiesAreEqual(getElementById('inline-code'),[
        ['color','rgb(84, 84, 84)'],
        ['font-size','16px'],
        ['font-family','\'Lucida Sans Typewriter\', \'Lucida Console\', monaco, \'Bitstream Vera Sans Mono\', monospace']
        ]);
      });

    it('should match the design spec where it is Block code',() => {
      assertCssPropertiesAreEqual(getElementById('block-code'),[
        ['display','block'],
        ['overflow-x','auto'],
        ['overflow-y','auto'],
        ['font-size','16px'],
        ['font-family','\'Lucida Sans Typewriter\', \'Lucida Console\', monaco, \'Bitstream Vera Sans Mono\', monospace']
        ]);
      });

    it('should match the design spec where it is user input',() => {
      assertCssPropertiesAreEqual(getElementById('user-input'),[
        ['background-color','rgb(51, 51, 51)'],
        ['color','rgb(255, 255, 255)'],
        ['border-bottom-left-radius','3px'],
        ['border-bottom-right-radius','3px'],
        ['border-top-left-radius','3px'],
        ['border-top-right-radius','3px'],
        ['box-sizing','border-box'],
        ['padding-bottom','2px'],
        ['padding-top','2px'],
        ['padding-left','4px'],
        ['padding-right','4px'],
        ['font-family','\'Lucida Sans Typewriter\', \'Lucida Console\', monaco, \'Bitstream Vera Sans Mono\', monospace']
        ]);
      });
  });
});<|endoftext|>


<commit_before>import React from 'react';
import { connect } from 'react-redux';

import ChartConfig from '../views/chart-config';
import * as metricApi from '../../api/metric-api';

class ChartConfigContainer extends React.Component {
  constructor(props) {
    super(props);
    this.whitelistedMetricIds = metricApi.getWhitelistedMetricIds(props.location);
  }

  componentDidMount() {
    metricApi.getMetricMetadata();
  }

  _handleSubmit(e) {
    var metrics = Array.from(
      document.querySelectorAll('input[type="checkbox"]:checked'),
      input => input.value
    ).join(',');

    if (metrics) {
      window.location = '/?metrics=' + metrics;
    }
  }

  render() {
    return (
      <ChartConfig {...this.props} whitelistedMetricIds={this.whitelistedMetricIds} handleSubmit={this._handleSubmit} />
    );
  }
}

const mapStateToProps = function(store) {
  return {
    metadata: store.metricMetadataState.metadata
  };
};

export default connect(mapStateToProps)(ChartConfigContainer);
<commit_msg>Don't reload application after configuring metrics<commit_after>import React from 'react';
import { connect } from 'react-redux';
import { browserHistory } from 'react-router';

import ChartConfig from '../views/chart-config';
import * as metricApi from '../../api/metric-api';

class ChartConfigContainer extends React.Component {
  constructor(props) {
    super(props);
    this.whitelistedMetricIds = metricApi.getWhitelistedMetricIds(props.location);
  }

  componentDidMount() {
    metricApi.getMetricMetadata();
  }

  _handleSubmit(e) {
    var metrics = Array.from(
      document.querySelectorAll('input[type="checkbox"]:checked'),
      input => input.value
    ).join(',');

    if (metrics) {
      browserHistory.push(`/?metrics=${metrics}`);
    }
  }

  render() {
    return (
      <ChartConfig {...this.props} whitelistedMetricIds={this.whitelistedMetricIds} handleSubmit={this._handleSubmit} />
    );
  }
}

const mapStateToProps = function(store) {
  return {
    metadata: store.metricMetadataState.metadata
  };
};

export default connect(mapStateToProps)(ChartConfigContainer);
<|endoftext|>


<commit_before>/*
  Author = Dinesh Guleria
  VSCP Developer
  Date : 27-3-2014
*/

function doc_onload()
{

   // select Scroll area images on load
   select_scroll_area_image();
   // Show floor area on load
   floor_area_visible_onload();
   // Show widget on load
   Central_widget_visible_onload();
   // Create the Socket for I/O devices
   create_device_socket(Multi_Floor_Device_Array);
   // Create the Socket for Measurement  devices
   create_measurement_device_socket(Multi_Floor_Temperature_Device_Array);
}

function create_measurement_device_socket( Device_Array )
{

    for (var i = 0; i < Device_Array.length; i++)
    {
        var btn = new vscpws_simpleTextEvent( Device_Array[i].url,           // url to VSCP websocket i/f
                                             Device_Array[i].id,              // Where it should be placed
                                             Device_Array[i].vscpclass,       // Event class 10/60/65/15
                                             Device_Array[i].vscptype,        // Evet type
                                             Device_Array[i].codingIndex,     // Datacoding index
                                             Device_Array[i].decimals,        // Number of decimals
                                             Device_Array[i].formatstr,       // A value format string
                                             Device_Array[i].guid,            // GUID we are interested in
                                             Device_Array[i].fncallback );     // If set function to call
                                                                               // when data arraives
    }

}

function create_device_socket( Device_Array )
{

    for (var i = 0; i < Device_Array.length; i++)
    {
        var btn = new vscpws_stateButton( Device_Array[i].url,  // url
                                      Device_Array[i].canvasName,    // canvas for button
                                      Device_Array[i].bLocal,            // No local state change
                                      Device_Array[i].btnType,            // Button type
                                      Device_Array[i].bNoState);

        btn.setOnTransmittEvent(Device_Array[i].onTxEventvscpclass,Device_Array[i].onTxEventvscptype,Device_Array[i].onTxEventdata,Device_Array[i].onTxEventguid);
        btn.setOnTransmittZone(Device_Array[i].onTxEventindex,Device_Array[i].onTxEventzone, Device_Array[i].onTxEventsubzone);
        btn.setOffTransmittEvent(Device_Array[i].offTxEventvscpclass,Device_Array[i].offTxEventvscptype,Device_Array[i].offTxEventdata,Device_Array[i].offTxEventguid);
        btn.setOffTransmittZone(Device_Array[i].offTxEventindex,Device_Array[i].offTxEventzone, Device_Array[i].offTxEventsubzone);

        btn.setOnReceiveEvent(Device_Array[i].onRxEventvscpclass,Device_Array[i].onRxEventvscptype,Device_Array[i].onRxEventdata,Device_Array[i].onRxEventguid);
        btn.setOnReceiveZone(Device_Array[i].onRxEventindex,Device_Array[i].onRxEventzone, Device_Array[i].onRxEventsubzone);
        btn.setOffReceiveEvent(Device_Array[i].offRxEventvscpclass,Device_Array[i].offRxEventvscptype,Device_Array[i].offRxEventdata,Device_Array[i].offRxEventguid);
        btn.setOffReceiveZone(Device_Array[i].offRxEventindex,Device_Array[i].offRxEventzone, Device_Array[i].offRxEventsubzone);

    }

}

function floor_area_visible_onload()
{

  $(floor_area_id).each(function(index, element) {
        if(element != floor_area_id[0] )
        {
          $("." + element).hide();

        }
        else
        {
          $("." + element).show();
          //$("." + element).css('background-color', 'blue');
        }
    });

}

function select_scroll_area_image()
{
  //Show area on the scrollable div
  // set img src
  $(div_class_scrollable_Image).each(function(index, element) {
        if(element != div_class_scrollable_Image[0] )
        {
          //alert("hellooooo");
          $("#" +element).attr('src', '../lib/widgets/room/room_unselected.png');

        }
        else
        {
          //alert("he");
          $("#" + element).attr('src', '../lib/widgets/room/room_selected.jpg');
        }

    });

  // Change the color of horizontal line
  $(div_class_scrollable_Hr).each(function(index, element) {
        if(element != div_class_scrollable_Hr[0] )
        {
          //alert("hellooooo");
          $("#" +element).css('background-color', '#DDDFED');

        }
        else
        {
          //alert("he");
          $("#" + element).css('background-color', '#00FF00');
        }

    });

}

function Central_widget_visible_onload()
{

  $(central_area_widgets_id).each(function(index, element) {
        if(element != central_area_widgets_id[0] )
        {
          $("." + element).hide();

        }
    });

}

function show_area(parameter, parameter_image_array, parameter_image, parameter_Hr_array, parameter_Hr, parameter_central, parameter_Menu_array, parmeter_menu_image)
{

  //Show area on the scrollable div
  // set img src
  $(parameter_image_array).each(function(index, element) {
        if(element != parameter_image )
        {
          //alert("hellooooo");
          $("#" +element).attr('src', '../lib/widgets/room/room_unselected.png');

        }
        else
        {
          //alert("he");
          $("#" + element).attr('src', '../lib/widgets/room/room_selected.jpg');
        }

    });

  // Change the color of horizontal line
  $(parameter_Hr_array).each(function(index, element) {
        if(element != parameter_Hr )
        {
          //alert("hellooooo");
          $("#" +element).css('background-color', '#DDDFED');

        }
        else
        {
          //alert("he");
          $("#" + element).css('background-color', '#00FF00');
        }

    });

  //Show area on the menu div
  $(floor_area_id).each(function(index, element) {
        if(element != parameter )
        {
          $("." + element).hide();

        }
        else
        {
          $("." + element).show();
        }

    });

   // Show area on the central div
   show_Central_widget(parameter_central, parameter_Menu_array, parmeter_menu_image);

}

function show_Central_widget(parameter,parameter_image_array, parameter_image)
{

  // set img src
  $(parameter_image_array).each(function(index, element) {
        if(element != parameter_image )
        {
          //alert("hellooooo");
          $("#" +element).attr('src', '../lib/widgets/room/room_unselected.png');

        }
        else
        {
          //alert("he");
          $("#" + element).attr('src', '../lib/widgets/room/room_selected.jpg');
        }

    });

  // Show elements in central area
  $(central_area_widgets_id).each(function(index, element) {
        if(element != parameter )
        {
          $("." + element).hide();

        }
        else
        {
          $("." + element).show();
        }

    });

}

function GetElementInsideContainer(containerID, childID) {
    var elm = {};
    var elms = document.getElementById(containerID).getElementsByTagName("*");
    for (var i = 0; i < elms.length; i++) {
        if (elms[i].id === childID) {
            elm = elms[i];
            break;
        }
    }
    return elm;
}
<commit_msg>Dinesh : Multifloor : Added support for temperature measurement<commit_after>/*
  Author = Dinesh Guleria
  VSCP Developer
  Date : 27-3-2014
*/

function doc_onload()
{

   // select Scroll area images on load
   select_scroll_area_image();
   // Show floor area on load
   floor_area_visible_onload();
   // Show widget on load
   Central_widget_visible_onload();
   // Create the Socket for I/O devices
   create_device_socket(Multi_Floor_Device_Array);
   // Create the Socket for Measurement  devices
   create_measurement_device_socket(Multi_Floor_Temperature_Device_Array);

}

function create_measurement_device_socket( Device_Array )
{

    for (var i = 0; i < Device_Array.length; i++)
    {
        var btn = new vscpws_simpleTextEvent( Device_Array[i].url,           // url to VSCP websocket i/f
                                             Device_Array[i].id,              // Where it should be placed
                                             Device_Array[i].vscpclass,       // Event class 10/60/65/15
                                             Device_Array[i].vscptype,        // Evet type
                                             Device_Array[i].codingIndex,     // Datacoding index
                                             Device_Array[i].decimals,        // Number of decimals
                                             Device_Array[i].formatstr,       // A value format string
                                             Device_Array[i].guid,            // GUID we are interested in
                                             Device_Array[i].fncallback );     // If set function to call
                                                                               // when data arraives
    }

}

function create_device_socket( Device_Array )
{

    for (var i = 0; i < Device_Array.length; i++)
    {
        var btn = new vscpws_stateButton( Device_Array[i].url,  // url
                                      Device_Array[i].canvasName,    // canvas for button
                                      Device_Array[i].bLocal,            // No local state change
                                      Device_Array[i].btnType,            // Button type
                                      Device_Array[i].bNoState);

        btn.setOnTransmittEvent(Device_Array[i].onTxEventvscpclass,Device_Array[i].onTxEventvscptype,Device_Array[i].onTxEventdata,Device_Array[i].onTxEventguid);
        btn.setOnTransmittZone(Device_Array[i].onTxEventindex,Device_Array[i].onTxEventzone, Device_Array[i].onTxEventsubzone);
        btn.setOffTransmittEvent(Device_Array[i].offTxEventvscpclass,Device_Array[i].offTxEventvscptype,Device_Array[i].offTxEventdata,Device_Array[i].offTxEventguid);
        btn.setOffTransmittZone(Device_Array[i].offTxEventindex,Device_Array[i].offTxEventzone, Device_Array[i].offTxEventsubzone);

        btn.setOnReceiveEvent(Device_Array[i].onRxEventvscpclass,Device_Array[i].onRxEventvscptype,Device_Array[i].onRxEventdata,Device_Array[i].onRxEventguid);
        btn.setOnReceiveZone(Device_Array[i].onRxEventindex,Device_Array[i].onRxEventzone, Device_Array[i].onRxEventsubzone);
        btn.setOffReceiveEvent(Device_Array[i].offRxEventvscpclass,Device_Array[i].offRxEventvscptype,Device_Array[i].offRxEventdata,Device_Array[i].offRxEventguid);
        btn.setOffReceiveZone(Device_Array[i].offRxEventindex,Device_Array[i].offRxEventzone, Device_Array[i].offRxEventsubzone);

    }

}

function floor_area_visible_onload()
{

  $(floor_area_id).each(function(index, element) {
        if(element != floor_area_id[0] )
        {
          $("." + element).hide();

        }
        else
        {
          $("." + element).show();
          //$("." + element).css('background-color', 'blue');
        }
    });

}

function select_scroll_area_image()
{
  //Show area on the scrollable div
  // set img src
  $(div_class_scrollable_Image).each(function(index, element) {
        if(element != div_class_scrollable_Image[0] )
        {
          //alert("hellooooo");
          $("#" +element).attr('src', '../lib/widgets/room/room_unselected.png');

        }
        else
        {
          //alert("he");
          $("#" + element).attr('src', '../lib/widgets/room/room_selected.jpg');
        }

    });

  // Change the color of horizontal line
  $(div_class_scrollable_Hr).each(function(index, element) {
        if(element != div_class_scrollable_Hr[0] )
        {
          //alert("hellooooo");
          $("#" +element).css('background-color', '#DDDFED');

        }
        else
        {
          //alert("he");
          $("#" + element).css('background-color', '#00FF00');
        }

    });

}

function Central_widget_visible_onload()
{

  $(central_area_widgets_id).each(function(index, element) {
        if(element != central_area_widgets_id[0] )
        {
          $("." + element).hide();

        }
    });

}

function show_area(parameter, parameter_image_array, parameter_image, parameter_Hr_array, parameter_Hr, parameter_central, parameter_Menu_array, parmeter_menu_image)
{

  //Show area on the scrollable div
  // set img src
  $(parameter_image_array).each(function(index, element) {
        if(element != parameter_image )
        {
          //alert("hellooooo");
          $("#" +element).attr('src', '../lib/widgets/room/room_unselected.png');

        }
        else
        {
          //alert("he");
          $("#" + element).attr('src', '../lib/widgets/room/room_selected.jpg');
        }

    });

  // Change the color of horizontal line
  $(parameter_Hr_array).each(function(index, element) {
        if(element != parameter_Hr )
        {
          //alert("hellooooo");
          $("#" +element).css('background-color', '#DDDFED');

        }
        else
        {
          //alert("he");
          $("#" + element).css('background-color', '#00FF00');
        }

    });

  //Show area on the menu div
  $(floor_area_id).each(function(index, element) {
        if(element != parameter )
        {
          $("." + element).hide();

        }
        else
        {
          $("." + element).show();
        }

    });

   // Show area on the central div
   show_Central_widget(parameter_central, parameter_Menu_array, parmeter_menu_image);

}

function show_Central_widget(parameter,parameter_image_array, parameter_image)
{

  // set img src
  $(parameter_image_array).each(function(index, element) {
        if(element != parameter_image )
        {
          //alert("hellooooo");
          $("#" +element).attr('src', '../lib/widgets/room/room_unselected.png');

        }
        else
        {
          //alert("he");
          $("#" + element).attr('src', '../lib/widgets/room/room_selected.jpg');
        }

    });

  // Show elements in central area
  $(central_area_widgets_id).each(function(index, element) {
        if(element != parameter )
        {
          $("." + element).hide();

        }
        else
        {
          $("." + element).show();
        }

    });

}

function GetElementInsideContainer(containerID, childID) {
    var elm = {};
    var elms = document.getElementById(containerID).getElementsByTagName("*");
    for (var i = 0; i < elms.length; i++) {
        if (elms[i].id === childID) {
            elm = elms[i];
            break;
        }
    }
    return elm;
}
<|endoftext|>


<commit_before>const assert = require('assert');
const dgram = require('dgram');

const SysLogger = require('../');

var server;
module.exports = {

  'SysLogger': {
    'beforeEach': function(done) {
      server = dgram.createSocket('udp4');
      server.bind(0, done);
    },
    'log': {
      'should output formatted message': function(done) {
        var s = new SysLogger({
          port: server.address().port
        });

        server.once('message', function(buf) {
          var str = buf.toString();

          assert(/^<\d+>/.test(str), str);
          assert(/<\d+> \w{3} \d{2} \d{2}:\d{2}:\d{2}/.test(str), str);
          assert(/SysLogger\$\d+/.test(str), str);
          assert(new RegExp("[" + process.pid + "]:").test(str), str);
          assert(/foo$/.test(str));
          done();
        });

        s.info('foo');
      }
    },
    'afterEach': function() {
      server.close();
    }
  }

};
<commit_msg>fix test for node 0.8<commit_after>const assert = require('assert');
const dgram = require('dgram');

const SysLogger = require('../');

var server;
module.exports = {

  'SysLogger': {
    'beforeEach': function(done) {
      server = dgram.createSocket('udp4');
      server.once('listening', done);
      server.bind(0);
    },
    'log': {
      'should output formatted message': function(done) {
        var s = new SysLogger({
          port: server.address().port
        });

        server.once('message', function(buf) {
          var str = buf.toString();

          assert(/^<\d+>/.test(str), str);
          assert(/<\d+> \w{3} \d{2} \d{2}:\d{2}:\d{2}/.test(str), str);
          assert(/SysLogger\$\d+/.test(str), str);
          assert(new RegExp("[" + process.pid + "]:").test(str), str);
          assert(/foo$/.test(str));
          done();
        });

        s.info('foo');
      }
    },
    'afterEach': function() {
      server.close();
    }
  }

};
<|endoftext|>


<commit_before>require('./harness').run();

var recvCount = 0;
var body = "hello world";

connection.addListener('ready', function () {
  puts("connected to " + connection.serverProperties.product);

  var exchange = connection.exchange('node-json-fanout', {type: 'fanout'});

  var q = connection.queue('node-json-queue', function() {
    var origMessage1 = {two:2, one:1},
        origMessage2 = {foo:'bar', hello: 'world'},
        origMessage3 = {coffee:'caf\u00E9', tea: 'th\u00E9'};

    q.bind(exchange, "*");

    q.subscribe(function (json, headers, deliveryInfo) {
      recvCount++;

      assert.equal("node-json-fanout", deliveryInfo.exchange);
      assert.equal("node-json-queue", deliveryInfo.queue);
      assert.equal(false, deliveryInfo.redelivered);

      switch (deliveryInfo.routingKey) {
        case 'message.json1':
          assert.deepEqual(origMessage1, json);
          break;

        case 'message.json2':
          assert.deepEqual(origMessage2, json);
          break;

        case 'message.json3':
          assert.deepEqual(origMessage3, json);
          break;

        default:
          throw new Error('unexpected routing key: ' + deliveryInfo.routingKey);
      }
    })
    .addCallback(function () {
      puts("publishing 3 json messages");
      exchange.publish('message.json1', origMessage1);
      exchange.publish('message.json2', origMessage2, {contentType: 'application/json'});
      exchange.publish('message.json3', origMessage3, {contentType: 'application/json'});

      setTimeout(function () {
        // wait one second to receive the message, then quit
        connection.end();
      }, 1000);
    })
  });
});

process.addListener('exit', function () {
  assert.equal(3, recvCount);
});
<commit_msg>Add failing test for overly long utf8 messages<commit_after>require('./harness').run();

var recvCount = 0;
var body = "hello world";

connection.addListener('ready', function () {
  puts("connected to " + connection.serverProperties.product);

  var exchange = connection.exchange('node-json-fanout', {type: 'fanout'});

  var q = connection.queue('node-json-queue', function() {
    var origMessage1 = {two:2, one:1},
        origMessage2 = {foo:'bar', hello: 'world'},
        origMessage3 = {coffee:'caf\u00E9', tea: 'th\u00E9', hearts: (new Array(50000)).join('❤')};

    q.bind(exchange, "*");

    q.subscribe(function (json, headers, deliveryInfo) {
      recvCount++;

      assert.equal("node-json-fanout", deliveryInfo.exchange);
      assert.equal("node-json-queue", deliveryInfo.queue);
      assert.equal(false, deliveryInfo.redelivered);

      switch (deliveryInfo.routingKey) {
        case 'message.json1':
          assert.deepEqual(origMessage1, json);
          break;

        case 'message.json2':
          assert.deepEqual(origMessage2, json);
          break;

        case 'message.json3':
          assert.deepEqual(origMessage3, json);
          break;

        default:
          throw new Error('unexpected routing key: ' + deliveryInfo.routingKey);
      }
    })
    .addCallback(function () {
      puts("publishing 3 json messages");
      exchange.publish('message.json1', origMessage1);
      exchange.publish('message.json2', origMessage2, {contentType: 'application/json'});
      exchange.publish('message.json3', origMessage3, {contentType: 'application/json'});

      setTimeout(function () {
        // wait one second to receive the message, then quit
        connection.end();
      }, 1000);
    })
  });
});

process.addListener('exit', function () {
  assert.equal(3, recvCount);
});
<|endoftext|>


<commit_before>/*
	molt, a responsive image updater

	Author
		Aurélien Delogu (dev@dreamysource.fr)
*/

(function(context,name,definition){
	if(typeof module!='undefined' && module.exports){
		module.exports=definition();
	}
	else if(typeof define=='function' && define.amd){
		define(definition);
	}
	else{
		context[name]=definition();
	}
}(this,'molt',function(){

	var images=[],
		Promises={
			promises: {
				early: [],
				each: [],
				then: []
			},
			add: function(type,func){
				if(typeof func=='function'){
					this.promises[type].push(func);
				}
			},
			run: function(type,obj){
				for(var i=0,j=this.promises[type].length;i<j;++i){
					this.promises[type][i].apply(obj);
				}
			}
		},
		loading,
		loaded,
		cache=[],
		getOnLoad=function(mode,img){
			return function(){
				++loaded;
				cache.push(img.getAttribute('src'));
				Promises.run('each',{
					mode : mode,
					image : img
				});
				if(loaded>=loading){
					Promises.run('then',{
						mode : mode,
						images : images
					});
				}
			};
		},
		getOnError=function(url){
			return function(){
				throw "An error occured when loading '"+url+"'";
			};
		},
		// Core function
		refresh=function(){
			// Prepare
			var width=W(),
				i,j,k,l,
				attributes,
				url,
				mode,
				modes,
				img;
			loading=0;
			loaded=0;
			// Launch early promises
			Promises.run('early',{
				mode : mode,
				images : images
			});
			// Browse images
			for(i=0,j=images.length;i<j;++i){
				// Prepare
				img=images[i];
				modes=[];
				url='';
				attributes=img.attributes;
				mode=0;
				// Discover modes
				if(attributes['data-src']){
					modes=attributes['data-src'].value.match(/\{(.+?)\}/)[1].split(/\s*,\s*/);
				}
				else{
					for(k=0,l=attributes.length;k<l;++k){
						if(/^data-\d+$/i.test(attributes[k].name)){
							modes.push(parseInt(attributes[k].name.substring(5),10));
						}
					}
				}
				// Sort modes
				modes.sort(function(a,b){
					return a-b;
				});
				// Find which URL to load
				for(k=0,l=modes.length;k<l;++k){
					if(width>=modes[k]){
						mode=modes[k];
						if(attributes['data-src']){
							url=attributes['data-src'].value.replace(/\{.+?\}/,modes[k]);
						}
						else{
							url=attributes['data-'+modes[k]].value;
						}
					}
				}
				// Load image
				if(url && url!=img.src){
					++loading;
					if(cache.indexOf(url)==-1){
						if(!img.onload){
							img.onload=getOnLoad(mode,img);
							img.onerror=getOnError(url);
						}
						img.src=url;
					}
					else{
						img.src=url;
						getOnLoad(mode,img)();
					}
					if(img.style.visibility!='visible'){
						img.style.visibility='visible';
						img.style.width='auto';
						img.style.height='auto';
					}
				}
				// Hide image
				else if(img.style.visibility!='hidden'){
					img.style.visibility='hidden';
					img.style.width=0;
					img.style.height=0;
				}
			}
		};

	// Add new nodes to the stack
	return function(nodes){
		if(nodes.length===undefined){
			nodes=[nodes];
		}
		for(var i=0,j=nodes.length;i<j;++i){
			images.push(nodes[i]);
		}
		// Promises
		var promises={
			early: function(func){
				Promises.add('early',func);
				return promises;
			},
			each: function(func){
				Promises.add('each',func);
				return promises;
			},
			then: function(func){
				Promises.add('then',func);
				return promises;
			},
			start: function(){
				W(refresh);
				refresh();
			}
		};
		return promises;
	};

}));<commit_msg>Improve images loading, add 'eachOnce' promise<commit_after>/*
	molt, a responsive image updater

	Author
		Aurélien Delogu (dev@dreamysource.fr)
*/

(function(context,name,definition){
	if(typeof module!='undefined' && module.exports){
		module.exports=definition();
	}
	else if(typeof define=='function' && define.amd){
		define(definition);
	}
	else{
		context[name]=definition();
	}
}(this,'molt',function(){

	var images=[],
		Promises={
			promises: {
				early: [],
				each: [],
				eachonce: [],
				once: [],
				then: []
			},
			add: function(type,func){
				if(typeof func=='function'){
					this.promises[type].push(func);
				}
			},
			run: function(type,obj){
				for(var i=0,j=this.promises[type].length;i<j;++i){
					this.promises[type][i].apply(obj);
				}
			}
		},
		loading=0,
		registered=false,
		getOnLoad=function(url,img,mode){
			return function(){
				// Load image to the DOM
				img.src=url;
				// Launch 'eachonce' callbacks
				if(Promises.promises.eachonce.length){
					Promises.run('eachonce',{mode:mode,img:img});
					Promises.promises.eachonce=[];
				}
				// Launch 'each' callbacks
				Promises.run('each',{mode:mode,img:img});
				// If all images have been loaded
				if(!--loading){
					// Launch 'once' callbacks
					if(Promises.promises.once.length){
						Promises.run('once',{mode:mode,imgs:images});
						Promises.promises.once=[];
					}
					// Launch 'then' callbacks
					Promises.run('then',{mode:mode,imgs:images});
				}
			};
		},
		getOnError=function(url){
			return function(){
				--loading;
				throw "An error has occured when loading '"+url+"'";
			};
		},
		// Core function
		refresh=function(){
			// Register W once
			if(!registered){
				W(refresh);
				registered=true;
			}
			// Prepare
			var width=W(),
				i,j,k,l,
				attributes,
				url,
				mode,
				modes,
				img,
				image,
				then=true;
			loading+=images.length;
			// Launch 'early' callbacks
			Promises.run('early',{
				mode : mode,
				imgs : images
			});
			// Browse images
			for(i=0,j=images.length;i<j;++i){
				// Prepare
				img=images[i];
				modes=[];
				url='';
				attributes=img.attributes;
				mode=0;
				// Discover modes
				if(attributes['data-src']){
					modes=attributes['data-src'].value.match(/\{(.+?)\}/)[1].split(/\s*,\s*/);
				}
				else{
					for(k=0,l=attributes.length;k<l;++k){
						if(/^data-\d+$/i.test(attributes[k].name)){
							modes.push(parseInt(attributes[k].name.substring(5),10));
						}
					}
				}
				// Sort modes
				modes.sort(function(a,b){
					return a-b;
				});
				// Find which URL to load
				for(k=0,l=modes.length;k<l;++k){
					if(width>=modes[k]){
						mode=modes[k];
						if(attributes['data-src']){
							url=attributes['data-src'].value.replace(/\{.+?\}/,modes[k]);
						}
						else{
							url=attributes['data-'+modes[k]].value;
						}
					}
				}
				// Load image
				if(url){
					then=false;
					image=new Image();
					image.src=url;
					if(image.complete===true){
						img.src=url;
						getOnLoad(url,img,mode)();
					}
					else{
						image.onload=getOnLoad(url,img,mode);
						image.onerror=getOnError(url);
					}
					if(img.style.visibility!='visible'){
						img.style.visibility='visible';
						img.style.width='auto';
						img.style.height='auto';
					}
				}
				// Hide image
				else if(img.style.visibility!='hidden'){
					--loading;
					img.style.visibility='hidden';
					img.style.width=0;
					img.style.height=0;
				}
			}
			// Launch 'then' callbacks
			if(then){
				Promises.run('then',{mode:mode,imgs:images});
			}
		};

	// Add new nodes to the stack
	return function(nodes){
		if(nodes.length===undefined){
			nodes=[nodes];
		}
		for(var i=0,j=nodes.length;i<j;++i){
			images.push(nodes[i]);
		}
		// Promises
		var promises={
			early: function(func){
				Promises.add('early',func);
				return promises;
			},
			each: function(func){
				Promises.add('each',func);
				return promises;
			},
			eachOnce: function(func){
				Promises.add('eachonce',func);
				return promises;
			},
			once: function(func){
				Promises.add('once',func);
				return promises;
			},
			then: function(func){
				Promises.add('then',func);
				return promises;
			},
			start: function(){
				refresh();
			}
		};
		return promises;
	};

}));<|endoftext|>


<commit_before>basePath = '..';
files = [
  JASMINE,
  JASMINE_ADAPTER,
  'components/jquery/jquery.js',
  'components/angular/angular.js',
  'components/angular-mocks/angular-mocks.js',
  'src/directive.js',
  'test/spec/*.js'
];
singleRun = true;
browsers = [ 'Chrome' ];<commit_msg>Update jquery path<commit_after>basePath = '..';
files = [
  JASMINE,
  JASMINE_ADAPTER,
  'components/jquery/dist/jquery.js',
  'components/angular/angular.js',
  'components/angular-mocks/angular-mocks.js',
  'src/directive.js',
  'test/spec/*.js'
];
singleRun = true;
browsers = [ 'Chrome' ];<|endoftext|>


<commit_before>// @flow
/**
 * SpringFashionista: manages Fashions for spring animations.
 *
 * @module internal/fashionistas/spring
 */

import chroma from 'chroma-js'

import type { Styles, Fashion } from '../flow-types'
import { parseStyle, stringifyFashion } from './common'

export const interpolateValue = (
  currentValue: number,
  endValue: number,
  progress: number,
): number => {
  const delta: number = endValue - currentValue;
  return currentValue + (delta * progress);
}

export const interpolateFashion = (
  from: Fashion,
  to: Fashion,
  springValue: number
): Fashion => {
  return from.isColorType && to.isColorType ?
    { ...from, value: chroma.mix(from.value, to.value, springValue) }
  : from.isNumberType && to.isNumberType ?
    { ...from, value: interpolateValue(from.value, to.value, springValue) }
  : from.isUnitType && to.isUnitType ?
    { ...from, value: interpolateValue(from.value, to.value, springValue) }
  :
    to
};

const interpolateCompositeFashion = (
  from: Fashion,
  to: Fashion,
  springValue: number
) => {
  return {
    ...from,
    styles: from.styles.map(
      (f: Fashion, i: number) => {
        const t = to.styles[i];
        return (f.isCompositeType && t.isCompositeType) ? (
          interpolateCompositeFashion(f, t, springValue)
        ) : (
          interpolateFashion(f, t, springValue)
        );
      }
    ),
  };
}

export const reconstructStyles = (
  fromStyles: Styles,
  toStyles: Styles,
  styleNames: string[],
  springValues: number[],
): Styles => {
  return styleNames.reduce(
    (reconstructed, styleName, index) => {
      const from = parseStyle(fromStyles[styleName], styleName);
      const to = parseStyle(toStyles[styleName], styleName);
      const value = springValues[index];
      reconstructed[styleName] = stringifyFashion(
        from.isBasicType && to.isBasicType ?
          interpolateFashion(from, to, value)
        : from.isCompositeType && to.isCompositeType ?
          interpolateCompositeFashion(from, to, value)
        :
          to
      );
      return reconstructed;
    },
    {}
  );
};
<commit_msg>:art: Fix flow errors<commit_after>// @flow
/**
 * SpringFashionista: manages Fashions for spring animations.
 *
 * @module internal/fashionistas/spring
 */

import chroma from 'chroma-js'

import type { Styles, Fashion, CompositeFashion } from '../flow-types'
import { parseStyle, stringifyFashion } from './common'

export const interpolateValue = (
  currentValue: number,
  endValue: number,
  progress: number,
): number => {
  const delta: number = endValue - currentValue;
  return currentValue + (delta * progress);
}

export const interpolateFashion = (
  from: Fashion,
  to: Fashion,
  springValue: number
): Fashion => {
  return from.isColorType && to.isColorType ?
    { ...from, value: chroma.mix(from.value, to.value, springValue) }
  : from.isNumberType && to.isNumberType ?
    { ...from, value: interpolateValue(from.value, to.value, springValue) }
  : from.isUnitType && to.isUnitType ?
    { ...from, value: interpolateValue(from.value, to.value, springValue) }
  :
    to
};

const interpolateCompositeFashion = (
  from: CompositeFashion,
  to: CompositeFashion,
  springValue: number
): Fashion => {
  return {
    ...from,
    styles: from.styles.map(
      (f: Fashion, i: number) => {
        const t: Fashion = to.styles[i];
        return (f.isCompositeType && t.isCompositeType) ? (
          interpolateCompositeFashion(f, t, springValue)
        ) : (
          interpolateFashion(f, t, springValue)
        );
      }
    ),
  };
}

export const reconstructStyles = (
  fromStyles: Styles,
  toStyles: Styles,
  styleNames: string[],
  springValues: number[],
): Styles => {
  return styleNames.reduce(
    (reconstructed, styleName, index) => {
      const from = parseStyle(fromStyles[styleName], styleName);
      const to = parseStyle(toStyles[styleName], styleName);
      const value = springValues[index];
      reconstructed[styleName] = stringifyFashion(
        from.isBasicType && to.isBasicType ?
          interpolateFashion(from, to, value)
        : from.isCompositeType && to.isCompositeType ?
          interpolateCompositeFashion(from, to, value)
        :
          to
      );
      return reconstructed;
    },
    {}
  );
};
<|endoftext|>


<commit_before>

/**
 * WPCOM module
 */

var WPCOM = require('../');
var Site = require('../lib/site');
var util = require('./util');
var assert = require('assert');
var fs = require('fs');

/**
 * Testing data
 */

var test = require('./data');

/**
 * Create a `Site` instance
 */

describe('WPCOM#Site', function(){

  // Create a new_post before to start the tests
  var new_post;
  before(function(done){
    util.addPost(function(err, post) {
      if (err) return done(err);

      new_post = post;
      done();
    });
  });

  describe('sync', function(){

    it('should be create a site object instance', function(){
      var site = util.public_site();

      assert.ok(site instanceof Site);
      assert.equal(test.site.public.url, site._id);
    });

  });

  describe('async', function(){

    describe('site.get()', function(){
      it('should require site data', function(done){
        var site = util.public_site();

        site.get(function(err, info){
          if (err) throw err;

          assert.equal('number', typeof info.ID);
          assert.equal('string', typeof info.name);

          done();
        });
      });
    });

    describe('site.postsList()', function(){

      it('should request posts list', function(done){
        var site = util.public_site();

        site.postsList(function(err, list){
          if (err) throw err;

          // list object data testing
          assert.equal('object', typeof list);

          // `posts list` object data testing
          assert.equal('number', typeof list.found);

          assert.equal('object', typeof list.posts);
          assert.ok(list.posts instanceof Array);

          done();
        });
      });

      it('should request only one post', function(done){

        var site = util.public_site();

        site.postsList({ number: 1 }, function(err, list){
          if (err) throw err;

          // list object data testing
          assert.equal('object', typeof list);
          assert.equal('number', typeof list.found);
          assert.equal('object', typeof list.posts);
          assert.ok(list.posts instanceof Array);
          assert.ok(list.posts.length <= 1);

          done();
        });

      });

    });

    describe('site.mediaList()', function(){

      it('should request media library list', function(done){
        var site = util.private_site();

        site.mediaList(function(err, list){
          if (err) throw err;

          // list object data testing
          assert.equal('object', typeof list);
          assert.equal('number', typeof list.found);
          assert.equal('object', typeof list.media);
          assert.ok(list.media instanceof Array);

          done();

        });

      });

    });

    describe('site.usersList()', function(){

      it('should request users list', function(done){
        var site = util.private_site();

        site.usersList(function(err, list){
          if (err) throw err;

          assert.equal('number', typeof list.found);
          assert.ok(list.users instanceof Array);
          done();
        });

      });

    });

    describe('site.addPost()', function(){

      it('should create a new blog post', function(done){
        var site = util.private_site();

        var post = site.addPost(test.new_post_data, function(err, data){
          if (err) throw err;

          assert.equal('object', typeof data);
          assert.equal(test.site.private.id, data.site_ID);

          done();
        });

      });

    });

    describe('site.deletePost()', function(){

      it('should delete a blog post', function(done){

        var site = util.private_site();

        var post = site.deletePost(new_post.ID, function(err, data){

          if (err) throw err;

          assert.equal('object', typeof data);
          assert.equal(test.site.private.id, data.site_ID);
          assert.equal(new_post.ID, data.ID);

          done();

        });

      });

    });

    describe('site.addMediaFiles([fs])', function(){

      it('should create a new media from a file', function(done){
        var site = util.private_site();

        // pass streams
        var files = [];
        //test.new_media_data.files
        for (var i = 0; i < test.new_media_data.files.length; i++) {
          files.push(fs.createReadStream(test.new_media_data.files[i]));
        }

        var media = site.addMediaFiles(files, function(err, data){
          if (err) throw err;

          assert.ok(data);
          assert.ok(data.media instanceof Array);
          assert.equal(test.new_media_data.files.length, data.media.length);
          done();
        });

      });

    });

    describe('site.addMediaUrls([\'url1\', \'url2\'])', function(){

      it('should create a new site media', function(done){
        var site = util.private_site();

        var media = site.addMediaUrls(test.new_media_data.media_urls, function(err, data){
          if (err) throw err;

          assert.ok(data);
          assert.ok(data.media instanceof Array);
          assert.equal(test.new_media_data.media_urls.length, data.media.length);
          done();
        });

      });

    });

  });

});
<commit_msg>test: add site.commentsList() test<commit_after>

/**
 * WPCOM module
 */

var WPCOM = require('../');
var Site = require('../lib/site');
var util = require('./util');
var assert = require('assert');
var fs = require('fs');

/**
 * Testing data
 */

var test = require('./data');

/**
 * Create a `Site` instance
 */

describe('WPCOM#Site', function(){

  // Create a new_post before to start the tests
  var new_post;
  before(function(done){
    util.addPost(function(err, post) {
      if (err) return done(err);

      new_post = post;
      done();
    });
  });

  describe('sync', function(){

    it('should be create a site object instance', function(){
      var site = util.public_site();

      assert.ok(site instanceof Site);
      assert.equal(test.site.public.url, site._id);
    });

  });

  describe('async', function(){

    describe('site.get()', function(){
      it('should require site data', function(done){
        var site = util.public_site();

        site.get(function(err, info){
          if (err) throw err;

          assert.equal('number', typeof info.ID);
          assert.equal('string', typeof info.name);

          done();
        });
      });
    });

    describe('site.postsList()', function(){

      it('should request posts list', function(done){
        var site = util.public_site();

        site.postsList(function(err, list){
          if (err) throw err;

          // list object data testing
          assert.equal('object', typeof list);

          // `posts list` object data testing
          assert.equal('number', typeof list.found);

          assert.equal('object', typeof list.posts);
          assert.ok(list.posts instanceof Array);

          done();
        });
      });

      it('should request only one post', function(done){

        var site = util.public_site();

        site.postsList({ number: 1 }, function(err, list){
          if (err) throw err;

          // list object data testing
          assert.equal('object', typeof list);
          assert.equal('number', typeof list.found);
          assert.equal('object', typeof list.posts);
          assert.ok(list.posts instanceof Array);
          assert.ok(list.posts.length <= 1);

          done();
        });

      });

    });

    describe('site.mediaList()', function(){

      it('should request media library list', function(done){
        var site = util.private_site();

        site.mediaList(function(err, list){
          if (err) throw err;

          // list object data testing
          assert.equal('object', typeof list);
          assert.equal('number', typeof list.found);
          assert.equal('object', typeof list.media);
          assert.ok(list.media instanceof Array);

          done();

        });

      });

    });

    describe('site.usersList()', function(){

      it('should request users list', function(done){
        var site = util.private_site();

        site.usersList(function(err, list){
          if (err) throw err;

          assert.equal('number', typeof list.found);
          assert.ok(list.users instanceof Array);
          done();
        });

      });

    });

    describe('site.commentsList()', function(){

      it('should request media library list', function(done){
        var site = util.private_site();

        site.commentsList(function(err, list){
          if (err) throw err;

          // list object data testing
          assert.equal('object', typeof list);
          assert.equal('number', typeof list.found);
          assert.equal('object', typeof list.comments);
          assert.ok(list.comments instanceof Array);

          done();

        });

      });

    });

    describe('site.addPost()', function(){

      it('should create a new blog post', function(done){
        var site = util.private_site();

        var post = site.addPost(test.new_post_data, function(err, data){
          if (err) throw err;

          assert.equal('object', typeof data);
          assert.equal(test.site.private.id, data.site_ID);

          done();
        });

      });

    });

    describe('site.deletePost()', function(){

      it('should delete a blog post', function(done){

        var site = util.private_site();

        var post = site.deletePost(new_post.ID, function(err, data){

          if (err) throw err;

          assert.equal('object', typeof data);
          assert.equal(test.site.private.id, data.site_ID);
          assert.equal(new_post.ID, data.ID);

          done();

        });

      });

    });

    describe('site.addMediaFiles([fs])', function(){

      it('should create a new media from a file', function(done){
        var site = util.private_site();

        // pass streams
        var files = [];
        //test.new_media_data.files
        for (var i = 0; i < test.new_media_data.files.length; i++) {
          files.push(fs.createReadStream(test.new_media_data.files[i]));
        }

        var media = site.addMediaFiles(files, function(err, data){
          if (err) throw err;

          assert.ok(data);
          assert.ok(data.media instanceof Array);
          assert.equal(test.new_media_data.files.length, data.media.length);
          done();
        });

      });

    });

    describe('site.addMediaUrls([\'url1\', \'url2\'])', function(){

      it('should create a new site media', function(done){
        var site = util.private_site();

        var media = site.addMediaUrls(test.new_media_data.media_urls, function(err, data){
          if (err) throw err;

          assert.ok(data);
          assert.ok(data.media instanceof Array);
          assert.equal(test.new_media_data.media_urls.length, data.media.length);
          done();
        });

      });

    });

  });

});
<|endoftext|>