@capillarytech/creatives-library 8.0.291 → 8.0.292

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/package.json +1 -1
  2. package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +33 -0
  3. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +422 -0
  4. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.scss +35 -0
  5. package/v2Components/CommonTestAndPreview/DeliverySettings/TECH_DETAILING_DELIVERY_SETTINGS.md +725 -0
  6. package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +92 -0
  7. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +251 -0
  8. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +111 -0
  9. package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +91 -0
  10. package/v2Components/CommonTestAndPreview/SendTestMessage.js +51 -1
  11. package/v2Components/CommonTestAndPreview/actions.js +20 -0
  12. package/v2Components/CommonTestAndPreview/constants.js +10 -0
  13. package/v2Components/CommonTestAndPreview/index.js +148 -15
  14. package/v2Components/CommonTestAndPreview/reducer.js +47 -0
  15. package/v2Components/CommonTestAndPreview/sagas.js +60 -0
  16. package/v2Components/CommonTestAndPreview/selectors.js +51 -0
  17. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +889 -0
  18. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +222 -0
  19. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +235 -0
  20. package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +135 -0
  21. package/v2Components/CommonTestAndPreview/tests/actions.test.js +50 -0
  22. package/v2Components/CommonTestAndPreview/tests/constants.test.js +18 -0
  23. package/v2Components/CommonTestAndPreview/tests/index.test.js +342 -1
  24. package/v2Components/CommonTestAndPreview/tests/reducer.test.js +118 -0
  25. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +145 -0
  26. package/v2Components/CommonTestAndPreview/tests/selectors.test.js +146 -0
  27. package/v2Components/TestAndPreviewSlidebox/index.js +14 -0
  28. package/v2Containers/CreativesContainer/index.js +0 -8
  29. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +697 -12
  30. package/v2Containers/SmsTrai/Edit/index.js +5 -1
  31. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +201 -0
  32. package/v2Containers/Whatsapp/index.js +1 -1
  33. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +26242 -4225
