/** @jsx React.DOM */
jest.autoMockOff();

describe('react.backbone', function() {
  var ReactWithAddons = require('react/addons');
  var TestUtils = ReactWithAddons.addons.TestUtils;
  var Backbone = require('backbone');
  var React = require('../react.backbone.js');

  describe("with :model key", function() {
    var UserView = React.createBackboneClass({
        render: function() {
            return (
              <div>
                  <h1>{this.getModel().get("name")}</h1>
              </div>
            );
        }
    });

    it('renders model as-is', function() {
      var user = new Backbone.Model({name: "Clay"});
      var userView = UserView({model: user});
      TestUtils.renderIntoDocument(userView);

      var header = TestUtils.findRenderedDOMComponentWithTag(userView, 'h1');
      expect(header.getDOMNode().textContent).toEqual('Clay');
    });

    it('renders model after changes to property', function() {
      var user = new Backbone.Model({name: "Clay"});
      var userView = UserView({model: user});
      TestUtils.renderIntoDocument(userView);
      user.set("name", "David");

      var header = TestUtils.findRenderedDOMComponentWithTag(userView, 'h1');
      expect(header.getDOMNode().textContent).toEqual('David');
    });
  });

  describe("with :collection key", function() {
    var UsersListView = React.createBackboneClass({
      render: function() {
        var usersList = this.getCollection().map(function(user) {
            return <li>{user.get("name")}</li>;
        });

        return (
          <ul>
            { usersList }
          </ul>
        );
      }
    });

    it('renders collection as-is', function() {
      var usersList = new Backbone.Collection([{name: "Clay"}, {name: "David"}]);
      var usersListView = UsersListView({collection: usersList});
      TestUtils.renderIntoDocument(usersListView);

      jest.runOnlyPendingTimers();

      var list = TestUtils.findRenderedDOMComponentWithTag(usersListView, 'ul');
      expect(list.getDOMNode().childNodes.length).toEqual(2);
      expect(list.getDOMNode().childNodes[0].textContent).toEqual("Clay");
    });

    it('renders collection on adding', function() {

      var usersList = new Backbone.Collection([{name: "Clay"}, {name: "David"}]);
      var usersListView = UsersListView({collection: usersList});
      TestUtils.renderIntoDocument(usersListView);
      usersList.add({name: "Jack"});

      jest.runOnlyPendingTimers();

      var list = TestUtils.findRenderedDOMComponentWithTag(usersListView, 'ul');
      expect(list.getDOMNode().childNodes.length).toEqual(3);
      expect(list.getDOMNode().childNodes[2].textContent).toEqual("Jack");
    });
  });

});
@@ -1257,32 +1257,1234 @@
 David');%0A    %7D);
+%0A%0A    describe(%22with changeOptions%22, function() %7B%0A      var UserView = React.createBackboneClass(%7B%0A        changeOptions: %22change:name%22,%0A        render: function() %7B%0A            return (%0A              %3Cdiv%3E%0A                  %3Ch1%3E%7Bthis.getModel().get(%22name%22)%7D %7Bthis.getModel().get(%22age%22)%7D%3C/h1%3E%0A              %3C/div%3E%0A            );%0A        %7D%0A      %7D);%0A%0A      it('doesnt render if other property is changed', function() %7B%0A        var user = new Backbone.Model(%7Bname: %22Clay%22, age: %2280%22%7D);%0A        var userView = UserView(%7Bmodel: user%7D);%0A        TestUtils.renderIntoDocument(userView);%0A        user.set(%22age%22, %2260%22);%0A%0A        var header = TestUtils.findRenderedDOMComponentWithTag(userView, 'h1');%0A        expect(header.getDOMNode().textContent).toEqual('Clay 80');%0A      %7D);%0A%0A      it('does render if valid property is changed', function() %7B%0A        var user = new Backbone.Model(%7Bname: %22Clay%22, age: %2280%22%7D);%0A        var userView = UserView(%7Bmodel: user%7D);%0A        TestUtils.renderIntoDocument(userView);%0A        user.set(%22name%22, %22David%22);%0A%0A        var header = TestUtils.findRenderedDOMComponentWithTag(userView, 'h1');%0A        expect(header.getDOMNode().textContent).toEqual('David 80');%0A      %7D);%0A%0A    %7D);
 %0A  %7D);%0A%0A  descri

test change options