Skip to content

Commit cad9c3e

Browse files
author
Evan Greer
committed
feat: merges action into button
1 parent 8df97eb commit cad9c3e

6 files changed

Lines changed: 30 additions & 146 deletions

src/__tests__/IterableEmbeddedMessageElementsButton.test.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { IterableEmbeddedMessageElementsButton } from '../embedded/classes/IterableEmbeddedMessageElementsButton';
2-
import { IterableEmbeddedMessageElementsButtonAction } from '../embedded/classes/IterableEmbeddedMessageElementsButtonAction';
32
import { Iterable } from '../core/classes/Iterable';
43

54
describe('IterableEmbeddedMessageButton', () => {
@@ -14,14 +13,12 @@ describe('IterableEmbeddedMessageButton', () => {
1413
action: { type: 'openUrl', data: 'https://example.com' },
1514
};
1615

17-
const button = IterableEmbeddedMessageElementsButton.fromDict(dict);
16+
const button = new IterableEmbeddedMessageElementsButton(dict);
1817

1918
expect(button).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
2019
expect(button.id).toBe('button-123');
2120
expect(button.title).toBe('Click Me!');
22-
expect(button.action).toBeInstanceOf(
23-
IterableEmbeddedMessageElementsButtonAction
24-
);
21+
expect(button.action).toBeInstanceOf(Object);
2522
expect(button.action?.type).toBe('openUrl');
2623
expect(button.action?.data).toBe('https://example.com');
2724
});
@@ -31,7 +28,7 @@ describe('IterableEmbeddedMessageButton', () => {
3128

3229
const dict = { id: 'button-123' };
3330

34-
const button = IterableEmbeddedMessageElementsButton.fromDict(dict);
31+
const button = new IterableEmbeddedMessageElementsButton(dict);
3532

3633
expect(button).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
3734
expect(button.id).toBe('button-123');
@@ -47,23 +44,23 @@ describe('IterableEmbeddedMessageButton', () => {
4744
title: 'Click Me!',
4845
};
4946

50-
const button = IterableEmbeddedMessageElementsButton.fromDict(dict);
47+
const button = new IterableEmbeddedMessageElementsButton(dict);
5148

5249
expect(button).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
5350
expect(button.id).toBe('button-123');
5451
expect(button.title).toBe('Click Me!');
5552
expect(button.action).toBeUndefined();
5653
});
5754

58-
it('should throw an error if id is missing in fromDict', () => {
55+
it('should throw an error if id is missing', () => {
5956
Iterable.logger.log('iterableEmbeddedMessageButton_fromDict_missing_id');
6057

6158
const dict = {
6259
title: 'Click Me!',
6360
action: { type: 'openUrl', data: 'https://example.com' },
6461
};
65-
66-
expect(() => IterableEmbeddedMessageElementsButton.fromDict(dict)).toThrow(
62+
// @ts-expect-error - id is purposely missing
63+
expect(() => new IterableEmbeddedMessageElementsButton(dict)).toThrow(
6764
'id is required'
6865
);
6966
});
@@ -78,13 +75,11 @@ describe('IterableEmbeddedMessageButton', () => {
7875
action: { type: 'close' },
7976
};
8077

81-
const button = IterableEmbeddedMessageElementsButton.fromDict(dict);
78+
const button = new IterableEmbeddedMessageElementsButton(dict);
8279

8380
expect(button).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
8481
expect(button.id).toBe('button-123');
85-
expect(button.action).toBeInstanceOf(
86-
IterableEmbeddedMessageElementsButtonAction
87-
);
82+
expect(button.action).toBeInstanceOf(Object);
8883
expect(button.action?.type).toBe('close');
8984
expect(button.action?.data).toBeUndefined();
9085
});

src/__tests__/IterableEmbeddedMessageElementsButtonAction.test.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/embedded/classes/IterableEmbeddedMessageElements.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export class IterableEmbeddedMessageElements {
6767
? IterableEmbeddedMessageDefaultAction.fromDict(dict.defaultAction)
6868
: undefined;
6969

70-
const buttons = dict.buttons?.map((button) =>
71-
IterableEmbeddedMessageElementsButton.fromDict(button)
70+
const buttons = dict.buttons?.map(
71+
(button) => new IterableEmbeddedMessageElementsButton(button)
7272
);
7373

7474
const text = dict.text?.map((text) =>
Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { IterableEmbeddedMessageElementsButtonAction } from './IterableEmbeddedMessageElementsButtonAction';
2-
31
/**
42
* IterableEmbeddedMessageElementsButton represents a button in an embedded message.
53
*/
@@ -9,45 +7,30 @@ export class IterableEmbeddedMessageElementsButton {
97
/** The title for the embedded message button */
108
readonly title?: string;
119
/** The action for the embedded message button */
12-
readonly action?: IterableEmbeddedMessageElementsButtonAction;
10+
readonly action?: {
11+
type: string;
12+
data?: string;
13+
};
1314

1415
/**
1516
* Creates an instance of IterableEmbeddedMessageButton.
1617
*
17-
* @param id - The ID for the embedded message button.
18-
* @param title - The title for the embedded message button.
19-
* @param action - The action for the embedded message button.
20-
*/
21-
constructor(
22-
id: string,
23-
title?: string,
24-
action?: IterableEmbeddedMessageElementsButtonAction
25-
) {
26-
this.id = id;
27-
this.title = title;
28-
this.action = action;
29-
}
30-
31-
/**
32-
* Creates an instance of `IterableEmbeddedMessageButton` from a dictionary object.
33-
*
3418
* @param dict - The dictionary object containing the properties to initialize the `IterableEmbeddedMessageButton` instance.
35-
* @returns A new instance of `IterableEmbeddedMessageButton` initialized with the provided dictionary properties.
3619
*/
37-
static fromDict(
38-
dict: Partial<EmbeddedMessageElementsButtonDict>
39-
): IterableEmbeddedMessageElementsButton {
20+
constructor(dict: EmbeddedMessageElementsButtonDict) {
4021
if (!dict.id) {
4122
throw new Error('id is required');
4223
}
43-
const action = dict.action
44-
? IterableEmbeddedMessageElementsButtonAction.fromDict(dict.action)
45-
: undefined;
46-
return new IterableEmbeddedMessageElementsButton(
47-
dict.id,
48-
dict.title,
49-
action
50-
);
24+
25+
this.id = dict.id;
26+
this.title = dict.title;
27+
28+
if (dict.action) {
29+
this.action = {
30+
type: dict.action.type,
31+
data: dict.action.data,
32+
};
33+
}
5134
}
5235
}
5336

@@ -60,5 +43,8 @@ export interface EmbeddedMessageElementsButtonDict {
6043
/** The title for the embedded message button */
6144
title?: string;
6245
/** The action for the embedded message button */
63-
action?: IterableEmbeddedMessageElementsButtonAction;
46+
action?: {
47+
type: string;
48+
data?: string;
49+
};
6450
}

src/embedded/classes/IterableEmbeddedMessageElementsButtonAction.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/embedded/classes/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from './IterableEmbeddedManager';
22
export * from './IterableEmbeddedPlacement';
33
export * from './IterableEmbeddedMessageElementsButton';
4-
export * from './IterableEmbeddedMessageElementsButtonAction';
54
export * from './IterableEmbeddedMessageMetadata';

0 commit comments

Comments
 (0)