discourse/test/javascripts/views/container-view-test.js.es6

91 lines
3.8 KiB
Text
Raw Normal View History

2015-04-08 14:17:21 -04:00
import Presence from 'discourse/mixins/presence';
2014-07-30 18:56:01 -04:00
var SomeViewClass = Ember.View.extend();
2013-10-16 11:47:51 -04:00
2014-07-30 18:56:01 -04:00
function containerHasOnlyOneChild(containerView, klass) {
2014-07-18 12:19:47 -04:00
equal(containerView.get('childViews').length, 1, "container has no other children than the one created by method");
ok(containerView.objectAt(0) instanceof klass, "container's child created by method is an instance of a correct class");
}
2013-10-16 11:47:51 -04:00
2014-07-30 18:56:01 -04:00
function containerHasTwoChildren(containerView, klass1, klass2) {
2014-07-18 12:19:47 -04:00
equal(containerView.get('childViews').length, 2, "container has both already existing and newly created children");
ok(containerView.objectAt(0) instanceof klass1, "already existing child's class is correct");
ok(containerView.objectAt(1) instanceof klass2, "newly created child's class is correct");
}
2013-10-16 11:47:51 -04:00
2014-07-30 18:56:01 -04:00
function childHasProperty(containerView, name) {
2014-07-18 12:19:47 -04:00
equal(containerView.objectAt(0).get(name), name, "method passes properties to the container's child it creates");
2014-07-30 18:56:01 -04:00
}
2013-10-16 11:47:51 -04:00
2014-07-30 18:56:01 -04:00
moduleFor("view:container");
2013-10-16 11:47:51 -04:00
2015-04-08 14:17:21 -04:00
test("mixes in Presence", function() {
2014-07-30 18:56:01 -04:00
var containerView = this.subject();
2015-04-08 14:17:21 -04:00
ok(Presence.detect(containerView));
2013-10-16 11:47:51 -04:00
});
test("attachViewWithArgs: creates a view of a given class with given properties and appends it to the container", function() {
2014-07-30 18:56:01 -04:00
var containerView = this.subject();
2014-07-18 12:19:47 -04:00
containerView.attachViewWithArgs({foo: "foo"}, SomeViewClass);
2014-07-30 18:56:01 -04:00
containerHasOnlyOneChild(containerView, SomeViewClass);
childHasProperty(containerView, "foo");
2013-10-16 11:47:51 -04:00
});
test("attachViewWithArgs: creates a view of a given class without any properties and appends it to the container", function() {
2014-07-30 18:56:01 -04:00
var containerView = this.subject();
containerView.attachViewWithArgs(null, SomeViewClass);
containerHasOnlyOneChild(containerView, SomeViewClass);
2013-10-16 11:47:51 -04:00
});
test("attachViewWithArgs: creates a view without class specified (Ember.View is used by default) with given properties and appends it to the container", function() {
2014-07-30 18:56:01 -04:00
var containerView = this.subject();
2014-07-18 12:19:47 -04:00
containerView.attachViewWithArgs({foo: "foo"});
2013-10-16 11:47:51 -04:00
2014-07-30 18:56:01 -04:00
containerHasOnlyOneChild(containerView, Ember.View);
childHasProperty(containerView, "foo");
2013-10-16 11:47:51 -04:00
});
test("attachViewWithArgs: creates a view without class specified (Ember.View is used by default) without any properties and appends it to the container", function() {
2014-07-30 18:56:01 -04:00
var containerView = this.subject();
2014-07-18 12:19:47 -04:00
containerView.attachViewWithArgs();
2013-10-16 11:47:51 -04:00
2014-07-30 18:56:01 -04:00
containerHasOnlyOneChild(containerView, Ember.View);
2013-10-16 11:47:51 -04:00
});
test("attachViewWithArgs: appends a view to a container already containing other views", function() {
var AlreadyContainedViewClass = Ember.View.extend();
var alreadyContainedView = AlreadyContainedViewClass.create();
2014-07-30 18:56:01 -04:00
var containerView = this.subject();
2014-07-18 12:19:47 -04:00
containerView.pushObject(alreadyContainedView);
2013-10-16 11:47:51 -04:00
2014-07-18 12:19:47 -04:00
containerView.attachViewWithArgs(null, SomeViewClass);
2013-10-16 11:47:51 -04:00
2014-07-30 18:56:01 -04:00
containerHasTwoChildren(containerView, AlreadyContainedViewClass, SomeViewClass);
2013-10-16 11:47:51 -04:00
});
test("attachViewClass: creates a view of a given class without any properties and appends it to the container", function() {
2014-07-30 18:56:01 -04:00
var containerView = this.subject();
2014-07-18 12:19:47 -04:00
containerView.attachViewClass(SomeViewClass);
2013-10-16 11:47:51 -04:00
2014-07-30 18:56:01 -04:00
containerHasOnlyOneChild(containerView, SomeViewClass);
2013-10-16 11:47:51 -04:00
});
test("attachViewClass: creates a view without class specified (Ember.View is used by default) without any properties and appends it to the container", function() {
2014-07-30 18:56:01 -04:00
var containerView = this.subject();
2014-07-18 12:19:47 -04:00
containerView.attachViewClass();
2013-10-16 11:47:51 -04:00
2014-07-30 18:56:01 -04:00
containerHasOnlyOneChild(containerView, Ember.View);
2013-10-16 11:47:51 -04:00
});
test("attachViewClass: appends a view to a container already containing other views", function() {
var AlreadyContainedViewClass = Ember.View.extend();
var alreadyContainedView = AlreadyContainedViewClass.create();
2014-07-30 18:56:01 -04:00
var containerView = this.subject();
2014-07-18 12:19:47 -04:00
containerView.pushObject(alreadyContainedView);
2013-10-16 11:47:51 -04:00
2014-07-18 12:19:47 -04:00
containerView.attachViewClass(SomeViewClass);
2013-10-16 11:47:51 -04:00
2014-07-30 18:56:01 -04:00
containerHasTwoChildren(containerView, AlreadyContainedViewClass, SomeViewClass);
2013-10-16 11:47:51 -04:00
});