mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 11:11:13 +08:00
Upgrade to ember-qunit
This commit is contained in:
@ -1,29 +1,26 @@
|
||||
module("controller:admin-badges");
|
||||
moduleFor("controller:admin-badges", "controller:admin-badges", {
|
||||
needs: ['controller:modal', 'controller:admin-badge']
|
||||
});
|
||||
|
||||
test("canEditDescription", function() {
|
||||
var badge, controller;
|
||||
|
||||
badge = Discourse.Badge.create({id: 101, name: "Test Badge"});
|
||||
controller = testController("admin-badges", [badge]);
|
||||
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"});
|
||||
var controller = this.subject({ model: [badge] });
|
||||
controller.send('selectBadge', badge);
|
||||
ok(controller.get('canEditDescription'), "allows editing description when a translation exists for the badge name");
|
||||
|
||||
this.stub(I18n, "t").returns("translated string");
|
||||
badge = Discourse.Badge.create({id: 102, name: "Test Badge"});
|
||||
controller = testController("admin-badges", [badge]);
|
||||
controller.send('selectBadge', badge);
|
||||
ok(!controller.get('canEditDescription'), "shows the displayName when it is different from the name");
|
||||
badge.set('translatedDescription', 'translated');
|
||||
ok(!controller.get('canEditDescription'), "can't edit the description when it's got a translation");
|
||||
});
|
||||
|
||||
test("createNewBadge", function() {
|
||||
var controller = testController("admin-badges", []);
|
||||
var controller = this.subject();
|
||||
controller.send('createNewBadge');
|
||||
equal(controller.get('model.length'), 1, "adds a new badge to the list of badges");
|
||||
});
|
||||
|
||||
test("selectBadge", function() {
|
||||
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}),
|
||||
controller = testController("admin-badges", [badge]);
|
||||
controller = this.subject({ model: [badge] });
|
||||
|
||||
controller.send('selectBadge', badge);
|
||||
equal(controller.get('selectedItem'), badge, "the badge is selected");
|
||||
@ -32,10 +29,10 @@ test("selectBadge", function() {
|
||||
test("save", function() {
|
||||
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}),
|
||||
otherBadge = Discourse.Badge.create({id: 102, name: "Other Badge"}),
|
||||
controller = testController("admin-badges", [badge, otherBadge]);
|
||||
controller = this.subject({ model: [badge, otherBadge] });
|
||||
|
||||
controller.send('selectBadge', badge);
|
||||
this.stub(badge, "save").returns(Ember.RSVP.resolve({}));
|
||||
sinon.stub(badge, "save").returns(Ember.RSVP.resolve({}));
|
||||
controller.send("save");
|
||||
ok(badge.save.calledOnce, "called save on the badge");
|
||||
});
|
||||
@ -43,9 +40,9 @@ test("save", function() {
|
||||
test("destroy", function() {
|
||||
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}),
|
||||
otherBadge = Discourse.Badge.create({id: 102, name: "Other Badge"}),
|
||||
controller = testController("admin-badges", [badge, otherBadge]);
|
||||
controller = this.subject({model: [badge, otherBadge]});
|
||||
|
||||
this.stub(badge, 'destroy').returns(Ember.RSVP.resolve({}));
|
||||
sinon.stub(badge, 'destroy').returns(Ember.RSVP.resolve({}));
|
||||
|
||||
bootbox.confirm = function(text, yes, no, func) {
|
||||
func(false);
|
||||
|
@ -1,5 +1,5 @@
|
||||
module("controller:admin-email-index");
|
||||
moduleFor("controller:admin-email-index");
|
||||
|
||||
test("mixes in Discourse.Presence", function() {
|
||||
ok(Discourse.Presence.detect(controllerFor("admin-email-index")));
|
||||
ok(Discourse.Presence.detect(this.subject()));
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
module("controller:admin-email-preview-digest");
|
||||
moduleFor("controller:admin-email-preview-digest");
|
||||
|
||||
test("mixes in Discourse.Presence", function() {
|
||||
ok(Discourse.Presence.detect(controllerFor("admin-email-preview-digest")));
|
||||
ok(Discourse.Presence.detect(this.subject()));
|
||||
});
|
||||
|
@ -1,27 +1,20 @@
|
||||
module("controller:admin-site-settings", {
|
||||
setup: function() {
|
||||
sinon.stub(Ember.run, "debounce").callsArg(1);
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
Ember.run.debounce.restore();
|
||||
}
|
||||
});
|
||||
moduleFor("controller:admin-site-settings");
|
||||
|
||||
test("filter", function() {
|
||||
var allSettings = Em.A([Ember.Object.create({
|
||||
var allSettings = [Ember.Object.create({
|
||||
nameKey: 'users', name: 'users',
|
||||
siteSettings: [Discourse.SiteSetting.create({"setting":"username_change_period","description":"x","default":3,"type":"fixnum","value":"3","category":"users"})]
|
||||
}), Ember.Object.create({
|
||||
nameKey: 'posting', name: 'posting',
|
||||
siteSettings: [Discourse.SiteSetting.create({"setting":"display_name_on_posts","description":"x","default":false,"type":"bool","value":"true","category":"posting"})]
|
||||
})]);
|
||||
var adminSiteSettingsController = testController("admin-site-settings", allSettings);
|
||||
})];
|
||||
var adminSiteSettingsController = this.subject({ model: allSettings });
|
||||
adminSiteSettingsController.set('allSiteSettings', allSettings);
|
||||
|
||||
equal(adminSiteSettingsController.get('content')[0].nameKey, 'users', "Can get first site setting category's name key.");
|
||||
|
||||
adminSiteSettingsController.set('filter', 'username_change');
|
||||
|
||||
equal(adminSiteSettingsController.get('content').length, 2, "a. Filter with one match for username_change");
|
||||
equal(adminSiteSettingsController.get('content')[0].nameKey, "all_results", "b. First element is all the results that match");
|
||||
equal(adminSiteSettingsController.get('content')[1].nameKey, "users", "c. Filter with one match for username_change");
|
||||
|
@ -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});
|
||||
|
4
test/javascripts/helpers/init-ember-qunit.js
Normal file
4
test/javascripts/helpers/init-ember-qunit.js
Normal file
@ -0,0 +1,4 @@
|
||||
/* global emq */
|
||||
|
||||
emq.globalize();
|
||||
emq.setResolver(Discourse.Resolver.create({ namespace: Discourse }));
|
@ -26,29 +26,6 @@ function integration(name, lifecycle) {
|
||||
});
|
||||
}
|
||||
|
||||
function testController(klass, model) {
|
||||
// HAX until we get ES6 everywhere:
|
||||
if (typeof klass === "string") {
|
||||
var base = "discourse",
|
||||
moduleName,
|
||||
module;
|
||||
|
||||
// maybe a bit too hacky? (all of the "admin-*" controllers are in the "admin" directory)
|
||||
if (klass.indexOf("admin") === 0) {
|
||||
base = "admin";
|
||||
}
|
||||
|
||||
moduleName = base + '/controllers/' + klass;
|
||||
module = requirejs.entries[moduleName];
|
||||
|
||||
if (module) {
|
||||
klass = require(moduleName, null, null, true).default;
|
||||
}
|
||||
}
|
||||
|
||||
return klass.create({model: model, container: Discourse.__container__});
|
||||
}
|
||||
|
||||
function controllerFor(controller, model) {
|
||||
controller = Discourse.__container__.lookup('controller:' + controller);
|
||||
if (model) { controller.set('model', model ); }
|
||||
|
@ -14,6 +14,7 @@
|
||||
//= require handlebars.js
|
||||
//= require development/ember.js
|
||||
//= require message-bus.js
|
||||
//= require ember-qunit.js
|
||||
|
||||
//= require ../../app/assets/javascripts/locales/i18n
|
||||
//= require ../../app/assets/javascripts/discourse/helpers/i18n_helpers
|
||||
@ -41,6 +42,7 @@
|
||||
//= require helpers/qunit_helpers
|
||||
//= require helpers/assertions
|
||||
|
||||
//= require helpers/init-ember-qunit
|
||||
//= require_tree ./fixtures
|
||||
//= require_tree ./lib
|
||||
//= require_tree .
|
||||
@ -95,5 +97,11 @@ QUnit.testStart(function() {
|
||||
Discourse.SiteSettings = jQuery.extend(true, {}, Discourse.SiteSettingsOriginal);
|
||||
Discourse.BaseUri = "/";
|
||||
Discourse.BaseUrl = "";
|
||||
|
||||
// Never debounce in test, just makes testing harder
|
||||
sinon.stub(Ember.run, "debounce").callsArg(1)
|
||||
});
|
||||
|
||||
QUnit.testDone(function() {
|
||||
Ember.run.debounce.restore();
|
||||
});
|
||||
|
Reference in New Issue
Block a user