Upgrade to ember-qunit

This commit is contained in:
Robin Ward
2014-07-30 17:53:14 -04:00
parent d29157dab9
commit b6684e7168
15 changed files with 350 additions and 161 deletions
@@ -1,7 +1,9 @@
module("controller:avatar-selector");
moduleFor("controller:avatar-selector", "controller:avatar-selector", {
needs: ['controller:modal']
});
test("avatarTemplate", function() {
var avatarSelectorController = controllerFor('avatar-selector');
var avatarSelectorController = this.subject();
avatarSelectorController.setProperties({
selected: "system",
system_avatar_upload_id:1,
@@ -1,8 +1,12 @@
module("controller:create-account");
moduleFor("controller:create-account", "controller:create-account", {
needs: ['controller:modal']
});
test('basicUsernameValidation', function() {
var subject = this.subject;
var testInvalidUsername = function(username, expectedReason) {
var controller = controllerFor('create-account');
var controller = subject();
controller.set('accountUsername', username);
equal(controller.get('basicUsernameValidation.failed'), true, 'username should be invalid: ' + username);
equal(controller.get('basicUsernameValidation.reason'), expectedReason, 'username validation reason: ' + username + ', ' + expectedReason);
@@ -12,7 +16,7 @@ test('basicUsernameValidation', function() {
testInvalidUsername('x', I18n.t('user.username.too_short'));
testInvalidUsername('123456789012345678901', I18n.t('user.username.too_long'));
var controller = controllerFor('create-account');
var controller = subject();
controller.set('accountUsername', 'porkchops');
controller.set('prefilledUsername', 'porkchops');
equal(controller.get('basicUsernameValidation.ok'), true, 'Prefilled username is valid');
@@ -13,7 +13,7 @@ var buildAdminUser = function(args) {
}, args || {}));
};
module("controller:flag canDeleteSpammer");
moduleFor("controller:flag");
test("canDeleteSpammer not staff", function(){
var flagController = controllerFor('flag', buildPost());
@@ -1,4 +1,3 @@
var controller;
var notificationFixture = {
notification_type: 1, //mentioned
post_number: 1,
@@ -10,36 +9,26 @@ var notificationFixture = {
}
};
module("controller:notification", {
setup: function() {
controller = testController('notification', notificationFixture);
},
teardown: function() {
controller.set('model', null);
}
});
moduleFor("controller:notification");
test("scope property is correct", function() {
var controller = this.subject(notificationFixture);
equal(controller.get("scope"), "notifications.mentioned");
});
test("username property is correct", function() {
var controller = this.subject(notificationFixture);
equal(controller.get("username"), "velesin");
});
test("link property returns empty string when there is no topic title", function() {
var fixtureWithEmptyTopicTitle = _.extend({}, notificationFixture, {data: {topic_title: ""}});
Ember.run(function() {
controller.set("content", fixtureWithEmptyTopicTitle);
});
var controller = this.subject(fixtureWithEmptyTopicTitle);
equal(controller.get("link"), "");
});
test("link property returns correctly built link when there is a topic title", function() {
var $link = $(controller.get("link"));
equal($link.attr("href"), "/t/a-slug/1234", "generated link points to a correct URL");
equal($link.text(), "some title", "generated link has correct text");
var controller = this.subject(notificationFixture);
ok(controller.get("link").indexOf('/t/a-slug/1234') !== -1, 'has the correct URL');
ok(controller.get("link").indexOf('some title') !== -1, 'has the correct title');
});
@@ -1,83 +1,11 @@
var controller, view;
var appendView = function() {
Ember.run(function() {
view.appendTo(fixture());
});
};
var noItemsMessageSelector = "div.none";
var itemListSelector = "ul";
var itemSelector = "li";
module("controller:notifications", {
setup: function() {
sinon.stub(I18n, "t", function (scope, options) {
options = options || {};
return [scope, options.username, options.link].join(" ").trim();
});
controller = testController('notifications');
view = Ember.View.create({
container: Discourse.__container__,
controller: controller,
templateName: "notifications"
});
},
teardown: function() {
I18n.t.restore();
}
moduleFor('controller:notifications', 'controller:notifications', {
needs: ['controller:header']
});
test("mixes in HasCurrentUser", function() {
ok(Discourse.HasCurrentUser.detect(controller));
ok(Discourse.HasCurrentUser.detect(this.subject()));
});
test("by default uses NotificationController as its item controller", function() {
equal(controller.get("itemController"), "notification");
});
test("shows proper info when there are no notifications", function() {
controller.set("content", null);
appendView();
ok(exists(fixture(noItemsMessageSelector)), "special 'no notifications' message is displayed");
equal(fixture(noItemsMessageSelector).text(), "notifications.none", "'no notifications' message contains proper internationalized text");
equal(count(fixture(itemListSelector)), 0, "a list of notifications is not displayed");
});
test("displays a list of notifications and a 'more' link when there are notifications", function() {
controller.set("itemController", null);
controller.set("content", [
{
read: false,
scope: "scope_1",
username: "username_1",
link: "link_1"
},
{
read: true,
scope: "scope_2",
username: "username_2",
link: "link_2"
}
]);
appendView();
var items = fixture(itemSelector);
equal(count(items), 3, "number of list items is correct");
equal(items.eq(0).attr("class"), "ember-view", "first (unread) item has proper class");
equal(items.eq(0).text().trim(), "scope_1 username_1 link_1", "first item has correct content");
equal(items.eq(1).attr("class"), "ember-view read", "second (read) item has proper class");
equal(items.eq(1).text().trim(), "scope_2 username_2 link_2", "second item has correct content");
var moreLink = items.eq(2).find("> a");
equal(moreLink.attr("href"), Discourse.User.current().get("path"), "'more' link points to a correct URL");
equal(moreLink.text(), "notifications.more …", "'more' link has correct text");
equal(this.subject().get("itemController"), "notification");
});
@@ -1,4 +1,7 @@
module("Discourse.TopicController");
moduleFor('controller:topic', 'controller:topic', {
needs: ['controller:header', 'controller:modal', 'controller:composer', 'controller:quote-button',
'controller:search', 'controller:topic-progress']
});
var buildTopic = function() {
return Discourse.Topic.create({
@@ -11,9 +14,10 @@ var buildTopic = function() {
});
};
test("editingMode", function() {
var topic = buildTopic(),
topicController = testController(Discourse.TopicController, topic);
topicController = this.subject({model: topic});
ok(!topicController.get('editingTopic'), "we are not editing by default");
@@ -32,7 +36,7 @@ test("editingMode", function() {
});
test("toggledSelectedPost", function() {
var tc = testController(Discourse.TopicController, buildTopic()),
var tc = this.subject({ model: buildTopic() }),
post = Discourse.Post.create({id: 123, post_number: 2}),
postStream = tc.get('postStream');
@@ -54,7 +58,7 @@ test("toggledSelectedPost", function() {
});
test("selectAll", function() {
var tc = testController(Discourse.TopicController, buildTopic()),
var tc = this.subject({model: buildTopic()}),
post = Discourse.Post.create({id: 123, post_number: 2}),
postStream = tc.get('postStream');
@@ -72,7 +76,7 @@ test("selectAll", function() {
test("Automating setting of allPostsSelected", function() {
var topic = buildTopic(),
tc = testController(Discourse.TopicController, topic),
tc = this.subject({model: topic}),
post = Discourse.Post.create({id: 123, post_number: 2}),
postStream = tc.get('postStream');
@@ -89,7 +93,7 @@ test("Automating setting of allPostsSelected", function() {
test("Select Replies when present", function() {
var topic = buildTopic(),
tc = testController(Discourse.TopicController, topic),
tc = this.subject({ model: topic }),
p1 = Discourse.Post.create({id: 1, post_number: 1, reply_count: 1}),
p2 = Discourse.Post.create({id: 2, post_number: 2}),
p3 = Discourse.Post.create({id: 2, post_number: 3, reply_to_post_number: 1});