@@ -0,0 +1,222 @@
1
+ /**
2
+ * Tests for DeliverySettings component (sender ID / delivery settings summary + slidebox)
3
+ * @jest-environment jsdom
4
+ */
5
+
6
+ import React from 'react';
7
+ import { render, screen, fireEvent } from '@testing-library/react';
8
+ import { IntlProvider } from 'react-intl';
9
+ import DeliverySettings from '../../DeliverySettings';
10
+ import { CHANNELS } from '../../constants';
11
+
12
+ jest.mock('../../DeliverySettings/DeliverySettings.scss', () => ({}));
13
+
14
+ jest.mock('@capillarytech/cap-ui-library', () => ({
15
+ CapRow: ({ children, className, ...rest }) => <div className={className} data-testid="cap-row" {...rest}>{children}</div>,
16
+ CapHeading: ({ children }) => <div data-testid="cap-heading">{children}</div>,
17
+ CapIcon: ({ onClick, className, 'data-testid': testId }) => <button type="button" onClick={onClick} className={className} data-testid={testId || 'cap-icon'} aria-label="edit" />,
18
+ CapLabel: ({ children, type }) => <span data-type={type}>{children}</span>,
19
+ CapSlideBox: ({ show, content, handleClose }) => (show ? (
20
+ <div data-testid="cap-slidebox">
21
+ <button type="button" onClick={handleClose} data-testid="slidebox-close">Close</button>
22
+ {content}
23
+ </div>
24
+ ) : null),
25
+ }));
26
+
27
+ const mockModifyDeliverySettings = jest.fn();
28
+ jest.mock('../../DeliverySettings/ModifyDeliverySettings', () => function MockModifyDeliverySettings(props) {
29
+ mockModifyDeliverySettings(props);
30
+ return (
31
+ <div data-testid="modify-delivery-settings">
32
+ <button type="button" onClick={() => props.onSaveDeliverySettings({ domainId: 1 })} data-testid="modify-done">Done</button>
33
+ <button type="button" onClick={props.onClose} data-testid="modify-close">Cancel</button>
34
+ </div>
35
+ );
36
+ });
37
+
38
+ const defaultFormatMessage = (msg) => msg?.defaultMessage || msg?.id || '';
39
+
40
+ describe('DeliverySettings', () => {
41
+ const defaultProps = {
42
+ channel: CHANNELS.SMS,
43
+ deliverySettings: {},
44
+ senderDetailsOptions: [],
45
+ wecrmAccounts: [],
46
+ onSaveDeliverySettings: jest.fn(),
47
+ isLoadingSenderDetails: false,
48
+ formatMessage: defaultFormatMessage,
49
+ smsTraiDltEnabled: false,
50
+ registeredSenderIds: [],
51
+ whatsappAccountFromForm: undefined,
52
+ };
53
+
54
+ beforeEach(() => {
55
+ jest.clearAllMocks();
56
+ });
57
+
58
+ describe('channel visibility', () => {
59
+ it('should return null when channel is not in CHANNELS_WITH_DELIVERY_SETTINGS', () => {
60
+ const { container } = render(
61
+ <DeliverySettings {...defaultProps} channel="INAPP" />
62
+ );
63
+ expect(container.firstChild).toBeNull();
64
+ });
65
+
66
+ it('should render when channel is SMS', () => {
67
+ render(<DeliverySettings {...defaultProps} channel={CHANNELS.SMS} />);
68
+ expect(screen.getByTestId('cap-heading')).toBeTruthy();
69
+ });
70
+
71
+ it('should render when channel is EMAIL', () => {
72
+ render(<DeliverySettings {...defaultProps} channel={CHANNELS.EMAIL} />);
73
+ expect(screen.getByTestId('cap-heading')).toBeTruthy();
74
+ });
75
+
76
+ it('should render when channel is WHATSAPP', () => {
77
+ render(<DeliverySettings {...defaultProps} channel={CHANNELS.WHATSAPP} />);
78
+ expect(screen.getByTestId('cap-heading')).toBeTruthy();
79
+ });
80
+ });
81
+
82
+ describe('summary display', () => {
83
+ it('should show not configured when no delivery values for SMS', () => {
84
+ render(<DeliverySettings {...defaultProps} channel={CHANNELS.SMS} />);
85
+ expect(screen.getByText('Not configured')).toBeTruthy();
86
+ });
87
+
88
+ it('should show summary values for SMS when deliverySettings and senderDetailsOptions match', () => {
89
+ const senderDetailsOptions = [{ domainId: 1, domainName: 'SMS Domain' }];
90
+ const deliverySettings = { domainId: 1, gsmSenderId: 'SENDER1' };
91
+ render(
92
+ <DeliverySettings
93
+ {...defaultProps}
94
+ channel={CHANNELS.SMS}
95
+ deliverySettings={deliverySettings}
96
+ senderDetailsOptions={senderDetailsOptions}
97
+ />
98
+ );
99
+ expect(screen.getAllByText(/SMS Domain/).length).toBeGreaterThan(0);
100
+ expect(screen.getAllByText(/SENDER1/).length).toBeGreaterThan(0);
101
+ });
102
+
103
+ it('should show not configured for EMAIL when empty', () => {
104
+ render(<DeliverySettings {...defaultProps} channel={CHANNELS.EMAIL} />);
105
+ expect(screen.getByText('Not configured')).toBeTruthy();
106
+ });
107
+
108
+ it('should show summary for EMAIL when has domain and sender', () => {
109
+ const senderDetailsOptions = [{ domainId: 2, domainName: 'Email Domain' }];
110
+ const deliverySettings = {
111
+ domainId: 2,
112
+ senderEmail: 'noreply@test.com',
113
+ senderLabel: 'Test',
114
+ senderReplyTo: 'reply@test.com',
115
+ };
116
+ render(
117
+ <DeliverySettings
118
+ {...defaultProps}
119
+ channel={CHANNELS.EMAIL}
120
+ deliverySettings={deliverySettings}
121
+ senderDetailsOptions={senderDetailsOptions}
122
+ />
123
+ );
124
+ expect(screen.getAllByText(/Email Domain/).length).toBeGreaterThan(0);
125
+ expect(screen.getAllByText(/noreply@test\.com/).length).toBeGreaterThan(0);
126
+ });
127
+
128
+ it('should show summary for WHATSAPP when has account and sender', () => {
129
+ const wecrmAccounts = [{ name: 'WABA One', sourceAccountIdentifier: 'waba-1' }];
130
+ const deliverySettings = {
131
+ sourceAccountIdentifier: 'waba-1',
132
+ senderMobNum: '+1234567890',
133
+ };
134
+ render(
135
+ <DeliverySettings
136
+ {...defaultProps}
137
+ channel={CHANNELS.WHATSAPP}
138
+ deliverySettings={deliverySettings}
139
+ wecrmAccounts={wecrmAccounts}
140
+ />
141
+ );
142
+ expect(screen.getAllByText(/WABA One/).length).toBeGreaterThan(0);
143
+ expect(screen.getAllByText(/\+1234567890/).length).toBeGreaterThan(0);
144
+ });
145
+ });
146
+
147
+ describe('edit and slidebox', () => {
148
+ it('should open slidebox when edit icon is clicked', () => {
149
+ render(<DeliverySettings {...defaultProps} channel={CHANNELS.SMS} />);
150
+ expect(screen.queryByTestId('cap-slidebox')).toBeNull();
151
+ fireEvent.click(screen.getByTestId('delivery-settings-edit'));
152
+ expect(screen.getByTestId('cap-slidebox')).toBeTruthy();
153
+ expect(screen.getByTestId('modify-delivery-settings')).toBeTruthy();
154
+ });
155
+
156
+ it('should pass correct props to ModifyDeliverySettings', () => {
157
+ render(<DeliverySettings {...defaultProps} channel={CHANNELS.SMS} />);
158
+ fireEvent.click(screen.getByTestId('delivery-settings-edit'));
159
+ expect(mockModifyDeliverySettings).toHaveBeenCalledWith(
160
+ expect.objectContaining({
161
+ channel: CHANNELS.SMS,
162
+ deliverySettings: {},
163
+ senderDetailsOptions: [],
164
+ wecrmAccounts: [],
165
+ isLoading: false,
166
+ smsTraiDltEnabled: false,
167
+ registeredSenderIds: [],
168
+ whatsappAccountFromForm: undefined,
169
+ })
170
+ );
171
+ });
172
+
173
+ it('should call onSaveDeliverySettings and close slidebox when Done is clicked', () => {
174
+ const onSave = jest.fn();
175
+ render(
176
+ <DeliverySettings
177
+ {...defaultProps}
178
+ channel={CHANNELS.SMS}
179
+ onSaveDeliverySettings={onSave}
180
+ />
181
+ );
182
+ fireEvent.click(screen.getByTestId('delivery-settings-edit'));
183
+ fireEvent.click(screen.getByTestId('modify-done'));
184
+ expect(onSave).toHaveBeenCalledWith({ domainId: 1 });
185
+ expect(screen.queryByTestId('cap-slidebox')).toBeNull();
186
+ });
187
+
188
+ it('should pass whatsappAccountFromForm to ModifyDeliverySettings', () => {
189
+ render(
190
+ <DeliverySettings
191
+ {...defaultProps}
192
+ channel={CHANNELS.WHATSAPP}
193
+ whatsappAccountFromForm={{ accountName: 'My WABA' }}
194
+ />
195
+ );
196
+ fireEvent.click(screen.getByTestId('delivery-settings-edit'));
197
+ expect(mockModifyDeliverySettings).toHaveBeenCalledWith(
198
+ expect.objectContaining({
199
+ whatsappAccountFromForm: { accountName: 'My WABA' },
200
+ })
201
+ );
202
+ });
203
+
204
+ it('should pass SMS TRAI props to ModifyDeliverySettings', () => {
205
+ render(
206
+ <DeliverySettings
207
+ {...defaultProps}
208
+ channel={CHANNELS.SMS}
209
+ smsTraiDltEnabled
210
+ registeredSenderIds={['HPCLTD']}
211
+ />
212
+ );
213
+ fireEvent.click(screen.getByTestId('delivery-settings-edit'));
214
+ expect(mockModifyDeliverySettings).toHaveBeenCalledWith(
215
+ expect.objectContaining({
216
+ smsTraiDltEnabled: true,
217
+ registeredSenderIds: ['HPCLTD'],
218
+ })
219
+ );
220
+ });
221
+ });
222
+ });
@@ -0,0 +1,235 @@
1
+ /**
2
+ * Tests for parseSenderDetailsResponse
3
+ * Covers sender ID / delivery settings response parsing for SMS, EMAIL, WHATSAPP
4
+ */
5
+
6
+ import { parseSenderDetailsResponse } from '../../../DeliverySettings/utils/parseSenderDetailsResponse';
7
+
8
+ describe('parseSenderDetailsResponse', () => {
9
+ describe('when entity is missing or null', () => {
10
+ it('should return empty domains when response is null', () => {
11
+ expect(parseSenderDetailsResponse('SMS', null)).toEqual({ domains: [] });
12
+ });
13
+
14
+ it('should return empty domains when response is undefined', () => {
15
+ expect(parseSenderDetailsResponse('SMS', undefined)).toEqual({ domains: [] });
16
+ });
17
+
18
+ it('should return empty domains when entity is missing', () => {
19
+ expect(parseSenderDetailsResponse('SMS', {})).toEqual({ domains: [] });
20
+ });
21
+ });
22
+
23
+ describe('when entity is object with channel key', () => {
24
+ it('should parse SMS channel entity array', () => {
25
+ const response = {
26
+ entity: {
27
+ SMS: [
28
+ {
29
+ id: 10,
30
+ priority: 1,
31
+ domainProperties: {
32
+ domainName: 'SMS Domain 1',
33
+ id: 100,
34
+ contactInfo: [
35
+ { type: 'gsm_sender_id', valid: true, value: 'GSM1', default: true },
36
+ { type: 'cdma_sender_id', valid: true, value: 'CDMA1' },
37
+ ],
38
+ connectionProperties: {},
39
+ },
40
+ },
41
+ ],
42
+ },
43
+ };
44
+ const result = parseSenderDetailsResponse('SMS', response);
45
+ expect(result.domains).toHaveLength(1);
46
+ expect(result.domains[0]).toMatchObject({
47
+ dgmId: 10,
48
+ domainName: 'SMS Domain 1',
49
+ domainId: 100,
50
+ priority: 1,
51
+ });
52
+ expect(result.domains[0].gsmSenders).toHaveLength(1);
53
+ expect(result.domains[0].gsmSenders[0].value).toBe('GSM1');
54
+ expect(result.domains[0].cdmaSenders).toHaveLength(1);
55
+ expect(result.domains[0].cdmaSenders[0].value).toBe('CDMA1');
56
+ });
57
+
58
+ it('should parse EMAIL channel entity array', () => {
59
+ const response = {
60
+ entity: {
61
+ EMAIL: [
62
+ {
63
+ id: 20,
64
+ priority: 0,
65
+ domainProperties: {
66
+ domainName: 'Email Domain',
67
+ id: 200,
68
+ contactInfo: [
69
+ { type: 'sender_id', valid: true, value: 'noreply@example.com' },
70
+ { type: 'reply_to_id', valid: true, value: 'reply@example.com' },
71
+ ],
72
+ },
73
+ },
74
+ ],
75
+ },
76
+ };
77
+ const result = parseSenderDetailsResponse('EMAIL', response);
78
+ expect(result.domains).toHaveLength(1);
79
+ expect(result.domains[0]).toMatchObject({
80
+ dgmId: 20,
81
+ domainName: 'Email Domain',
82
+ domainId: 200,
83
+ priority: 0,
84
+ });
85
+ expect(result.domains[0].emailSenders).toHaveLength(1);
86
+ expect(result.domains[0].emailSenders[0].value).toBe('noreply@example.com');
87
+ expect(result.domains[0].emailRepliers).toHaveLength(1);
88
+ expect(result.domains[0].emailRepliers[0].value).toBe('reply@example.com');
89
+ });
90
+
91
+ it('should parse WHATSAPP channel with sourceAccountIdentifier', () => {
92
+ const response = {
93
+ entity: {
94
+ WHATSAPP: [
95
+ {
96
+ id: 30,
97
+ priority: 0,
98
+ domainProperties: {
99
+ domainName: 'WABA Domain',
100
+ id: 300,
101
+ contactInfo: [],
102
+ connectionProperties: {
103
+ sourceAccountIdentifier: 'waba-123',
104
+ },
105
+ },
106
+ },
107
+ ],
108
+ },
109
+ };
110
+ const result = parseSenderDetailsResponse('WHATSAPP', response);
111
+ expect(result.domains).toHaveLength(1);
112
+ expect(result.domains[0].sourceAccountIdentifier).toBe('waba-123');
113
+ expect(result.domains[0].gsmSenders).toEqual([]);
114
+ expect(result.domains[0].cdmaSenders).toEqual([]);
115
+ });
116
+ });
117
+
118
+ describe('when entity is direct array', () => {
119
+ it('should use entity as channelSenderDetails when entity is array', () => {
120
+ const response = {
121
+ entity: [
122
+ {
123
+ id: 1,
124
+ priority: 0,
125
+ domainProperties: { domainName: 'Direct Domain', id: 1 },
126
+ },
127
+ ],
128
+ };
129
+ const result = parseSenderDetailsResponse('SMS', response);
130
+ expect(result.domains).toHaveLength(1);
131
+ expect(result.domains[0].domainName).toBe('Direct Domain');
132
+ });
133
+ });
134
+
135
+ describe('filtering and sorting', () => {
136
+ it('should filter contactInfo by type and valid', () => {
137
+ const response = {
138
+ entity: {
139
+ SMS: [
140
+ {
141
+ id: 1,
142
+ priority: 0,
143
+ domainProperties: {
144
+ domainName: 'D1',
145
+ id: 1,
146
+ contactInfo: [
147
+ { type: 'gsm_sender_id', valid: true, value: 'A' },
148
+ { type: 'gsm_sender_id', valid: false, value: 'B' },
149
+ { type: 'other', valid: true, value: 'C' },
150
+ ],
151
+ },
152
+ },
153
+ ],
154
+ },
155
+ };
156
+ const result = parseSenderDetailsResponse('SMS', response);
157
+ expect(result.domains[0].gsmSenders).toHaveLength(1);
158
+ expect(result.domains[0].gsmSenders[0].value).toBe('A');
159
+ });
160
+
161
+ it('should sort domains by priority', () => {
162
+ const response = {
163
+ entity: {
164
+ SMS: [
165
+ { id: 1, priority: 2, domainProperties: { domainName: 'Second', id: 1 } },
166
+ { id: 2, priority: 0, domainProperties: { domainName: 'First', id: 2 } },
167
+ ],
168
+ },
169
+ };
170
+ const result = parseSenderDetailsResponse('SMS', response);
171
+ expect(result.domains[0].domainName).toBe('First');
172
+ expect(result.domains[1].domainName).toBe('Second');
173
+ });
174
+
175
+ it('should dedupe by domainName keeping first occurrence', () => {
176
+ const response = {
177
+ entity: {
178
+ SMS: [
179
+ { id: 1, priority: 0, domainProperties: { domainName: 'Same', id: 1 } },
180
+ { id: 2, priority: 1, domainProperties: { domainName: 'Same', id: 2 } },
181
+ ],
182
+ },
183
+ };
184
+ const result = parseSenderDetailsResponse('SMS', response);
185
+ expect(result.domains).toHaveLength(1);
186
+ expect(result.domains[0].domainId).toBe(1);
187
+ });
188
+ });
189
+
190
+ describe('edge cases', () => {
191
+ it('should return empty domains when channel key has no array', () => {
192
+ const response = { entity: { SMS: null } };
193
+ expect(parseSenderDetailsResponse('SMS', response)).toEqual({ domains: [] });
194
+ });
195
+
196
+ it('should return empty domains when channel key is missing and entity is not array', () => {
197
+ const response = { entity: { EMAIL: [] } };
198
+ expect(parseSenderDetailsResponse('SMS', response)).toEqual({ domains: [] });
199
+ });
200
+
201
+ it('should handle missing domainProperties with defaults', () => {
202
+ const response = {
203
+ entity: {
204
+ SMS: [{ id: 1, priority: 0 }],
205
+ },
206
+ };
207
+ const result = parseSenderDetailsResponse('SMS', response);
208
+ expect(result.domains).toHaveLength(1);
209
+ expect(result.domains[0].domainId).toBe(-1);
210
+ expect(result.domains[0].domainName).toBeUndefined();
211
+ expect(result.domains[0].gsmSenders).toEqual([]);
212
+ expect(result.domains[0].cdmaSenders).toEqual([]);
213
+ });
214
+
215
+ it('should use wabaId when sourceAccountIdentifier missing for WHATSAPP', () => {
216
+ const response = {
217
+ entity: {
218
+ WHATSAPP: [
219
+ {
220
+ id: 1,
221
+ priority: 0,
222
+ domainProperties: {
223
+ domainName: 'W',
224
+ id: 1,
225
+ connectionProperties: { wabaId: 'waba-456' },
226
+ },
227
+ },
228
+ ],
229
+ },
230
+ };
231
+ const result = parseSenderDetailsResponse('WHATSAPP', response);
232
+ expect(result.domains[0].sourceAccountIdentifier).toBe('waba-456');
233
+ });
234
+ });
235
+ });
@@ -2,6 +2,7 @@
2
2
  * Tests for SendTestMessage Component
