github.com/marinho/drone@v0.2.1-0.20140504195434-d3ba962e89a7/cmd/droned/assets/test/commit_updates_test.js (about)

     1  describe("CommitUpdates", function() {
     2    describe("constructor", function() {
     3      it("initializes with a socket", function() {
     4        var socket = {mock: true};
     5        var updates = new Drone.CommitUpdates(socket);
     6        expect(updates.socket).toEqual(socket);
     7      });
     8  
     9      it("initializes with a string", function() {
    10        window.WebSocket = function(url) { this.url = url; };
    11        var updates = new Drone.CommitUpdates('/path');
    12        expect(updates.socket.url).toEqual('ws://localhost/path');
    13      });
    14  
    15      it("attaches handlers to the socket", function() {
    16        var socket = {mock: true};
    17        var updates = new Drone.CommitUpdates(socket);
    18        expect(typeof(socket.onmessage)).toEqual("function");
    19      });
    20    });
    21  
    22    describe("onMessage", function() {
    23      it("appends to the lineBuffer", function() {
    24        var updates = new Drone.CommitUpdates({});
    25        updates.lineBuffer = "foo ";
    26        updates.onMessage({data: 'bar'});
    27        expect(updates.lineBuffer).toEqual('foo bar');
    28      });
    29    });
    30  
    31    describe("updateScreen", function() {
    32      it("does nothing when the lineBuffer is empty", function() {
    33        var updates = new Drone.CommitUpdates({});
    34        var el = document.createElement('div');
    35        expect(el.innerHTML).toEqual('');
    36        updates.startOutput(el);
    37        expect(el.innerHTML).toEqual('');
    38        updates.stopOutput();
    39      });
    40  
    41      it("writes the lineBuffer to the element", function() {
    42        var socket = {};
    43        var updates = new Drone.CommitUpdates(socket);
    44        socket.onmessage({data: 'foo'});
    45        socket.onmessage({data: ' bar'});
    46  
    47        var el = document.createElement('div');
    48        expect(el.innerHTML).toEqual('');
    49  
    50        updates.startOutput(el);
    51        expect(el.innerHTML).toEqual('foo bar');
    52        updates.stopOutput();
    53      });
    54    });
    55  });