Upgrade Notifications to fix deprecations and use store

This commit is contained in:
Robin Ward
2015-05-05 13:44:19 -04:00
parent aab9706b7a
commit 0b65c88003
22 changed files with 133 additions and 323 deletions

View File

@@ -1,33 +0,0 @@
moduleFor("controller:header", "controller:header", {
needs: ['controller:application']
});
test("showNotifications action", function() {
let resolveRequestWith;
const request = new Ember.RSVP.Promise(function(resolve) {
resolveRequestWith = resolve;
});
const currentUser = Discourse.User.create({ unread_notifications: 1});
const controller = this.subject({ currentUser: currentUser });
const viewSpy = { showDropdownBySelector: sinon.spy() };
sandbox.stub(Discourse, "ajax").withArgs("/notifications").returns(request);
Ember.run(function() {
controller.send("showNotifications", viewSpy);
});
equal(controller.get("notifications"), null, "notifications are null before data has finished loading");
equal(currentUser.get("unread_notifications"), 1, "current user's unread notifications count is not zeroed before data has finished loading");
ok(viewSpy.showDropdownBySelector.calledWith("#user-notifications"), "dropdown with loading glyph is shown before data has finished loading");
Ember.run(function() {
resolveRequestWith(["notification"]);
});
// Can't use deepEquals because controller.get("notifications") is an ArrayProxy, not an Array
ok(controller.get("notifications").indexOf("notification") !== -1, "notification is in the controller");
equal(currentUser.get("unread_notifications"), 0, "current user's unread notifications count is zeroed after data has finished loading");
ok(viewSpy.showDropdownBySelector.calledWith("#user-notifications"), "dropdown with notifications is shown after data has finished loading");
});

View File

@@ -1,56 +0,0 @@
import Site from 'discourse/models/site';
function buildFixture() {
return {
notification_type: 1, //mentioned
post_number: 1,
topic_id: 1234,
slug: "a-slug",
data: {
topic_title: "some title",
display_username: "velesin"
},
site: Site.current()
};
}
moduleFor("controller:notification");
test("scope property is correct", function() {
const controller = this.subject(buildFixture());
equal(controller.get("scope"), "notifications.mentioned");
});
test("username property is correct", function() {
const controller = this.subject(buildFixture());
equal(controller.get("username"), "velesin");
});
test("description property returns badge name when there is one", function() {
const fixtureWithBadgeName = _.extend({}, buildFixture(), { data: { badge_name: "badge" } });
const controller = this.subject(fixtureWithBadgeName);
equal(controller.get("description"), "badge");
});
test("description property returns empty string when there is no topic title", function() {
const fixtureWithEmptyTopicTitle = _.extend({}, buildFixture(), { data: { topic_title: "" } });
const controller = this.subject(fixtureWithEmptyTopicTitle);
equal(controller.get("description"), "");
});
test("description property returns topic title", function() {
const fixtureWithTopicTitle = _.extend({}, buildFixture(), { data: { topic_title: "topic" } });
const controller = this.subject(fixtureWithTopicTitle);
equal(controller.get("description"), "topic");
});
test("url property returns badge's url when there is a badge", function() {
const fixtureWithBadge = _.extend({}, buildFixture(), { data: { badge_id: 1, badge_name: "Badge Name"} });
const controller = this.subject(fixtureWithBadge);
equal(controller.get("url"), "/badges/1/badge-name");
});
test("url property returns topic's url when there is a topic", function() {
const controller = this.subject(buildFixture());
equal(controller.get("url"), "/t/a-slug/1234");
});

View File

@@ -1,2 +1,2 @@
/*jshint maxlen:10000000 */
export default {"/notifications": [ { notification_type: 2, read: true, post_number: 2, topic_id: 1234, slug: "a-slug", data: { topic_title: "some title", display_username: "velesin" } } ] };
export default {"/notifications": {notifications: [ { id: 123, notification_type: 2, read: true, post_number: 2, topic_id: 1234, slug: "a-slug", data: { topic_title: "some title", display_username: "velesin" } } ] }};

View File

@@ -36,7 +36,7 @@ test('updating simultaneously', function() {
expect(2);
const store = createStore();
store.find('widget', 123).then(function(widget) {
return store.find('widget', 123).then(function(widget) {
const firstPromise = widget.update({ name: 'new name' });
const secondPromise = widget.update({ name: 'new name' });
@@ -90,7 +90,7 @@ test('creating simultaneously', function() {
test('destroyRecord', function() {
const store = createStore();
store.find('widget', 123).then(function(widget) {
return store.find('widget', 123).then(function(widget) {
widget.destroyRecord().then(function(result) {
ok(result);
});

View File

@@ -20,6 +20,7 @@ test('pagination support', function() {
equal(rs.get('totalRows'), 4);
ok(rs.get('loadMoreUrl'), 'has a url to load more');
ok(!rs.get('loadingMore'), 'it is not loading more');
ok(rs.get('canLoadMore'));
const promise = rs.loadMore();
@@ -28,6 +29,7 @@ test('pagination support', function() {
ok(!rs.get('loadingMore'), 'it finished loading more');
equal(rs.get('length'), 4);
ok(!rs.get('loadMoreUrl'));
ok(!rs.get('canLoadMore'));
});
});
});