Lots of work on tests
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
module("Discourse.HeaderView");
|
||||
moduleFor("view:header");
|
||||
|
||||
test("showNotifications", function() {
|
||||
var controllerSpy = {
|
||||
send: sinon.spy()
|
||||
};
|
||||
var view = viewClassFor('header').create({
|
||||
controller: controllerSpy
|
||||
});
|
||||
|
||||
var view = this.subject({controller: controllerSpy});
|
||||
view.showNotifications();
|
||||
|
||||
ok(controllerSpy.send.calledWith("showNotifications", view), "sends showNotifications message to the controller, passing header view as a param");
|
||||
|
||||
@@ -1,59 +1,17 @@
|
||||
var appendTextFieldWithProperties = function(properties) {
|
||||
var view = componentClassFor('text-field').create(properties);
|
||||
Ember.run(function() {
|
||||
view.appendTo(fixture());
|
||||
});
|
||||
};
|
||||
|
||||
var hasAttr = function($element, attrName, attrValue) {
|
||||
equal($element.attr(attrName), attrValue, "'" + attrName + "' attribute is correctly rendered");
|
||||
};
|
||||
|
||||
var hasNoAttr = function($element, attrName) {
|
||||
equal($element.attr(attrName), undefined, "'" + attrName + "' attribute is not rendered");
|
||||
};
|
||||
|
||||
module("view:text-field");
|
||||
moduleForComponent("text-field");
|
||||
|
||||
test("renders correctly with no properties set", function() {
|
||||
appendTextFieldWithProperties({});
|
||||
|
||||
var $input = fixture("input");
|
||||
hasAttr($input, "type", "text");
|
||||
hasAttr($input, "placeholder", "");
|
||||
hasNoAttr($input, "autocorrect");
|
||||
hasNoAttr($input, "autocapitalize");
|
||||
hasNoAttr($input, "autofocus");
|
||||
var component = this.subject();
|
||||
equal(component.get('type'), "text");
|
||||
});
|
||||
|
||||
test("renders correctly with all allowed properties set", function() {
|
||||
this.stub(I18n, "t").returnsArg(0);
|
||||
test("support a placeholder", function() {
|
||||
sandbox.stub(I18n, "t").returnsArg(0);
|
||||
|
||||
appendTextFieldWithProperties({
|
||||
autocorrect: "on",
|
||||
autocapitalize: "off",
|
||||
autofocus: "autofocus",
|
||||
var component = this.subject({
|
||||
placeholderKey: "placeholder.i18n.key"
|
||||
});
|
||||
|
||||
var $input = fixture("input");
|
||||
hasAttr($input, "type", "text");
|
||||
hasAttr($input, "placeholder", "placeholder.i18n.key");
|
||||
hasAttr($input, "autocorrect", "on");
|
||||
hasAttr($input, "autocapitalize", "off");
|
||||
hasAttr($input, "autofocus", "autofocus");
|
||||
equal(component.get('type'), "text");
|
||||
equal(component.get('placeholder'), "placeholder.i18n.key");
|
||||
});
|
||||
|
||||
// NEIL commented out this test. It fails now that TextField is in the components dir.
|
||||
|
||||
// test("is registered as helper", function() {
|
||||
// var view = Ember.View.create({
|
||||
// template: Ember.Handlebars.compile("{{text-field}}")
|
||||
// });
|
||||
|
||||
// Ember.run(function() {
|
||||
// view.appendTo(fixture());
|
||||
// });
|
||||
|
||||
// ok(exists(fixture("input")));
|
||||
// });
|
||||
|
||||
Reference in New Issue
Block a user