Skip to content

Commit

Permalink
Merge pull request #30 from ikaikastine/showNotification
Browse files Browse the repository at this point in the history
Show Notification Action
  • Loading branch information
joshfarrant committed Dec 3, 2018
2 parents f1ee838 + c4af54d commit 53d2d64
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
58 changes: 58 additions & 0 deletions __tests__/actions/showNotification.spec.ts
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);
});

});
2 changes: 2 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import setName from './setName';
import setTorch from './setTorch';
import setVariable from './setVariable';
import setWiFi from './setWiFi';
import showNotification from './showNotification';
import showResult from './showResult';
import text from './text';
import url from './url';
Expand Down Expand Up @@ -76,6 +77,7 @@ export {
setCellularData,
setLowPowerMode,
setName,
showNotification,
setTorch,
setVariable,
setWiFi,
Expand Down
41 changes: 41 additions & 0 deletions src/actions/showNotification.ts
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;
1 change: 1 addition & 0 deletions src/interfaces/WF/WFWorkflowActionIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type WFWorkflowActionIdentifier = (
| 'is.workflow.actions.lowpowermode.set'
| 'is.workflow.actions.math'
| 'is.workflow.actions.nothing'
| 'is.workflow.actions.notification'
| 'is.workflow.actions.number'
| 'is.workflow.actions.previewdocument'
| 'is.workflow.actions.print'
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/WF/WFWorkflowActionParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ interface WFWorkflowActionParameters {
WFMenuPrompt?: string;
WFName?: string;
WFNetworkDetailsNetwork?: WFNetworkDetailsNetwork;
WFNotificationActionTitle?: string;
WFNotificationActionBody?: string;
WFNotificationActionSound?: boolean;
WFNumberActionNumber?: number;
WFNumberValue?: number;
WFShowWorkflow?: boolean;
Expand Down

0 comments on commit 53d2d64

Please sign in to comment.