Skip to content

Commit e884964

Browse files
Refactors ContextTypes to union type instead of enum (#1138)
1 parent 43ce7b2 commit e884964

2 files changed

Lines changed: 29 additions & 28 deletions

File tree

src/context/ContextType.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright FINOS FDC3 contributors - see NOTICE file
44
*/
5-
export enum ContextTypes {
6-
Chart = 'fdc3.chart',
7-
ChatInitSettings = 'fdc3.chat.initSettings',
8-
ChatRoom = 'fdc3.chat.room',
9-
Contact = 'fdc3.contact',
10-
ContactList = 'fdc3.contactList',
11-
Country = 'fdc3.country',
12-
Currency = 'fdc3.currency',
13-
Email = 'fdc3.email',
14-
Instrument = 'fdc3.instrument',
15-
InstrumentList = 'fdc3.instrumentList',
16-
Interaction = 'fdc3.interaction',
17-
Nothing = 'fdc3.nothing',
18-
Organization = 'fdc3.organization',
19-
Portfolio = 'fdc3.portfolio',
20-
Position = 'fdc3.position',
21-
ChatSearchCriteria = 'fdc3.chat.searchCriteria',
22-
TimeRange = 'fdc3.timerange',
23-
TransactionResult = 'fdc3.transactionResult',
24-
Valuation = 'fdc3.valuation',
25-
}
5+
export type StandardContextType =
6+
| 'fdc3.action'
7+
| 'fdc3.chart'
8+
| 'fdc3.chat.initSettings'
9+
| 'fdc3.chat.message'
10+
| 'fdc3.chat.room'
11+
| 'fdc3.chat.searchCriteria'
12+
| 'fdc3.contact'
13+
| 'fdc3.contactList'
14+
| 'fdc3.country'
15+
| 'fdc3.currency'
16+
| 'fdc3.email'
17+
| 'fdc3.instrument'
18+
| 'fdc3.instrumentList'
19+
| 'fdc3.interaction'
20+
| 'fdc3.message'
21+
| 'fdc3.organization'
22+
| 'fdc3.portfolio'
23+
| 'fdc3.position'
24+
| 'fdc3.nothing'
25+
| 'fdc3.timerange'
26+
| 'fdc3.transactionResult'
27+
| 'fdc3.valuation';
2628

27-
export type ContextType = ContextTypes | string;
29+
export type ContextType = StandardContextType | string;

test/Methods.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
broadcast,
66
compareVersionNumbers,
77
ContextHandler,
8-
ContextTypes,
98
DesktopAgent,
109
fdc3Ready,
1110
findIntent,
@@ -33,7 +32,7 @@ const TimeoutError = new Error('Timed out waiting for `fdc3Ready` event.');
3332
const UnexpectedError = new Error('`fdc3Ready` event fired, but `window.fdc3` not set to DesktopAgent.');
3433

3534
const ContactContext = {
36-
type: ContextTypes.Contact,
35+
type: 'fdc3.contact',
3736
id: { email: 'test@example.com' },
3837
};
3938

@@ -163,10 +162,10 @@ describe('test ES6 module', () => {
163162
test('findIntent should delegate to window.fdc3.findIntent (with additional output type argument)', async () => {
164163
const intent = 'ViewChart';
165164

166-
await findIntent(intent, ContactContext, ContextTypes.Contact);
165+
await findIntent(intent, ContactContext, 'fdc3.contact');
167166

168167
expect(window.fdc3.findIntent).toHaveBeenCalledTimes(1);
169-
expect(window.fdc3.findIntent).toHaveBeenLastCalledWith(intent, ContactContext, ContextTypes.Contact);
168+
expect(window.fdc3.findIntent).toHaveBeenLastCalledWith(intent, ContactContext, 'fdc3.contact');
170169
});
171170

172171
test('findIntentsByContext should delegate to window.fdc3.findIntentsByContext', async () => {
@@ -177,10 +176,10 @@ describe('test ES6 module', () => {
177176
});
178177

179178
test('findIntentsByContext should delegate to window.fdc3.findIntentsByContext (with additional output type argument)', async () => {
180-
await findIntentsByContext(ContactContext, ContextTypes.Contact);
179+
await findIntentsByContext(ContactContext, 'fdc3.contact');
181180

182181
expect(window.fdc3.findIntentsByContext).toHaveBeenCalledTimes(1);
183-
expect(window.fdc3.findIntentsByContext).toHaveBeenLastCalledWith(ContactContext, ContextTypes.Contact);
182+
expect(window.fdc3.findIntentsByContext).toHaveBeenLastCalledWith(ContactContext, 'fdc3.contact');
184183
});
185184

186185
test('broadcast should delegate to window.fdc3.broadcast', async () => {

0 commit comments

Comments
 (0)