// Generated by CoffeeScript 1.4.0
(function() {

  describe("A window message renderer", function() {
    var content, message, renderer, surface;
    surface = renderer = void 0;
    message = function(num) {
      var msg;
      msg = $($('.message', surface)[num]);
      return {
        source: $(msg.children()[0]),
        content: $(msg.children()[1])
      };
    };
    beforeEach(function() {
      var win;
      mocks.dom.setUp();
      surface = $('<div>');
      win = {
        $messages: surface,
        $messagesContainer: $('<#messages-container>'),
        isScrolledDown: function() {},
        scrollToBottom: function() {},
        getContext: function() {
          return {};
        },
        emit: function() {},
        isFocused: function() {
          return true;
        }
      };
      win.$messagesContainer.restoreScrollPosition = function() {};
      renderer = new chat.window.MessageRenderer(win);
      return spyOn(renderer, '_createContentFromText').andCallThrough();
    });
    content = function() {
      var args;
      args = renderer._createContentFromText.mostRecentCall.args;
      return html.display(args[0]);
    };
    afterEach(function() {
      mocks.dom.tearDown();
      return surface.remove();
    });
    it("displays messages to the user", function() {
      renderer.message('bob', 'hi');
      expect(message(0).source).toHaveText('bob');
      return expect(message(0).content).toHaveText('hi');
    });
    it("escapes html-like text", function() {
      renderer.message('joe', '<a "evil.jpg"/>');
      return expect(content()).toBe('&lt;a &quot;evil.jpg&quot;/&gt;');
    });
    it("doesn't collapse multiple spaces", function() {
      renderer.message('bill', 'hi     there');
      return expect(content()).toBe('hi     there', '');
    });
    it("auto-links urls", function() {
      renderer.message('*', 'check www.youtube.com out');
      return expect(content()).toBe('check <a target="_blank" ' + 'href="http://www.youtube.com">www.youtube.com</a> out');
    });
    it("allows long words to break", function() {
      var word;
      word = 'thisisareallyreallyreallyreallyreallyreallyreallylongword';
      renderer.message('bill', word);
      return expect(content()).toBe('<span class="longword">' + word + '</span>');
    });
    it("allows multiple long words to break", function() {
      var word1, word2;
      word1 = 'thisisareallyreallyreallyreallyreallyreallyreallylongword';
      word2 = 'andthisisalsoareallylongword!!!!!!!!!!!!!!!!!';
      renderer.message('joe', word1 + ' ' + word2);
      return expect(content()).toBe('<span class="longword">' + word1 + '</span> ' + '<span class="longword">' + word2 + '</span>');
    });
    it("allows the same long word to be used twice", function() {
      var word;
      word = 'andthisisalsoareallylongwordddddddddddddd';
      renderer.message('joe', word + ' ' + word);
      return expect(content()).toBe('<span class="longword">' + word + '</span> ' + '<span class="longword">' + word + '</span>');
    });
    it("allows long words to break even when they contain HTML", function() {
      var escapedWord, word;
      word = 'thisisareallyreallyrea"<>&><"lyreallyreallyreallylongword';
      renderer.message('bill', word);
      escapedWord = word.slice(0, 22) + '&quot;&lt;&gt;&amp;&gt;&lt;&quot;' + word.slice(29);
      return expect(content()).toBe('<span class="longword">' + escapedWord + '</span>');
    });
    return it("doesn't allow short words that seem long due to HTML escaping to break", function() {
      renderer.message('joe', '<a href="evil.jpg"/>');
      return expect(content()).toBe('&lt;a href=&quot;evil.jpg&quot;/&gt;');
    });
  });

}).call(this);
