Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
Bug 1139899 - Mark as read notifications for the visible question
Browse files Browse the repository at this point in the history
  • Loading branch information
rik committed Apr 20, 2015
1 parent a812285 commit e34cd7b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/js/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ function push_notification() {
var tag;
var actor;

var unknown_type = false;

switch(notification.verb) {
case 'answered':
var QuestionC = window.Navigation.current_view.QuestionController;
Expand All @@ -75,12 +77,17 @@ function push_notification() {
break;

default:
unknown_type = true;
console.error('unknown notification type: ', notification.verb);
break;
}

if (!title) {
return notification.id;
if (unknown_type) {
return notification.id;
} else {
return SumoDB.mark_notification_as_read(notification.id);
}
}

return SumoDB.get_question(notification.target.id)
Expand Down
8 changes: 8 additions & 0 deletions app/test/unit/notifications_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ suite('notifications', function() {
function reset_test() {
navigator.mozSetMessageHandler.reset();
window.Notification.reset();
SumoDB.mark_notification_as_read.reset();
Notif.init();
var push_handler_spy = navigator.mozSetMessageHandler.withArgs('push');
var push_handler = push_handler_spy.firstCall.args[1];
Expand All @@ -152,6 +153,13 @@ suite('notifications', function() {
}).then(done, done);
});

test('marks the notification as read', function(done) {
reset_test().then(() => {
sinon.assert.calledWith(SumoDB.mark_notification_as_read,
ANSWERED_NOTIF.id);
}).then(done, done);
});

test('displays the notification if app in background', function(done) {
Object.defineProperty(document, 'hidden', {
configurable: true,
Expand Down

0 comments on commit e34cd7b

Please sign in to comment.