pulsar/spec/notification-spec.coffee

61 lines
2.4 KiB
CoffeeScript
Raw Normal View History

2014-11-21 05:53:06 +03:00
Notification = require '../src/notification'
2014-11-25 01:43:12 +03:00
describe "Notification", ->
2014-11-21 05:53:06 +03:00
[notification] = []
it "throws an error when created with a non-string message", ->
expect(-> new Notification('error', null)).toThrow()
expect(-> new Notification('error', 3)).toThrow()
expect(-> new Notification('error', {})).toThrow()
expect(-> new Notification('error', false)).toThrow()
2015-07-07 22:20:01 +03:00
expect(-> new Notification('error', [])).toThrow()
it "throws an error when created with non-object options", ->
expect(-> new Notification('error', 'message', 'foo')).toThrow()
expect(-> new Notification('error', 'message', 3)).toThrow()
expect(-> new Notification('error', 'message', false)).toThrow()
2015-07-07 22:20:01 +03:00
expect(-> new Notification('error', 'message', [])).toThrow()
2014-11-25 01:43:12 +03:00
describe "::getTimestamp()", ->
it "returns a Date object", ->
notification = new Notification('error', 'message!')
expect(notification.getTimestamp() instanceof Date).toBe true
2014-11-21 05:53:06 +03:00
describe "::getIcon()", ->
it "returns a default when no icon specified", ->
notification = new Notification('error', 'message!')
2014-11-21 05:54:51 +03:00
expect(notification.getIcon()).toBe 'flame'
2014-11-21 05:53:06 +03:00
it "returns the icon specified", ->
notification = new Notification('error', 'message!', icon: 'my-icon')
expect(notification.getIcon()).toBe 'my-icon'
2014-12-05 23:01:59 +03:00
describe "dismissing notifications", ->
describe "when the notfication is dismissable", ->
it "calls a callback when the notification is dismissed", ->
dismissedSpy = jasmine.createSpy()
notification = new Notification('error', 'message', dismissable: true)
notification.onDidDismiss dismissedSpy
expect(notification.isDismissable()).toBe true
expect(notification.isDismissed()).toBe false
notification.dismiss()
expect(dismissedSpy).toHaveBeenCalled()
expect(notification.isDismissed()).toBe true
describe "when the notfication is not dismissable", ->
it "does nothing when ::dismiss() is called", ->
dismissedSpy = jasmine.createSpy()
notification = new Notification('error', 'message')
notification.onDidDismiss dismissedSpy
expect(notification.isDismissable()).toBe false
expect(notification.isDismissed()).toBe true
notification.dismiss()
expect(dismissedSpy).not.toHaveBeenCalled()
expect(notification.isDismissed()).toBe true