3
3
  *
4
4
  * Tests the component that handles sending test messages
5
+ * @jest-environment jsdom
5
6
  */
6
7
 
7
8
  import React from 'react';
@@ -11,8 +12,34 @@ import {
11
12
  import { IntlProvider } from 'react-intl';
12
13
  import PropTypes from 'prop-types';
13
14
  import isEmpty from 'lodash/isEmpty';
15
+ // Mock cap-ui-library so SendTestMessage can load (Jest hoists mocks)
16
+ jest.mock('@capillarytech/cap-ui-library/CapRow', () => ({ children, ...rest }) => <div {...rest}>{children}</div>);
17
+ jest.mock('@capillarytech/cap-ui-library/CapButton', () => ({ children, ...rest }) => <button type="button" {...rest}>{children}</button>);
18
+ jest.mock('@capillarytech/cap-ui-library/CapHeader', () => ({ title, description }) => <div><span>{title}</span>{description}</div>);
19
+ jest.mock('@capillarytech/cap-ui-library/CapTreeSelect', () => ({ treeData, onChange, value, placeholder }) => (
20
+ <div data-testid="cap-tree-select"><input onChange={(e) => onChange && onChange(e.target.value)} placeholder={placeholder} /></div>
21
+ ));
22
+
14
23
  import SendTestMessage from '../SendTestMessage';
15
24
 
25
+ // Mock DeliverySettings to assert props
26
+ jest.mock('../DeliverySettings', () => function MockDeliverySettings(props) {
27
+ return (
28
+ <div data-testid="delivery-settings" data-props={JSON.stringify({
29
+ channel: props.channel,
30
+ hasDeliverySettings: !!props.deliverySettings,
31
+ senderDetailsLength: (props.senderDetailsOptions || []).length,
32
+ wecrmAccountsLength: (props.wecrmAccounts || []).length,
33
+ hasOnSave: typeof props.onSaveDeliverySettings === 'function',
34
+ isLoadingSenderDetails: props.isLoadingSenderDetails,
35
+ smsTraiDltEnabled: props.smsTraiDltEnabled,
36
+ registeredSenderIds: props.registeredSenderIds,
37
+ whatsappAccountFromForm: props.whatsappAccountFromForm,
38
+ })}
39
+ />
40
+ );
41
+ });
42
+
16
43
  // Mock CapStepsAccordian to always render content expanded
17
44
  jest.mock('@capillarytech/cap-ui-library/CapStepsAccordian', () => {
18
45
  // eslint-disable-next-line global-require, import/no-extraneous-dependencies
@@ -100,6 +127,14 @@ describe('SendTestMessage', () => {
100
127
  },
101
128
  isSendingTestMessage: false,
102
129
  formatMessage: jest.fn((msg) => msg.defaultMessage || msg.id),
130
+ channel: 'EMAIL',
131
+ deliverySettings: {},
132
+ senderDetailsOptions: [],
133
+ wecrmAccounts: [],
134
+ onSaveDeliverySettings: jest.fn(),
135
+ isLoadingSenderDetails: false,
136
+ smsTraiDltEnabled: false,
137
+ registeredSenderIds: [],
103
138
  };
104
139
 
105
140
  beforeEach(() => {
@@ -162,6 +197,106 @@ describe('SendTestMessage', () => {
162
197
  });
163
198
  });
164
199
 
200
+ describe('DeliverySettings (sender ID / delivery settings)', () => {
201
+ it('should render DeliverySettings when channel is SMS', () => {
202
+ render(
203
+ <TestWrapper>
204
+ <SendTestMessage {...defaultProps} channel="SMS" />
205
+ </TestWrapper>
206
+ );
207
+ const el = screen.getByTestId('delivery-settings');
208
+ expect(el).toBeTruthy();
209
+ const data = JSON.parse(el.getAttribute('data-props'));
210
+ expect(data.channel).toBe('SMS');
211
+ expect(data.hasOnSave).toBe(true);
212
+ });
213
+
214
+ it('should render DeliverySettings when channel is EMAIL', () => {
215
+ render(
216
+ <TestWrapper>
217
+ <SendTestMessage {...defaultProps} channel="EMAIL" />
218
+ </TestWrapper>
219
+ );
220
+ expect(screen.getByTestId('delivery-settings')).toBeTruthy();
221
+ });
222
+
223
+ it('should render DeliverySettings when channel is WHATSAPP', () => {
224
+ render(
225
+ <TestWrapper>
226
+ <SendTestMessage {...defaultProps} channel="WHATSAPP" />
227
+ </TestWrapper>
228
+ );
229
+ expect(screen.getByTestId('delivery-settings')).toBeTruthy();
230
+ });
231
+
232
+ it('should not render DeliverySettings when channel is INAPP', () => {
233
+ render(
234
+ <TestWrapper>
235
+ <SendTestMessage {...defaultProps} channel="INAPP" />
236
+ </TestWrapper>
237
+ );
238
+ expect(screen.queryByTestId('delivery-settings')).toBeNull();
239
+ });
240
+
241
+ it('should pass whatsappAccountFromForm when channel is WHATSAPP and formData has accountName', () => {
242
+ render(
243
+ <TestWrapper>
244
+ <SendTestMessage
245
+ {...defaultProps}
246
+ channel="WHATSAPP"
247
+ formData={{ ...defaultProps.formData, accountName: 'My WABA' }}
248
+ />
249
+ </TestWrapper>
250
+ );
251
+ const el = screen.getByTestId('delivery-settings');
252
+ const data = JSON.parse(el.getAttribute('data-props'));
253
+ expect(data.whatsappAccountFromForm).toEqual({ accountName: 'My WABA' });
254
+ });
255
+
256
+ it('should pass whatsappAccountFromForm undefined when channel is WHATSAPP and formData has no accountName', () => {
257
+ render(
258
+ <TestWrapper>
259
+ <SendTestMessage
260
+ {...defaultProps}
261
+ channel="WHATSAPP"
262
+ formData={{ ...defaultProps.formData, accountName: undefined }}
263
+ />
264
+ </TestWrapper>
265
+ );
266
+ const el = screen.getByTestId('delivery-settings');
267
+ const data = JSON.parse(el.getAttribute('data-props'));
268
+ expect(data.whatsappAccountFromForm).toBeUndefined();
269
+ });
270
+
271
+ it('should pass delivery props to DeliverySettings', () => {
272
+ const onSave = jest.fn();
273
+ render(
274
+ <TestWrapper>
275
+ <SendTestMessage
276
+ {...defaultProps}
277
+ channel="SMS"
278
+ deliverySettings={{ domainId: 1 }}
279
+ senderDetailsOptions={[{ domainId: 1, domainName: 'SMS Dom' }]}
280
+ wecrmAccounts={[]}
281
+ onSaveDeliverySettings={onSave}
282
+ isLoadingSenderDetails={true}
283
+ smsTraiDltEnabled
284
+ registeredSenderIds={['ID1']}
285
+ />
286
+ </TestWrapper>
287
+ );
288
+ const el = screen.getByTestId('delivery-settings');
289
+ const data = JSON.parse(el.getAttribute('data-props'));
290
+ expect(data.hasDeliverySettings).toBe(true);
291
+ expect(data.senderDetailsLength).toBe(1);
292
+ expect(data.wecrmAccountsLength).toBe(0);
293
+ expect(data.hasOnSave).toBe(true);
294
+ expect(data.isLoadingSenderDetails).toBe(true);
295
+ expect(data.smsTraiDltEnabled).toBe(true);
296
+ expect(data.registeredSenderIds).toEqual(['ID1']);
297
+ });
298
+ });
299
+
165
300
  describe('Loading States', () => {
166
301
  it('should show loading when fetching test customers', () => {
167
302
  const props = {
@@ -17,6 +17,8 @@ import {
17
17
  getPrefilledValuesRequested,
18
18
  clearPrefilledValues,
19
19
  clearPreviewErrors,
20
+ getSenderDetailsRequested,
21
+ getWeCrmAccountsRequested,
20
22
  } from '../actions';
21
23
 
22
24
  import {
@@ -32,6 +34,8 @@ import {
32
34
  GET_PREFILLED_VALUES_REQUESTED,
33
35
  CLEAR_PREFILLED_VALUES,
34
36
  CLEAR_PREVIEW_ERRORS,
37
+ GET_SENDER_DETAILS_REQUESTED,
38
+ GET_WECRM_ACCOUNTS_REQUESTED,
35
39
  } from '../constants';
36
40
 
37
41
  describe('CommonTestAndPreview Actions', () => {
@@ -321,4 +325,50 @@ describe('CommonTestAndPreview Actions', () => {
321
325
  expect(clearPreviewErrors()).toEqual(expectedAction);
322
326
  });
323
327
  });
328
+
329
+ describe('getSenderDetailsRequested', () => {
330
+ it('should create an action to request sender details with channel and orgUnitId', () => {
331
+ const payload = { channel: 'SMS', orgUnitId: 123 };
332
+ const expectedAction = {
333
+ type: GET_SENDER_DETAILS_REQUESTED,
334
+ payload,
335
+ };
336
+ expect(getSenderDetailsRequested(payload)).toEqual(expectedAction);
337
+ });
338
+
339
+ it('should handle EMAIL channel', () => {
340
+ const payload = { channel: 'EMAIL', orgUnitId: -1 };
341
+ expect(getSenderDetailsRequested(payload)).toEqual({
342
+ type: GET_SENDER_DETAILS_REQUESTED,
343
+ payload,
344
+ });
345
+ });
346
+
347
+ it('should handle WHATSAPP channel', () => {
348
+ const payload = { channel: 'WHATSAPP', orgUnitId: 456 };
349
+ expect(getSenderDetailsRequested(payload)).toEqual({
350
+ type: GET_SENDER_DETAILS_REQUESTED,
351
+ payload,
352
+ });
353
+ });
354
+ });
355
+
356
+ describe('getWeCrmAccountsRequested', () => {
357
+ it('should create an action to request WeCRM accounts with sourceName', () => {
358
+ const payload = { sourceName: 'WHATSAPP' };
359
+ const expectedAction = {
360
+ type: GET_WECRM_ACCOUNTS_REQUESTED,
361
+ payload,
362
+ };
363
+ expect(getWeCrmAccountsRequested(payload)).toEqual(expectedAction);
364
+ });
365
+
366
+ it('should handle empty payload', () => {
367
+ const payload = {};
368
+ expect(getWeCrmAccountsRequested(payload)).toEqual({
369
+ type: GET_WECRM_ACCOUNTS_REQUESTED,
370
+ payload: {},
371
+ });
372
+ });
373
+ });
324
374
  });