Skip to content

Commit

Permalink
Merge c6887b4 into d1e4cb8
Browse files Browse the repository at this point in the history
  • Loading branch information
regaw-leinad committed Dec 17, 2018
2 parents d1e4cb8 + c6887b4 commit c866313
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 2 deletions.
33 changes: 33 additions & 0 deletions __tests__/_fixtures/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,39 @@ export const testShortcutNoActions: WFWorkflow = {
WFWorkflowActions: [],
};

export const testShortcutNoActionsNoWidget: WFWorkflow = {
WFWorkflowClientVersion: '724',
WFWorkflowClientRelease: '2.1',
WFWorkflowIcon: {
WFWorkflowIconStartColor: 4274264319,
WFWorkflowIconGlyphNumber: 59446,
},
WFWorkflowImportQuestions: [],
WFWorkflowTypes: [
'WatchKit',
],
WFWorkflowInputContentItemClasses: [
'WFAppStoreAppContentItem',
'WFArticleContentItem',
'WFContactContentItem',
'WFDateContentItem',
'WFEmailAddressContentItem',
'WFGenericFileContentItem',
'WFImageContentItem',
'WFiTunesProductContentItem',
'WFLocationContentItem',
'WFDCMapsLinkContentItem',
'WFAVAssetContentItem',
'WFPDFContentItem',
'WFPhoneNumberContentItem',
'WFRichTextContentItem',
'WFSafariWebPageContentItem',
'WFStringContentItem',
'WFURLContentItem',
],
WFWorkflowActions: [],
};

export const testShortcutWithActions: WFWorkflow = {
WFWorkflowClientVersion: '724',
WFWorkflowClientRelease: '2.1',
Expand Down
18 changes: 18 additions & 0 deletions __tests__/utils/buildShortcut.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('buildShortcut function', () => {
color: 4274264319,
glyph: 59446,
},
showInWidget: true,
});
const expected = encodeShortcut(template);

Expand All @@ -33,6 +34,7 @@ describe('buildShortcut function', () => {
color: 4274264319,
glyph: 59446,
},
showInWidget: true,
});
const expected = encodeShortcut(template);

Expand All @@ -46,6 +48,7 @@ describe('buildShortcut function', () => {
color: 1440408063,
glyph: 59784,
},
showInWidget: true,
};
const template = buildShortcutTemplate(testActions, options);
const expected = encodeShortcut(template);
Expand All @@ -60,6 +63,7 @@ describe('buildShortcut function', () => {
color: 1440408063,
glyph: 59446,
},
showInWidget: true,
});
const expected = encodeShortcut(template);

Expand All @@ -71,4 +75,18 @@ describe('buildShortcut function', () => {
expect(actual).toEqual(expected);
});

it('builds an encoded shortcut object that is not shown in shortcuts widget', () => {
const template = buildShortcutTemplate([], {
icon: {
color: 4274264319,
glyph: 59446,
},
showInWidget: false,
});
const expected = encodeShortcut(template);

const actual = buildShortcut([], { showInWidget: false });
expect(actual).toEqual(expected);
});

});
22 changes: 21 additions & 1 deletion __tests__/utils/buildShortcutTemplate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { buildShortcutTemplate } from '../../src/utils';

import BuildShortcutOptions from '../../src/interfaces/BuildShortcutOptions';

import {
testActions,
testShortcutNoActions,
testShortcutNoActionsNoWidget,
testShortcutWithActions,
testShortcutWithModifiedOptions,
} from '../_fixtures/actions';

const defaultOptions = {
const defaultOptions: BuildShortcutOptions = {
icon: {
color: 4274264319,
glyph: 59446,
},
showInWidget: true,
};

const noWidgetOptions: BuildShortcutOptions = {
icon: {
color: 4274264319,
glyph: 59446,
},
showInWidget: false,
};

describe('buildShortcutTemplate function', () => {
Expand Down Expand Up @@ -42,8 +54,16 @@ describe('buildShortcutTemplate function', () => {
color: 3980825855,
glyph: 59769,
},
showInWidget: true,
});
expect(actual).toMatchObject(expected);
});

it('builds a shortcut object that is not shown in shortcuts widget', () => {
const expected = testShortcutNoActionsNoWidget;

const actual = buildShortcutTemplate(undefined, noWidgetOptions);
expect(actual).toMatchObject(expected);
});

});
1 change: 1 addition & 0 deletions src/interfaces/BuildShortcutOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ interface BuildShortcutOptions {
color: number;
glyph: number;
};
showInWidget: boolean;
}

export default BuildShortcutOptions;
6 changes: 6 additions & 0 deletions src/utils/buildShortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export const buildShortcut = (
color?: number,
glyph?: number,
},
showInWidget?: boolean,
},
): string => {
const completeOptions = {
icon: {
color: 4274264319, // Yellow
glyph: 59446, // Keyboard
},
showInWidget: true,
};

if (options && options.icon) {
Expand All @@ -32,6 +34,10 @@ export const buildShortcut = (
};
}

if (options && options.showInWidget === false) {
completeOptions.showInWidget = false;
}

const template = buildShortcutTemplate(actions, completeOptions);
const shortcut = encodeShortcut(template);
return shortcut;
Expand Down
3 changes: 2 additions & 1 deletion src/utils/buildShortcutTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { flatten } from './flatten';
import BuildShortcutOptions from '../interfaces/BuildShortcutOptions';
import WFWorkflow from '../interfaces/WF/WFWorkflow';
import WFWorkflowActionsInterface from '../interfaces/WF/WFWorkflowAction';
import WFWorkflowType from '../interfaces/WF/WFWorkflowType';

/** @ignore */
export const buildShortcutTemplate = (
Expand All @@ -17,7 +18,7 @@ export const buildShortcutTemplate = (
},
WFWorkflowImportQuestions: [],
WFWorkflowTypes: [
'NCWidget',
...(options.showInWidget ? ['NCWidget' as WFWorkflowType] : []),
'WatchKit',
],
WFWorkflowInputContentItemClasses: [
Expand Down

0 comments on commit c866313

Please sign in to comment.