@capillarytech/creatives-library 7.12.40 → 7.12.42

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "7.12.40",
4
+ "version": "7.12.42",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -27,11 +27,6 @@ export const CTA_URL_OPTIONS = [
27
27
  value: STATIC_URL,
28
28
  label: <FormattedMessage {...messages.ctaWebsiteTypeStatic} />,
29
29
  },
30
- // {
31
- // value: DYNAMIC_URL,
32
- // label: <FormattedMessage {...messages.ctaWebsiteTypeDynamic} />,
33
- // disabled: true,
34
- // },
35
30
  ];
36
31
  export const BTN_MAX_LENGTH = 20;
37
32
  export const PHONE_NUMBER_MAX_LENGTH = 15;
@@ -90,6 +90,7 @@ export const CapWhatsappCTA = (props) => {
90
90
 
91
91
  const ctaOptions = CTA_OPTIONS.map((option) => {
92
92
  const { value, label, tooltipLabel } = option;
93
+ //if button 1 is of type-> PHONE_NUMBER, it is disabled in second button
93
94
  const isDisabled = ctaData.length === 2 && ctaData[0].ctaType === value;
94
95
  return {
95
96
  value,
@@ -132,10 +133,7 @@ export const CapWhatsappCTA = (props) => {
132
133
  const { ctaType, text, phone_number, url } = ctaData[index] || {};
133
134
  if (text === '') {
134
135
  return true;
135
- } else if (
136
- ctaType === PHONE_NUMBER &&
137
- (phone_number === '91' || phone_number === '' || phone_number.length < 5)
138
- ) {
136
+ } else if (ctaType === PHONE_NUMBER && phone_number.length < 5) {
139
137
  return true;
140
138
  } else if (ctaType === WEBSITE && (url === '' || urlError)) {
141
139
  return true;
@@ -152,6 +150,7 @@ export const CapWhatsappCTA = (props) => {
152
150
 
153
151
  const renderedContent = () => {
154
152
  const renderArray = [];
153
+ const addBtnDisabled = ctaData.length === 1 && !ctaData[0].isSaved;
155
154
  ctaData.forEach((cta) => {
156
155
  const { index, ctaType, text, phone_number, url, isSaved } = cta || {};
157
156
  if (isSaved) {
@@ -166,17 +165,20 @@ export const CapWhatsappCTA = (props) => {
166
165
  <CapIcon
167
166
  size="s"
168
167
  type="drag"
169
- style={{ transform: 'rotate(90deg)' }}
168
+ className="whatsapp-saved-cta-drag-icon"
170
169
  />
171
170
  </CapColumn>
172
171
  <CapColumn
173
172
  span={1}
174
- style={{ marginBottom: ctaIsPhone ? '-4px' : '' }}
173
+ className={`${ctaIsPhone ? 'whatsapp-saved-cta-phone-icon' : ''}`}
175
174
  >
176
175
  <CapIcon size="s" type={ctaIsPhone ? 'call' : 'launch'} />
177
176
  </CapColumn>
178
177
  <CapColumn span={6}>
179
- <CapLabel type="label2" style={{ fontWeight: '500' }}>
178
+ <CapLabel
179
+ type="label2"
180
+ className="whatsapp-saved-cta-button-text"
181
+ >
180
182
  {text}
181
183
  </CapLabel>
182
184
  </CapColumn>
@@ -199,7 +201,7 @@ export const CapWhatsappCTA = (props) => {
199
201
  )}
200
202
  <CapColumn
201
203
  span={1}
202
- style={{ marginLeft: '16px' }}
204
+ className="whatsapp-saved-cta-edit-icon"
203
205
  onClick={() => editCta(index)}
204
206
  >
205
207
  <CapIcon size="s" type="edit" />
@@ -338,15 +340,14 @@ export const CapWhatsappCTA = (props) => {
338
340
  });
339
341
  // eslint-disable-next-line no-lone-blocks
340
342
  {
343
+ // when first button is not saved, add button is disabled with tooltip
341
344
  // eslint-disable-next-line no-unused-expressions
342
345
  ctaData.length < 2 &&
343
346
  renderArray.push(
344
347
  <CapRow>
345
348
  <CapTooltip
346
349
  title={
347
- ctaData.length === 1 && !ctaData[0].isSaved
348
- ? formatMessage(messages.ctaAddDisabled)
349
- : ''
350
+ addBtnDisabled ? formatMessage(messages.ctaAddDisabled) : ''
350
351
  }
351
352
  placement={'right'}
352
353
  >
@@ -354,7 +355,7 @@ export const CapWhatsappCTA = (props) => {
354
355
  <CapButton
355
356
  type="flat"
356
357
  id="whatsapp-cta-add-button"
357
- disabled={ctaData.length === 1 && !ctaData[0].isSaved}
358
+ disabled={addBtnDisabled}
358
359
  className="margin-t-12 margin-l-24"
359
360
  isAddBtn
360
361
  onClick={addCta}
@@ -24,6 +24,21 @@
24
24
  text-align: center;
25
25
  background-color: #f1f1f1;
26
26
  }
27
+
28
+ .whatsapp-saved-cta-drag-icon {
29
+ transform: rotate(90deg);
30
+ }
31
+
32
+ .whatsapp-saved-cta-phone-icon {
33
+ margin-bottom: -4px;
34
+ }
35
+
36
+ .whatsapp-saved-cta-button-text {
37
+ font-weight: 500;
38
+ }
39
+ .whatsapp-saved-cta-edit-icon{
40
+ margin-left: 16px;
41
+ }
27
42
  }
28
43
 
29
44
  .cap-whatsapp-cta {
@@ -29,10 +29,6 @@ export default defineMessages({
29
29
  id: `${prefix}.ctaWebsiteTypeStatic`,
30
30
  defaultMessage: 'Static',
31
31
  },
32
- // ctaWebsiteTypeDynamic: {
33
- // id: `${prefix}.ctaWebsiteTypeDynamic`,
34
- // defaultMessage: 'Dynamic',
35
- // },
36
32
  ctaPhoneNoPlaceholder: {
37
33
  id: `${prefix}.ctaPhoneNoPlaceholder`,
38
34
  defaultMessage: 'Enter phone number',
@@ -0,0 +1,152 @@
1
+ import React from 'react';
2
+ import { injectIntl } from 'react-intl';
3
+ import '@testing-library/jest-dom';
4
+ import { render, screen, fireEvent } from '../../../utils/test-utils';
5
+ import { CapWhatsappCTA } from '../index';
6
+ import { INITIAL_CTA_DATA } from '../../../v2Containers/Whatsapp/constants';
7
+ import userEvent from '@testing-library/user-event';
8
+
9
+ const updateHandler = jest.fn();
10
+ const deleteHandler = jest.fn();
11
+ const initializeComponent = (data) => {
12
+ const Component = injectIntl(CapWhatsappCTA);
13
+ return render(
14
+ <Component
15
+ ctaData={data}
16
+ updateHandler={updateHandler}
17
+ deleteHandler={deleteHandler}
18
+ />,
19
+ );
20
+ };
21
+
22
+ describe('CapWhatsappCTA', () => {
23
+ it('Test if CapWhatsappCTA component renders', () => {
24
+ initializeComponent([
25
+ {
26
+ index: 0,
27
+ ctaType: 'PHONE_NUMBER',
28
+ text: '',
29
+ phone_number: '9112345',
30
+ urlType: 'STATIC_URL',
31
+ url: '',
32
+ isSaved: false,
33
+ },
34
+ ]);
35
+ expect(screen.getByText('Type of action')).toBeInTheDocument();
36
+ expect(screen.getByText('Button text')).toBeInTheDocument();
37
+ expect(screen.getAllByText('Phone number')[1]).toBeInTheDocument();
38
+ expect(screen.getByRole('button', { name: /save/i })).toBeDisabled();
39
+ });
40
+
41
+ it('first button', async () => {
42
+ initializeComponent([
43
+ {
44
+ index: 0,
45
+ ctaType: 'PHONE_NUMBER',
46
+ text: '',
47
+ phone_number: '9112345',
48
+ urlType: 'STATIC_URL',
49
+ url: '',
50
+ isSaved: false,
51
+ },
52
+ ]);
53
+ const btnTextEvent = {
54
+ target: {
55
+ value: 'Call us',
56
+ id: 0,
57
+ },
58
+ };
59
+ // button text
60
+ const buttontextInput = await screen.getByPlaceholderText(
61
+ 'Enter button text',
62
+ );
63
+ fireEvent.change(buttontextInput, btnTextEvent);
64
+ expect(updateHandler).toHaveBeenCalledWith(
65
+ {
66
+ index: 0,
67
+ ctaType: 'PHONE_NUMBER',
68
+ text: 'Call us',
69
+ phone_number: '9112345',
70
+ urlType: 'STATIC_URL',
71
+ url: '',
72
+ isSaved: false,
73
+ },
74
+ '0',
75
+ );
76
+ });
77
+ it('second button', async () => {
78
+ initializeComponent([
79
+ {
80
+ index: 0,
81
+ ctaType: 'PHONE_NUMBER',
82
+ text: 'Call us',
83
+ phone_number: '9112345',
84
+ urlType: 'STATIC_URL',
85
+ url: '',
86
+ isSaved: true,
87
+ },
88
+ {
89
+ index: 1,
90
+ ctaType: 'WEBSITE',
91
+ text: 'Visit us',
92
+ phone_number: '',
93
+ urlType: 'STATIC_URL',
94
+ url: '',
95
+ isSaved: false,
96
+ },
97
+ ]);
98
+ const urlEvent1 = {
99
+ target: {
100
+ value: 'https://www.google.co.in',
101
+ id: 1,
102
+ },
103
+ };
104
+ const urlEvent2 = {
105
+ target: {
106
+ value: 'test',
107
+ id: 1,
108
+ },
109
+ };
110
+ // button text
111
+ const urlInput = await screen.getByPlaceholderText(
112
+ 'Enter website URL',
113
+ );
114
+ fireEvent.change(urlInput, urlEvent1);
115
+ expect(updateHandler).toHaveBeenCalledWith(
116
+ {
117
+ index: 1,
118
+ ctaType: 'WEBSITE',
119
+ text: 'Visit us',
120
+ phone_number: '',
121
+ urlType: 'STATIC_URL',
122
+ url: 'https://www.google.co.in',
123
+ isSaved: false,
124
+ },
125
+ '1',
126
+ );
127
+ fireEvent.change(urlInput, urlEvent2);
128
+ });
129
+ it('both buttons', async () => {
130
+ initializeComponent([
131
+ {
132
+ index: 0,
133
+ ctaType: 'PHONE_NUMBER',
134
+ text: 'Call us',
135
+ phone_number: '9112345',
136
+ urlType: 'STATIC_URL',
137
+ url: '',
138
+ isSaved: true,
139
+ },
140
+ {
141
+ index: 1,
142
+ ctaType: 'WEBSITE',
143
+ text: 'Visit us',
144
+ phone_number: '',
145
+ urlType: 'STATIC_URL',
146
+ url: 'https://www.google.co.in',
147
+ isSaved: true,
148
+ },
149
+ ]);
150
+ expect(screen.getByText(/https:\/\/www\.google\.co\.in/i)).toBeInTheDocument();
151
+ });
152
+ });
@@ -3,10 +3,7 @@
3
3
  exports[`Test Templates container Should render correct preview component for rcs channel 1`] = `
4
4
  <CapRow>
5
5
  <CapColumn
6
- span={16}
7
- />
8
- <CapColumn
9
- span={8}
6
+ span={24}
10
7
  >
11
8
  <div
12
9
  className="preview-container "
@@ -24,7 +21,21 @@ exports[`Test Templates container Should render correct preview component for rc
24
21
  >
25
22
  <div
26
23
  className="message-pop sms"
27
- />
24
+ >
25
+ <CapLabel
26
+ className="message-pop-item align-left rcs-content"
27
+ fontWeight="bold"
28
+ type="label5"
29
+ >
30
+ RCS Title
31
+ </CapLabel>
32
+ <CapLabel
33
+ className="message-pop-item align-left rcs-content rcs-desc"
34
+ type="label5"
35
+ >
36
+ RCS Description
37
+ </CapLabel>
38
+ </div>
28
39
  </div>
29
40
  </div>
30
41
  </div>
@@ -35,26 +46,187 @@ exports[`Test Templates container Should render correct preview component for rc
35
46
  exports[`Test Templates container Should render correct preview component for whatsapp channel 1`] = `
36
47
  <CapRow>
37
48
  <CapColumn
38
- span={16}
49
+ span={24}
50
+ >
51
+ <div
52
+ className="preview-container "
53
+ >
54
+ <div
55
+ className="shell-v2 align-center"
56
+ >
57
+ <CapImage
58
+ alt="Preview is being generated"
59
+ className="preview-image"
60
+ src="test-file-stub"
61
+ />
62
+ <CapLabel
63
+ className="whatsapp-brand-name"
64
+ type="label1"
65
+ >
66
+ 30
67
+ </CapLabel>
68
+ <div
69
+ className="msg-container whatsapp-message-container"
70
+ >
71
+ <div
72
+ className="message-pop align-left"
73
+ style={
74
+ Object {
75
+ "background-color": "#ffffff",
76
+ "border-radius": "6px",
77
+ "left": 0,
78
+ "padding": "4px 0 0.571rem",
79
+ "width": "88%",
80
+ }
81
+ }
82
+ >
83
+ <CapLabel
84
+ className="whatsapp-content"
85
+ type="label1"
86
+ >
87
+ You have received {{1}} points
88
+ </CapLabel>
89
+ <CapDivider
90
+ className="whatsapp-divider"
91
+ />
92
+ <CapLabel
93
+ className="whatsapp-cta-preview"
94
+ type="label21"
95
+ >
96
+ <CapIcon
97
+ size="xs"
98
+ svgProps={
99
+ Object {
100
+ "style": Object {
101
+ "marginRight": "4px",
102
+ },
103
+ }
104
+ }
105
+ type="call"
106
+ />
107
+ Call
108
+ </CapLabel>
109
+ <CapLabel
110
+ className="whatsapp-cta-preview"
111
+ type="label21"
112
+ >
113
+ <CapIcon
114
+ size="xs"
115
+ svgProps={
116
+ Object {
117
+ "style": Object {
118
+ "marginRight": "4px",
119
+ },
120
+ }
121
+ }
122
+ type="launch"
123
+ />
124
+ Visit
125
+ </CapLabel>
126
+ </div>
127
+ </div>
128
+ </div>
129
+ <CapHeading
130
+ className="margin-t-16"
131
+ style={
132
+ Object {
133
+ "textAlign": "center",
134
+ }
135
+ }
136
+ type="h3"
137
+ >
138
+ <FormattedMessage
139
+ defaultMessage="1 Message ({length} characters)"
140
+ id="app.components.TemplatePreview.whatsappMessageLength"
141
+ values={
142
+ Object {
143
+ "length": "test",
144
+ }
145
+ }
146
+ />
147
+ </CapHeading>
148
+ </div>
149
+ </CapColumn>
150
+ </CapRow>
151
+ `;
152
+
153
+ exports[`Test Templates container Should render correct preview component for whatsapp channel 2`] = `
154
+ <CapRow>
155
+ <CapColumn
156
+ span={24}
39
157
  >
40
- <WhatsappStatusContainer />
41
- <CapHeading
42
- className="margin-t-12"
43
- type="h3"
158
+ <div
159
+ className="preview-container "
44
160
  >
45
- <FormattedMessage
46
- defaultMessage="1 Message ({length} characters)"
47
- id="app.components.TemplatePreview.whatsappMessageLength"
48
- values={
161
+ <div
162
+ className="shell-v2 align-center"
163
+ >
164
+ <CapImage
165
+ alt="Preview is being generated"
166
+ className="preview-image"
167
+ src="test-file-stub"
168
+ />
169
+ <CapLabel
170
+ className="whatsapp-brand-name"
171
+ type="label1"
172
+ >
173
+ 30
174
+ </CapLabel>
175
+ <div
176
+ className="msg-container whatsapp-message-container"
177
+ >
178
+ <div
179
+ className="message-pop align-left"
180
+ style={
181
+ Object {
182
+ "background-color": "#ffffff",
183
+ "border-radius": "6px",
184
+ "left": 0,
185
+ "padding": "4px 0 0.571rem",
186
+ "width": "88%",
187
+ }
188
+ }
189
+ >
190
+ <CapLabel
191
+ className="whatsapp-content"
192
+ type="label1"
193
+ >
194
+ You have received {{1}} points
195
+ </CapLabel>
196
+ <CapDivider
197
+ className="whatsapp-divider"
198
+ />
199
+ </div>
200
+ </div>
201
+ </div>
202
+ <CapHeading
203
+ className="margin-t-16"
204
+ style={
49
205
  Object {
50
- "length": undefined,
206
+ "textAlign": "center",
51
207
  }
52
208
  }
53
- />
54
- </CapHeading>
209
+ type="h3"
210
+ >
211
+ <FormattedMessage
212
+ defaultMessage="1 Message ({length} characters)"
213
+ id="app.components.TemplatePreview.whatsappMessageLength"
214
+ values={
215
+ Object {
216
+ "length": "test",
217
+ }
218
+ }
219
+ />
220
+ </CapHeading>
221
+ </div>
55
222
  </CapColumn>
223
+ </CapRow>
224
+ `;
225
+
226
+ exports[`Test Templates container Should render correct preview component for whatsapp channel 3`] = `
227
+ <CapRow>
56
228
  <CapColumn
57
- span={8}
229
+ span={24}
58
230
  >
59
231
  <div
60
232
  className="preview-container "
@@ -107,7 +279,7 @@ exports[`Test Templates container Should render correct preview component for wh
107
279
  id="app.components.TemplatePreview.whatsappMessageLength"
108
280
  values={
109
281
  Object {
110
- "length": undefined,
282
+ "length": "test",
111
283
  }
112
284
  }
113
285
  />
@@ -3,22 +3,69 @@ import { shallowWithIntl } from '../../../helpers/intl-enzym-test-helpers';
3
3
 
4
4
  import { TemplatePreview } from '../index';
5
5
 
6
-
7
6
  describe('Test Templates container', () => {
8
7
  let renderedComponent;
9
8
 
10
- const renderFunction = (channel) => {
9
+ const renderFunction = (
10
+ channel,
11
+ content,
12
+ whatsappAccountName,
13
+ whatsappContentLen,
14
+ ) => {
11
15
  renderedComponent = shallowWithIntl(
12
- <TemplatePreview channel={channel} showCount />,
16
+ <TemplatePreview
17
+ channel={channel}
18
+ content={content}
19
+ whatsappAccountName={whatsappAccountName}
20
+ whatsappContentLen={whatsappContentLen}
21
+ />,
13
22
  );
14
23
  };
15
24
 
16
25
  it('Should render correct preview component for whatsapp channel', () => {
17
- renderFunction('whatsapp');
26
+ renderFunction(
27
+ 'whatsapp',
28
+ {
29
+ templateMsg: 'You have received {{1}} points',
30
+ ctaData: [
31
+ {
32
+ index: 0,
33
+ type: 'PHONE_NUMBER',
34
+ text: 'Call',
35
+ phone_number: '+917892303868',
36
+ },
37
+ {
38
+ index: 1,
39
+ type: 'STATIC_URL',
40
+ text: 'Visit',
41
+ url: 'https://www.capillarytech.com/',
42
+ },
43
+ ],
44
+ },
45
+ 30,
46
+ 'test',
47
+ );
48
+ expect(renderedComponent).toMatchSnapshot();
49
+ renderFunction(
50
+ 'whatsapp',
51
+ {
52
+ templateMsg: 'You have received {{1}} points',
53
+ ctaData: [{}],
54
+ },
55
+ 30,
56
+ 'test',
57
+ );
58
+ expect(renderedComponent).toMatchSnapshot();
59
+ renderFunction('whatsapp', {}, 0, 'test');
18
60
  expect(renderedComponent).toMatchSnapshot();
19
61
  });
20
62
  it('Should render correct preview component for rcs channel', () => {
21
- renderFunction('rcs');
63
+ renderFunction('rcs', {
64
+ rcsPreviewContent: {
65
+ rcsTitle: 'RCS Title',
66
+ rcsDesc: 'RCS Description',
67
+ },
68
+ });
22
69
  expect(renderedComponent).toMatchSnapshot();
23
70
  });
24
71
  });
@@ -367,6 +367,7 @@ export class Creatives extends React.Component {
367
367
  }
368
368
  case constants.WHATSAPP: {
369
369
  const {
370
+ messageBody = '',
370
371
  templateConfigs: {
371
372
  id,
372
373
  name,
@@ -387,6 +388,7 @@ export class Creatives extends React.Component {
387
388
  }
388
389
  return btn;
389
390
  });
391
+ const unsubscribeRegex = /Click {{unsubscribe}} to unsubscribe/g;
390
392
  creativesTemplateData = {
391
393
  _id: id,
392
394
  type: constants.WHATSAPP,
@@ -401,11 +403,14 @@ export class Creatives extends React.Component {
401
403
  varMapped,
402
404
  mediaType,
403
405
  buttonType,
404
- buttons : modifiedButtons,
406
+ buttons: modifiedButtons,
405
407
  languages: [
406
408
  {
407
409
  language,
408
- content: template,
410
+ content:
411
+ messageBody.match(unsubscribeRegex)?.length > 0
412
+ ? `${template}\nClick {{unsubscribe}} to unsubscribe`
413
+ : template,
409
414
  },
410
415
  ],
411
416
  },
@@ -196,6 +196,20 @@ exports[`Test SlideBoxContent container Should render correct component for what
196
196
  content={
197
197
  Object {
198
198
  "charCount": 46,
199
+ "ctaData": Array [
200
+ Object {
201
+ "index": 0,
202
+ "phone_number": "+919738752617",
203
+ "text": "Call",
204
+ "type": "PHONE_NUMBER",
205
+ },
206
+ Object {
207
+ "index": 1,
208
+ "text": "More info",
209
+ "type": "STATIC_URL",
210
+ "url": "https://fast.com/",
211
+ },
212
+ ],
199
213
  "templateMsg": <React.Fragment>
200
214
  <CapLabel
201
215
  type="label5"
@@ -229,6 +243,21 @@ Click {{unsubscribe}} to unsubscribe
229
243
  "accessToken": "4676323eb5d1f975b0987070c03a8efc",
230
244
  "accountId": "AC41030cebba9e2f1ce37c78235da0ee18",
231
245
  "accountName": "whatsappTest",
246
+ "buttonType": "CTA",
247
+ "buttons": Array [
248
+ Object {
249
+ "index": 0,
250
+ "phone_number": "+919738752617",
251
+ "text": "Call",
252
+ "type": "PHONE_NUMBER",
253
+ },
254
+ Object {
255
+ "index": 1,
256
+ "text": "More info",
257
+ "type": "STATIC_URL",
258
+ "url": "https://fast.com/",
259
+ },
260
+ ],
232
261
  "category": "ALERT_UPDATE",
233
262
  "languages": Array [
234
263
  Object {