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);


  // - bubble
  // - 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);

    


  });

  /**
   */


}); 
@@ -2034,16 +2034,8 @@
 s);%0A
-%0A    %0A%0A%0A
   %7D)
@@ -2048,15 +2048,429 @@
 **%0A   */
+%0A%0A  it(%22can bubble an event%22, function () %7B%0A    var parent = app.createView(%22basic%22),%0A    child      = app.createView(%22basic%22),%0A    subChild   = app.createView(%22basic%22),%0A    bubbled;%0A%0A    child.setChild(%22child%22, subChild);%0A    parent.setChild(%22child%22, child);%0A%0A    parent.once(%22bubble%22, function (arg) %7B%0A      bubbled = arg;%0A    %7D);%0A%0A    subChild.bubble(%22bubble%22, %22blah!%22);%0A    expect(bubbled).to.be(%22blah!%22);%0A  %7D)
 %0A%0A%0A%7D); 

add bubble test