-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from ikaikastine/showNotification
Show Notification Action
- Loading branch information
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { showNotification } from '../../src/actions'; | ||
|
||
describe('showNotification function', () => { | ||
it('is a function', () => { | ||
expect(typeof showNotification).toBe('function'); | ||
}); | ||
|
||
it('builds a showNotification action when no options are passed', () => { | ||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.notification', | ||
WFWorkflowActionParameters: { | ||
WFNotificationActionTitle: '', | ||
WFNotificationActionBody: 'Hello World', | ||
WFNotificationActionSound: true, | ||
}, | ||
}; | ||
const actual = showNotification({}); | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a showNotification action when a body is passed', () => { | ||
const bodyString = 'This is a test notification.'; | ||
|
||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.notification', | ||
WFWorkflowActionParameters: { | ||
WFNotificationActionTitle: '', | ||
WFNotificationActionBody: bodyString, | ||
WFNotificationActionSound: true, | ||
}, | ||
}; | ||
|
||
const actual = showNotification({ | ||
body: bodyString, | ||
}); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a showNotification action when sound is set to false', () => { | ||
|
||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.notification', | ||
WFWorkflowActionParameters: { | ||
WFNotificationActionTitle: '', | ||
WFNotificationActionBody: 'Hello World', | ||
WFNotificationActionSound: false, | ||
}, | ||
}; | ||
|
||
const actual = showNotification({ | ||
sound: false, | ||
}); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction'; | ||
|
||
/** | ||
* Show Notification Action. Displays a local notification. | ||
* | ||
* ```js | ||
* showNotification({ | ||
* title: 'Hello, World!', | ||
* body: 'This is a test notification', | ||
* sound: true, | ||
* }); | ||
* ``` | ||
*/ | ||
|
||
const showNotification = ( | ||
options: { | ||
/** Title for the notification */ | ||
title ?: string, | ||
/** Body for the notification */ | ||
body ?: string, | ||
/** Enable or disable sound for the notification */ | ||
sound ?: boolean, | ||
}, | ||
): WFWorkflowAction => { | ||
const { | ||
title = '', | ||
body = 'Hello World', | ||
sound = true, | ||
} = options; | ||
|
||
return { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.notification', | ||
WFWorkflowActionParameters: { | ||
WFNotificationActionTitle: title, | ||
WFNotificationActionBody: body, | ||
WFNotificationActionSound: sound, | ||
}, | ||
}; | ||
}; | ||
|
||
export default showNotification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters