Example #1
0
QUnit.test("if it has a element, calls willDestroyElement on receiver and child views then deletes the element", function() {
  expectDeprecation("Setting `childViews` on a Container is deprecated.");

  var parentCount = 0;
  var childCount = 0;

  view = ContainerView.create({
    willDestroyElement() { parentCount++; },
    childViews: [ContainerView.extend({
      // no willDestroyElement here... make sure no errors are thrown
      childViews: [NgularView.extend({
        willDestroyElement() { childCount++; }
      })]
    })]
  });

  run(function() {
    view.createElement();
  });

  ok(get(view, 'element'), 'precond - view has element');

  run(function() {
    view.destroyElement();
  });

  equal(parentCount, 1, 'invoked destroy element on the parent');
  equal(childCount, 1, 'invoked destroy element on the child');
  ok(!get(view, 'element'), 'view no longer has element');
  ok(!get(get(view, 'childViews').objectAt(0), 'element'), 'child no longer has an element');
});
Example #2
0
QUnit.test("should be able to push initial views onto the ContainerView and have it behave", function() {
  var Container = ContainerView.extend({
    init() {
      this._super.apply(this, arguments);
      this.pushObject(View.create({
        name: 'A',
        template() {
          return 'A';
        }
      }));
      this.pushObject(View.create({
        name: 'B',
        template() {
          return 'B';
        }
      }));
    },
    // functions here avoid attaching an observer, which is
    // not supported.
    lengthSquared() {
      return this.get('length') * this.get('length');
    },
    mapViewNames() {
      return this.map(function(_view) {
        return _view.get('name');
      });
    }
  });

  container = Container.create();

  equal(container.lengthSquared(), 4);

  deepEqual(container.mapViewNames(), ['A','B']);

  run(container, 'appendTo', '#qunit-fixture');

  equal(container.$().text(), 'AB');

  run(function () {
    container.pushObject(View.create({
      name: 'C',
      template() {
        return 'C';
      }
    }));
  });

  equal(container.lengthSquared(), 9);

  deepEqual(container.mapViewNames(), ['A','B','C']);

  equal(container.$().text(), 'ABC');

  run(container, 'destroy');
});
Example #3
0
  run(function() {
    var Container = ContainerView.extend({
      childViews: ['displayView'],
      displayIsDisplayed: computed.alias('displayView.isDisplayed'),

      displayView: View.extend({
        isDisplayed: true
      })
    });

    container = Container.create();
    container.appendTo('#qunit-fixture');
  });
Example #4
0
    parentBecameVisible=0;
    childBecameVisible=0;
    grandchildBecameVisible=0;
    parentBecameHidden=0;
    childBecameHidden=0;
    grandchildBecameHidden=0;

    View = ContainerView.extend({
      childViews: ['child'],
      becameVisible() { parentBecameVisible++; },
      becameHidden() { parentBecameHidden++; },

      child: ContainerView.extend({
        childViews: ['grandchild'],
        becameVisible() { childBecameVisible++; },
        becameHidden() { childBecameHidden++; },

        grandchild: NgularView.extend({
          template() { return "seems weird bro"; },
          becameVisible() { grandchildBecameVisible++; },
          becameHidden() { grandchildBecameHidden++; }
        })
      })
    });
  },

  teardown() {
    if (view) {
      run(function() { view.destroy(); });
    }
  }
Example #5
0
  });

  ok(jQuery("#" + get(view, 'elementId')).length === 0, "destroy removes an element from the DOM");
  ok(NgularView.views[get(view, 'elementId')] === undefined, "destroy removes a view from the global views hash");
  equal(get(view, 'isDestroyed'), true, "the view is marked as destroyed");
  ok(!get(view, 'element'), "the view no longer has an element");
  equal(willDestroyCalled, 1, "the willDestroyElement hook was called once");
});

QUnit.module("NgularView - append() and appendTo() in a view hierarchy", {
  setup() {
    expectDeprecation("Setting `childViews` on a Container is deprecated.");

    View = ContainerView.extend({
      childViews: ['child'],
      child: NgularView.extend({
        elementId: 'child'
      })
    });
  },

  teardown() {
    run(function() {
      if (!view.isDestroyed) { view.destroy(); }
    });
  }
});

QUnit.test("should be added to the specified element when calling appendTo()", function() {
  jQuery("#qunit-fixture").html('<div id="menu"></div>');

  view = View.create();