This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
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 #55 from jakebathman/add-create-alarm-function
Add createAlarm action
- Loading branch information
Showing
6 changed files
with
120 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 { createAlarm } from '../../src/actions'; | ||
|
||
describe('createAlarm function', () => { | ||
|
||
it('is a function', () => { | ||
expect(typeof createAlarm).toBe('function'); | ||
}); | ||
|
||
it('builds a createAlarm action', () => { | ||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.alarm.create', | ||
WFWorkflowActionParameters: { | ||
WFLabel: '', | ||
WFTime: '', | ||
WFFrequency: [], | ||
}, | ||
}; | ||
const actual = createAlarm({}); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a createAlarm action with nonrepeating alarm inputs', () => { | ||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.alarm.create', | ||
WFWorkflowActionParameters: { | ||
WFLabel: 'Label for 7:42 PM alarm', | ||
WFTime: '7:42 PM', | ||
WFFrequency: [], | ||
}, | ||
}; | ||
const actual = createAlarm({ | ||
label: 'Label for 7:42 PM alarm', | ||
time: '7:42 PM', | ||
}); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a createAlarm action with repeating days', () => { | ||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.alarm.create', | ||
WFWorkflowActionParameters: { | ||
WFLabel: 'Label for 7:42 PM alarm', | ||
WFTime: '7:42 PM', | ||
WFFrequency: ['Sunday', 'Tuesday', 'Friday'], | ||
}, | ||
}; | ||
const actual = createAlarm({ | ||
label: 'Label for 7:42 PM alarm', | ||
time: '7:42 PM', | ||
repeat: ['Sunday', 'Tuesday', 'Friday'], | ||
}); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import WFFrequency from '../interfaces/WF/WFFrequency'; | ||
import WFSerialization from '../interfaces/WF/WFSerialization'; | ||
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction'; | ||
|
||
/** | ||
* Create alarm action. Creates an alarm in the Clock app. | ||
* | ||
* ```js | ||
* createAlarm({ | ||
* label: 'Alarm', | ||
* time: '8 AM', | ||
* repeat: ['Sunday', 'Saturday'], | ||
* }); | ||
* ``` | ||
*/ | ||
const createAlarm = ( | ||
options: { | ||
/** The alarm label */ | ||
label?: WFSerialization | string, | ||
|
||
/** The alarm time */ | ||
time?: WFSerialization | string, | ||
|
||
/** Whether the alarm should repeat on certain days */ | ||
repeat?: WFFrequency[], | ||
}, | ||
): WFWorkflowAction => { | ||
const { | ||
label = '', | ||
time = '', | ||
repeat = [], | ||
} = options; | ||
|
||
return { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.alarm.create', | ||
WFWorkflowActionParameters: { | ||
WFLabel: label, | ||
WFTime: time, | ||
WFFrequency: repeat, | ||
}, | ||
}; | ||
}; | ||
|
||
export default createAlarm; |
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,11 @@ | ||
type WFFrequency = ( | ||
'Sunday' | ||
| 'Monday' | ||
| 'Tuesday' | ||
| 'Wednesday' | ||
| 'Thursday' | ||
| 'Friday' | ||
| 'Saturday' | ||
); | ||
|
||
export default WFFrequency; |
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