var expect = require("expect.js"),
mojo       = require("../..");


describe("parent/child#", function () {

  var app = new mojo.Application(), 
  app2 = new mojo.Application();
  app.registerViewClass("basic", mojo.View);
  app2.registerViewClass("basic", mojo.View);


  // - parent defined
  // - inherit application, and models, parent, and _parent
  // - dispose child if parent disposed
  // - correct path
  // - can set child

  it("can set a child", function () {
    var parent = app.createView("basic"), 
    child = app.createView("basic"),

    // outside of application
    child2 = new mojo.View();

    parent.setChild("someChild", child);
    parent.setChild("someChild2", child2);

    expect(parent.get("sections.someChild")).to.be(child);
    expect(parent.get("sections.someChild2")).to.be(child2);

    expect(child.parent).to.be(parent); 
    expect(child.application).to.be(app);
    expect(child.models).to.be(app.models);

    expect(child2.parent).to.be(parent); 
    expect(child2.application).to.be(app);
    expect(child2.models).to.be(app.models);
  });


  /**
   */

  it("properly inherits application", function () {

    var parent  = app.createView("basic"),
    child       = app2.createView("basic"),
    subChild    = app2.createView("basic"),
    subSubChild = app2.createView("basic");

    child.setChild("someChild", subChild);
    subChild.setChild("subChild", subSubChild);

    expect(child.application).to.be(app2);
    expect(child.models).to.be(app2.models);
    expect(subChild.application).to.be(app2);
    expect(subChild.models).to.be(app2.models);
    expect(subSubChild.application).to.be(app2);
    expect(subSubChild.models).to.be(app2.models);

    parent.setChild("someChild", child);

    expect(child.application).to.be(app);
    expect(child.models).to.be(app.models);
    expect(subChild.application).to.be(app);
    expect(subChild.models).to.be(app.models);
    expect(subSubChild.application).to.be(app);
    expect(subSubChild.models).to.be(app.models);
  });

  /**
   */

  it("can bubble an event", function () {
    var parent = app.createView("basic"),
    child      = app.createView("basic"),
    subChild   = app.createView("basic"),
    bubbled;


    child.setChild("child", subChild);
    parent.setChild("child", child);

    parent.once("bubble", function (arg) {
      bubbled = arg;
    });

    subChild.bubble("bubble", "blah!");
    expect(bubbled).to.be("blah!");
  });

  /**
   */

  it("has the correct path", function () {
    var parent = app.createView("basic"),
    child      = app.createView("basic");
    parent.setChild("child", child);
    expect(child.path()).to.be("DecorableView.DecorableView");
  });

  
}); 
@@ -269,90 +269,8 @@
 ;%0A%0A%0A
-  // - parent defined%0A  // - inherit application, and models, parent, and _parent%0A
   //
@@ -2619,13 +2619,767 @@
  %7D);%0A%0A  
+/**%0A   */%0A%0A  it(%22removes the child if the parent is removed%22, function () %7B%0A    var parent = app.createView(%22basic%22),%0A    child      = app.createView(%22basic%22);%0A%0A    child.render();%0A    parent.setChild(%22child%22, child);%0A    parent.render();%0A%0A    parent.remove();%0A    expect(child.states.removed).to.be(true);%0A    expect(child.states.remove).to.be(true);%0A  %7D);%0A%0A  /**%0A   */%0A%0A  it(%22disposes the child if the parent is disposed%22, function () %7B%0A    var parent = app.createView(%22basic%22),%0A    child      = app.createView(%22basic%22);%0A%0A    child.render();%0A    parent.setChild(%22child%22, child);%0A    parent.render();%0A%0A    // still triggers .remove()%0A    parent.dispose();%0A%0A    expect(child.states.removed).to.be(true);%0A    expect(child.states.remove).to.be(true);%0A  %7D)%0A
 %0A%7D); 

remove child if parent is removed