From 730ba06c4753a21c784d6ed15e461e7fe27bf7d4 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Sun, 10 May 2015 12:21:18 -0700 Subject: [PATCH] fix(unread-notifications): Fix failing tests, add one for "Unknown" sender --- .../unread-notifications/lib/main.coffee | 2 +- .../unread-notifications/spec/main-spec.coffee | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/internal_packages/unread-notifications/lib/main.coffee b/internal_packages/unread-notifications/lib/main.coffee index 9b4853c85..aa095c7fe 100644 --- a/internal_packages/unread-notifications/lib/main.coffee +++ b/internal_packages/unread-notifications/lib/main.coffee @@ -46,7 +46,7 @@ module.exports = body = msg.subject if not body or body.length is 0 body = msg.snippet - from = msg.from[0]?.displayName ? "Unknown" + from = msg.from[0]?.displayName() ? "Unknown" notif = new Notification(from, { body: body tag: 'unread-update' diff --git a/internal_packages/unread-notifications/spec/main-spec.coffee b/internal_packages/unread-notifications/spec/main-spec.coffee index 6f912de7d..07dcd562b 100644 --- a/internal_packages/unread-notifications/spec/main-spec.coffee +++ b/internal_packages/unread-notifications/spec/main-spec.coffee @@ -21,6 +21,12 @@ describe "UnreadNotifications", -> from: [new Contact(name: 'Ben', email: 'ben@example.com')] subject: "Hello World" threadId: "A" + @msgNoSender = new Message + unread: true + date: new Date() + from: [] + subject: "Hello World" + threadId: "A" @msg2 = new Message unread: true date: new Date() @@ -78,6 +84,13 @@ describe "UnreadNotifications", -> expect(window.Notification).toHaveBeenCalled() expect(window.Notification.mostRecentCall.args).toEqual([ '2 Unread Messages', { tag : 'unread-update' } ]) + it "should create a Notification correctly, even if new mail has no sender", -> + waitsForPromise => + Main._onNewMailReceived({message: [@msgNoSender]}) + .then -> + expect(window.Notification).toHaveBeenCalled() + expect(window.Notification.mostRecentCall.args).toEqual([ 'Unknown', { body : 'Hello World', tag : 'unread-update' } ]) + it "should not create a Notification if there are no new messages", -> waitsForPromise -> Main._onNewMailReceived({message: []})