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
+5 -5
View File
@@ -11,7 +11,7 @@ test('displayName', function() {
var badge1 = Discourse.Badge.create({id: 1, name: "Test Badge 1"});
equal(badge1.get('displayName'), "Test Badge 1", "falls back to the original name in the absence of a translation");
this.stub(I18n, "t").returnsArg(0);
sandbox.stub(I18n, "t").returnsArg(0);
var badge2 = Discourse.Badge.create({id: 2, name: "Test Badge 2"});
equal(badge2.get('displayName'), "badges.badge.test_badge_2.name", "uses translation when available");
});
@@ -21,7 +21,7 @@ test('translatedDescription', function() {
equal(badge1.get('translatedDescription'), null, "returns null when no translation exists");
var badge2 = Discourse.Badge.create({id: 2, name: "Test Badge 2 **"});
this.stub(I18n, "t").returns("description translation");
sandbox.stub(I18n, "t").returns("description translation");
equal(badge2.get('translatedDescription'), "description translation", "users translated description");
});
@@ -30,7 +30,7 @@ test('displayDescription', function() {
equal(badge1.get('displayDescription'), "TEST", "returns original description when no translation exists");
var badge2 = Discourse.Badge.create({id: 2, name: "Test Badge 2 **"});
this.stub(I18n, "t").returns("description translation");
sandbox.stub(I18n, "t").returns("description translation");
equal(badge2.get('displayDescription'), "description translation", "users translated description");
});
@@ -61,7 +61,7 @@ test('updateFromJson', function() {
});
test('save', function() {
this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({}));
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({}));
var badge = Discourse.Badge.create({name: "New Badge", description: "This is a new badge.", badge_type_id: 1});
// TODO: clean API
badge.save(["name", "description", "badge_type_id"]);
@@ -69,7 +69,7 @@ test('save', function() {
});
test('destroy', function() {
this.stub(Discourse, 'ajax');
sandbox.stub(Discourse, 'ajax');
var badge = Discourse.Badge.create({name: "New Badge", description: "This is a new badge.", badge_type_id: 1});
badge.destroy();
ok(!Discourse.ajax.calledOnce, "no AJAX call for a new badge");
+2 -2
View File
@@ -31,7 +31,7 @@ test('findBySlug', function() {
luke = Discourse.Category.create({id: 2, slug: 'luke', parentCategory: darth}),
categoryList = [darth, luke];
this.stub(Discourse.Category, 'list').returns(categoryList);
sandbox.stub(Discourse.Category, 'list').returns(categoryList);
equal(Discourse.Category.findBySlug('darth'), darth, 'we can find a parent category');
equal(Discourse.Category.findBySlug('luke', 'darth'), luke, 'we can find a child with parent');
@@ -45,7 +45,7 @@ test('findByIds', function() {
2: Discourse.Category.create({id: 2})
};
this.stub(Discourse.Category, 'idMap').returns(categories);
sandbox.stub(Discourse.Category, 'idMap').returns(categories);
deepEqual(Discourse.Category.findByIds([1,2,3]), _.values(categories));
});
+6 -6
View File
@@ -1,6 +1,6 @@
module("Discourse.Composer", {
setup: function() {
sinon.stub(Discourse.User, 'currentProp').withArgs('admin').returns(false);
sandbox.stub(Discourse.User, 'currentProp').withArgs('admin').returns(false);
},
teardown: function() {
@@ -130,7 +130,7 @@ test("Title length for private messages", function() {
});
test('importQuote with no data', function() {
this.stub(Discourse.Post, 'load');
sandbox.stub(Discourse.Post, 'load');
var composer = Discourse.Composer.create();
composer.importQuote();
blank(composer.get('reply'), 'importing with no topic adds nothing');
@@ -158,7 +158,7 @@ test('editingFirstPost', function() {
asyncTestDiscourse('importQuote with a post', function() {
expect(1);
this.stub(Discourse.Post, 'load').withArgs(123).returns(Em.Deferred.promise(function (p) {
sandbox.stub(Discourse.Post, 'load').withArgs(123).returns(Em.Deferred.promise(function (p) {
p.resolve(Discourse.Post.create({raw: "let's quote"}));
}));
@@ -172,7 +172,7 @@ asyncTestDiscourse('importQuote with a post', function() {
asyncTestDiscourse('importQuote with no post', function() {
expect(1);
this.stub(Discourse.Post, 'load').withArgs(4).returns(Em.Deferred.promise(function (p) {
sandbox.stub(Discourse.Post, 'load').withArgs(4).returns(Em.Deferred.promise(function (p) {
p.resolve(Discourse.Post.create({raw: 'quote me'}));
}));
@@ -243,7 +243,7 @@ test('open with a quote', function() {
module("Discourse.Composer as admin", {
setup: function() {
sinon.stub(Discourse.User, 'currentProp').withArgs('admin').returns(true);
sandbox.stub(Discourse.User, 'currentProp').withArgs('admin').returns(true);
},
teardown: function() {
@@ -267,4 +267,4 @@ test("Title length for regular topics as admin", function() {
composer.set('title', '');
ok(!composer.get('titleLengthValid'), "admins must set title to at least 1 character");
});
});
+1 -1
View File
@@ -2,4 +2,4 @@ module("Discourse.EmailLog");
test("create", function() {
ok(Discourse.EmailLog.create(), "it can be created without arguments");
});
});
+1 -1
View File
@@ -2,4 +2,4 @@ module("Discourse.Invite");
test("create", function() {
ok(Discourse.Invite.create(), "it can be created without arguments");
});
});
+9 -9
View File
@@ -111,7 +111,7 @@ test("removePosts", function() {
test("cancelFilter", function() {
var postStream = buildStream(1235);
this.stub(postStream, "refresh");
sandbox.stub(postStream, "refresh");
postStream.set('summary', true);
postStream.cancelFilter();
@@ -124,7 +124,7 @@ test("cancelFilter", function() {
test("toggleParticipant", function() {
var postStream = buildStream(1236);
this.stub(postStream, "refresh");
sandbox.stub(postStream, "refresh");
equal(postStream.get('userFilters.length'), 0, "by default no participants are toggled");
@@ -137,7 +137,7 @@ test("toggleParticipant", function() {
test("streamFilters", function() {
var postStream = buildStream(1237);
this.stub(postStream, "refresh");
sandbox.stub(postStream, "refresh");
deepEqual(postStream.get('streamFilters'), {}, "there are no postFilters by default");
ok(postStream.get('hasNoFilters'), "there are no filters by default");
@@ -254,7 +254,7 @@ asyncTestDiscourse("loadIntoIdentityMap with no data", function() {
var postStream = buildStream(1234);
expect(1);
this.stub(Discourse, "ajax");
sandbox.stub(Discourse, "ajax");
postStream.loadIntoIdentityMap([]).then(function() {
ok(!Discourse.ajax.calledOnce, "an empty array returned a promise yet performed no ajax request");
start();
@@ -265,7 +265,7 @@ asyncTestDiscourse("loadIntoIdentityMap with post ids", function() {
var postStream = buildStream(1234);
expect(1);
this.stub(Discourse, "ajax").returns(Ember.RSVP.resolve({
sandbox.stub(Discourse, "ajax").returns(Ember.RSVP.resolve({
post_stream: {
posts: [{id: 10, post_number: 10}]
}
@@ -285,7 +285,7 @@ asyncTestDiscourse("loading a post's history", function() {
var secondPost = Discourse.Post.create({id: 2222});
this.stub(Discourse, "ajax").returns(Ember.RSVP.resolve([secondPost]));
sandbox.stub(Discourse, "ajax").returns(Ember.RSVP.resolve([secondPost]));
postStream.findReplyHistory(post).then(function() {
ok(Discourse.ajax.calledOnce, "it made the ajax request");
present(postStream.findLoadedPost(2222), "it stores the returned post in the identity map");
@@ -367,8 +367,8 @@ test("staging and committing a post", function() {
test('triggerNewPostInStream', function() {
var postStream = buildStream(225566);
this.stub(postStream, 'appendMore');
this.stub(postStream, 'refresh');
sandbox.stub(postStream, 'appendMore');
sandbox.stub(postStream, 'refresh');
postStream.triggerNewPostInStream(null);
ok(!postStream.appendMore.calledOnce, "asking for a null id does nothing");
@@ -418,7 +418,7 @@ test("comitting and triggerNewPostInStream race condition", function() {
equal(postStream.get('filteredPostsCount'), 0, "it has no filteredPostsCount yet");
stagedPost.set('id', 123);
this.stub(postStream, 'appendMore');
sandbox.stub(postStream, 'appendMore');
postStream.triggerNewPostInStream(123);
equal(postStream.get('filteredPostsCount'), 1, "it added the post");
+2 -2
View File
@@ -59,7 +59,7 @@ test('destroy by staff', function() {
var user = Discourse.User.create({username: 'staff', staff: true});
var post = buildPost({user: user});
this.stub(Discourse, 'ajax').returns(new Em.Deferred());
sandbox.stub(Discourse, 'ajax').returns(new Em.Deferred());
post.destroy(user);
present(post.get('deleted_at'), "it has a `deleted_at` field.");
@@ -77,7 +77,7 @@ test('destroy by non-staff', function() {
var user = Discourse.User.create({username: 'evil trout'});
var post = buildPost({user: user, cooked: originalCooked});
this.stub(Discourse, 'ajax');
sandbox.stub(Discourse, 'ajax');
post.destroy(user);
ok(!post.get('can_delete'), "the post can't be deleted again in this session");
+1 -1
View File
@@ -3,4 +3,4 @@ module("Discourse.Session");
test('highestSeenByTopic', function() {
var session = Discourse.Session.current();
deepEqual(session.get('highestSeenByTopic'), {}, "by default it returns an empty object");
});
});
+1 -1
View File
@@ -36,4 +36,4 @@ test('create categories', function() {
present(subcategory, "it loaded the subcategory");
equal(subcategory.get('parentCategory'), parent, "it has associated the child with the parent");
});
});
@@ -2,4 +2,4 @@ module("Discourse.StaffActionLog");
test("create", function() {
ok(Discourse.StaffActionLog.create(), "it can be created without arguments");
});
});
+3 -3
View File
@@ -48,7 +48,7 @@ test("destroy", function() {
var user = Discourse.User.create({username: 'eviltrout'});
var topic = Discourse.Topic.create({id: 1234});
this.stub(Discourse, 'ajax');
sandbox.stub(Discourse, 'ajax');
topic.destroy(user);
present(topic.get('deleted_at'), 'deleted at is set');
@@ -60,10 +60,10 @@ test("recover", function() {
var user = Discourse.User.create({username: 'eviltrout'});
var topic = Discourse.Topic.create({id: 1234, deleted_at: new Date(), deleted_by: user});
this.stub(Discourse, 'ajax');
sandbox.stub(Discourse, 'ajax');
topic.recover();
blank(topic.get('deleted_at'), "it clears deleted_at");
blank(topic.get('deleted_by'), "it clears deleted_by");
//ok(Discourse.ajax.calledOnce, "it called recover over the wire");
});
});
+4 -4
View File
@@ -19,7 +19,7 @@ test('createFromJson array', function() {
asyncTestDiscourse('findByUsername', function() {
expect(2);
this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve(multipleBadgesJson));
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve(multipleBadgesJson));
Discourse.UserBadge.findByUsername("anne3").then(function(badges) {
ok(Array.isArray(badges), "returns an array");
start();
@@ -29,7 +29,7 @@ asyncTestDiscourse('findByUsername', function() {
asyncTestDiscourse('findByBadgeId', function() {
expect(2);
this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve(multipleBadgesJson));
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve(multipleBadgesJson));
Discourse.UserBadge.findByBadgeId(880).then(function(badges) {
ok(Array.isArray(badges), "returns an array");
start();
@@ -39,7 +39,7 @@ asyncTestDiscourse('findByBadgeId', function() {
asyncTestDiscourse('grant', function() {
expect(2);
this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve(singleBadgeJson));
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve(singleBadgeJson));
Discourse.UserBadge.grant(1, "username").then(function(userBadge) {
ok(!Array.isArray(userBadge), "does not return an array");
start();
@@ -48,7 +48,7 @@ asyncTestDiscourse('grant', function() {
});
test('revoke', function() {
this.stub(Discourse, 'ajax');
sandbox.stub(Discourse, 'ajax');
var userBadge = Discourse.UserBadge.create({id: 1});
userBadge.revoke();
ok(Discourse.ajax.calledOnce, "makes an AJAX call");