Lots of work on tests

This commit is contained in:
Robin Ward
2014-07-30 18:56:01 -04:00
parent b6684e7168
commit 6f36d5996d
43 changed files with 248 additions and 311 deletions
+26 -23
View File
@@ -1,85 +1,88 @@
var SomeViewClass = Ember.View.extend(),
containerView;
var SomeViewClass = Ember.View.extend();
function containerHasOnlyOneChild(klass) {
function containerHasOnlyOneChild(containerView, klass) {
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");
}
function containerHasTwoChildren(klass1, klass2) {
function containerHasTwoChildren(containerView, klass1, klass2) {
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");
}
var childHasProperty = function(name) {
function childHasProperty(containerView, name) {
equal(containerView.objectAt(0).get(name), name, "method passes properties to the container's child it creates");
};
}
module("view:container", {
setup: function() {
containerView = Discourse.__container__.lookup('view:container');
}
});
moduleFor("view:container");
test("mixes in Discourse.Presence", function() {
var containerView = this.subject();
ok(Discourse.Presence.detect(containerView));
});
test("attachViewWithArgs: creates a view of a given class with given properties and appends it to the container", function() {
var containerView = this.subject();
containerView.attachViewWithArgs({foo: "foo"}, SomeViewClass);
containerHasOnlyOneChild(SomeViewClass);
childHasProperty("foo");
containerHasOnlyOneChild(containerView, SomeViewClass);
childHasProperty(containerView, "foo");
});
test("attachViewWithArgs: creates a view of a given class without any properties and appends it to the container", function() {
containerView.attachViewWithArgs(null, SomeViewClass);
containerHasOnlyOneChild(SomeViewClass);
var containerView = this.subject();
containerView.attachViewWithArgs(null, SomeViewClass);
containerHasOnlyOneChild(containerView, SomeViewClass);
});
test("attachViewWithArgs: creates a view without class specified (Ember.View is used by default) with given properties and appends it to the container", function() {
var containerView = this.subject();
containerView.attachViewWithArgs({foo: "foo"});
containerHasOnlyOneChild(Ember.View);
childHasProperty("foo");
containerHasOnlyOneChild(containerView, Ember.View);
childHasProperty(containerView, "foo");
});
test("attachViewWithArgs: creates a view without class specified (Ember.View is used by default) without any properties and appends it to the container", function() {
var containerView = this.subject();
containerView.attachViewWithArgs();
containerHasOnlyOneChild(Ember.View);
containerHasOnlyOneChild(containerView, Ember.View);
});
test("attachViewWithArgs: appends a view to a container already containing other views", function() {
var AlreadyContainedViewClass = Ember.View.extend();
var alreadyContainedView = AlreadyContainedViewClass.create();
var containerView = this.subject();
containerView.pushObject(alreadyContainedView);
containerView.attachViewWithArgs(null, SomeViewClass);
containerHasTwoChildren(AlreadyContainedViewClass, SomeViewClass);
containerHasTwoChildren(containerView, AlreadyContainedViewClass, SomeViewClass);
});
test("attachViewClass: creates a view of a given class without any properties and appends it to the container", function() {
var containerView = this.subject();
containerView.attachViewClass(SomeViewClass);
containerHasOnlyOneChild(SomeViewClass);
containerHasOnlyOneChild(containerView, SomeViewClass);
});
test("attachViewClass: creates a view without class specified (Ember.View is used by default) without any properties and appends it to the container", function() {
var containerView = this.subject();
containerView.attachViewClass();
containerHasOnlyOneChild(Ember.View);
containerHasOnlyOneChild(containerView, Ember.View);
});
test("attachViewClass: appends a view to a container already containing other views", function() {
var AlreadyContainedViewClass = Ember.View.extend();
var alreadyContainedView = AlreadyContainedViewClass.create();
var containerView = this.subject();
containerView.pushObject(alreadyContainedView);
containerView.attachViewClass(SomeViewClass);
containerHasTwoChildren(AlreadyContainedViewClass, SomeViewClass);
containerHasTwoChildren(containerView, AlreadyContainedViewClass, SomeViewClass);
});