Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Add setWiFi & setCellularData actions #24

Merged
merged 1 commit into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions __tests__/actions/setCellularData.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { setCellularData } from '../../src/actions';

describe('setCellularData function', () => {

it('is a function', () => {
expect(typeof setCellularData).toBe('function');
});

it('builds a setCellularData action when no value is passed', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.cellulardata.set',
WFWorkflowActionParameters: {
OnValue: true,
},
};
const actual = setCellularData({});

expect(actual).toEqual(expected);
});

it('builds a setCellularData action with given value', () => {
const value = false;
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.cellulardata.set',
WFWorkflowActionParameters: {
OnValue: value,
},
};
const actual = setCellularData({ value });

expect(actual).toEqual(expected);
});

});
34 changes: 34 additions & 0 deletions __tests__/actions/setWiFi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { setWiFi } from '../../src/actions';

describe('setWiFi function', () => {

it('is a function', () => {
expect(typeof setWiFi).toBe('function');
});

it('builds a setWiFi action when no value is passed', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.wifi.set',
WFWorkflowActionParameters: {
OnValue: true,
},
};
const actual = setWiFi({});

expect(actual).toEqual(expected);
});

it('builds a setWiFi action with given value', () => {
const value = false;
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.wifi.set',
WFWorkflowActionParameters: {
OnValue: value,
},
};
const actual = setWiFi({ value });

expect(actual).toEqual(expected);
});

});
4 changes: 4 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import runShortcut from './runShortcut';
import setAirplaneMode from './setAirplaneMode';
import setBluetooth from './setBluetooth';
import setBrightness from './setBrightness';
import setCellularData from './setCellularData';
import setLowPowerMode from './setLowPowerMode';
import setName from './setName';
import setTorch from './setTorch';
import setVariable from './setVariable';
import setWiFi from './setWiFi';
import showResult from './showResult';
import text from './text';
import url from './url';
Expand Down Expand Up @@ -55,10 +57,12 @@ export {
setAirplaneMode,
setBluetooth,
setBrightness,
setCellularData,
setLowPowerMode,
setName,
setTorch,
setVariable,
setWiFi,
showResult,
text,
url,
Expand Down
30 changes: 30 additions & 0 deletions src/actions/setCellularData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction';

/**
* Set setCellularData Action. Sets the device's cellular data to on or off.
*
* ```js
* setCellularData({
* value: true,
* });
* ```
*/
const setCellularData = (
options: {
/** Enable or disable cellular data */
value?: boolean,
},
): WFWorkflowAction => {
const {
value = true,
} = options;

return {
WFWorkflowActionIdentifier: 'is.workflow.actions.cellulardata.set',
WFWorkflowActionParameters: {
OnValue: value,
},
};
};

export default setCellularData;
30 changes: 30 additions & 0 deletions src/actions/setWiFi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction';

/**
* Set setWiFi Action. Sets the device's WiFi to on or off.
*
* ```js
* setWiFi({
* value: true,
* });
* ```
*/
const setWiFi = (
options: {
/** Enable or disable WiFi */
value?: boolean,
},
): WFWorkflowAction => {
const {
value = true,
} = options;

return {
WFWorkflowActionIdentifier: 'is.workflow.actions.wifi.set',
WFWorkflowActionParameters: {
OnValue: value,
},
};
};

export default setWiFi;
2 changes: 2 additions & 0 deletions src/interfaces/WF/WFWorkflowActionIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ type WFWorkflowActionIdentifier = (
| 'is.workflow.actions.airplanemode.set'
| 'is.workflow.actions.ask'
| 'is.workflow.actions.bluetooth.set'
| 'is.workflow.actions.cellulardata.set'
| 'is.workflow.actions.choosefrommenu'
| 'is.workflow.actions.comment'
| 'is.workflow.actions.conditional'
Expand Down Expand Up @@ -32,6 +33,7 @@ type WFWorkflowActionIdentifier = (
| 'is.workflow.actions.vibrate'
| 'is.workflow.actions.viewresult'
| 'is.workflow.actions.waittoreturn'
| 'is.workflow.actions.wifi.set'
);

export default WFWorkflowActionIdentifier;