-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathIterableEmbeddedMessageElementsButton.test.ts
More file actions
91 lines (72 loc) · 3.04 KB
/
Copy pathIterableEmbeddedMessageElementsButton.test.ts
File metadata and controls
91 lines (72 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { IterableEmbeddedMessageElementsButton } from '../embedded/classes/IterableEmbeddedMessageElementsButton';
import { IterableEmbeddedMessageElementsButtonAction } from '../embedded/classes/IterableEmbeddedMessageElementsButtonAction';
import { Iterable } from '../core/classes/Iterable';
describe('IterableEmbeddedMessageButton', () => {
it('should create an instance with all properties including button action', () => {
Iterable.logger.log(
'iterableEmbeddedMessageButton_fromDict_all_properties'
);
const dict = {
id: 'button-123',
title: 'Click Me!',
action: { type: 'openUrl', data: 'https://example.com' },
};
const button = IterableEmbeddedMessageElementsButton.fromDict(dict);
expect(button).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
expect(button.id).toBe('button-123');
expect(button.title).toBe('Click Me!');
expect(button.action).toBeInstanceOf(
IterableEmbeddedMessageElementsButtonAction
);
expect(button.action?.type).toBe('openUrl');
expect(button.action?.data).toBe('https://example.com');
});
it('should create an instance with only required properties', () => {
Iterable.logger.log('iterableEmbeddedMessageButton_fromDict_required_only');
const dict = { id: 'button-123' };
const button = IterableEmbeddedMessageElementsButton.fromDict(dict);
expect(button).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
expect(button.id).toBe('button-123');
expect(button.title).toBeUndefined();
expect(button.action).toBeUndefined();
});
it('should create an instance with title but no action', () => {
Iterable.logger.log('iterableEmbeddedMessageButton_fromDict_title_only');
const dict = {
id: 'button-123',
title: 'Click Me!',
};
const button = IterableEmbeddedMessageElementsButton.fromDict(dict);
expect(button).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
expect(button.id).toBe('button-123');
expect(button.title).toBe('Click Me!');
expect(button.action).toBeUndefined();
});
it('should throw an error if id is missing in fromDict', () => {
Iterable.logger.log('iterableEmbeddedMessageButton_fromDict_missing_id');
const dict = {
title: 'Click Me!',
action: { type: 'openUrl', data: 'https://example.com' },
};
expect(() => IterableEmbeddedMessageElementsButton.fromDict(dict)).toThrow(
'id is required'
);
});
it('should handle button action with only type', () => {
Iterable.logger.log(
'iterableEmbeddedMessageButton_fromDict_action_type_only'
);
const dict = {
id: 'button-123',
action: { type: 'close' },
};
const button = IterableEmbeddedMessageElementsButton.fromDict(dict);
expect(button).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
expect(button.id).toBe('button-123');
expect(button.action).toBeInstanceOf(
IterableEmbeddedMessageElementsButtonAction
);
expect(button.action?.type).toBe('close');
expect(button.action?.data).toBeUndefined();
});
});