@capillarytech/creatives-library 7.10.39 → 7.10.40

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 (37) hide show
  1. package/containers/Assets/Gallery/tests/__snapshots__/reducer.test.js.snap +0 -2
  2. package/containers/Email/index.js +2 -3
  3. package/index.js +6 -0
  4. package/package.json +1 -1
  5. package/routes.js +5 -0
  6. package/services/api.js +6 -1
  7. package/v2Components/TemplatePreview/_templatePreview.scss +7 -0
  8. package/v2Components/TemplatePreview/assets/images/whatsapp_mobile_android.svg +2041 -0
  9. package/v2Components/TemplatePreview/index.js +57 -3
  10. package/v2Components/TemplatePreview/messages.js +8 -0
  11. package/v2Containers/Assets/Gallery/tests/__snapshots__/reducer.test.js.snap +0 -2
  12. package/v2Containers/Assets/images/whatsappIllustration.png +0 -0
  13. package/v2Containers/CreativesContainer/SlideBoxContent.js +24 -2
  14. package/v2Containers/CreativesContainer/SlideBoxHeader.js +1 -0
  15. package/v2Containers/CreativesContainer/constants.js +1 -0
  16. package/v2Containers/Email/index.js +1 -3
  17. package/v2Containers/Line/Container/index.js +1 -1
  18. package/v2Containers/Templates/_templates.scss +43 -0
  19. package/v2Containers/Templates/actions.js +18 -10
  20. package/v2Containers/Templates/constants.js +3 -1
  21. package/v2Containers/Templates/index.js +259 -43
  22. package/v2Containers/Templates/messages.js +32 -0
  23. package/v2Containers/Templates/reducer.js +2 -0
  24. package/v2Containers/TemplatesV2/index.js +2 -0
  25. package/v2Containers/TemplatesV2/messages.js +4 -0
  26. package/v2Containers/Whatsapp/actions.js +17 -0
  27. package/v2Containers/Whatsapp/constants.js +98 -0
  28. package/v2Containers/Whatsapp/index.js +469 -0
  29. package/v2Containers/Whatsapp/index.scss +36 -0
  30. package/v2Containers/Whatsapp/messages.js +184 -0
  31. package/v2Containers/Whatsapp/reducer.js +39 -0
  32. package/v2Containers/Whatsapp/sagas.js +48 -0
  33. package/v2Containers/Whatsapp/selectors.js +25 -0
  34. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +123185 -0
  35. package/v2Containers/Whatsapp/tests/index.test.js +132 -0
  36. package/v2Containers/Whatsapp/tests/mockData.js +10 -0
  37. package/v2Containers/Whatsapp/utils.js +106 -0
@@ -0,0 +1,132 @@
1
+ import React from 'react';
2
+ import { browserHistory } from 'react-router';
3
+ import configureStore from '../../../store';
4
+ import { Provider } from 'react-redux';
5
+ import { mountWithIntl } from '../../../../app/helpers/intl-enzym-test-helpers';
6
+ import { Whatsapp } from '../index';
7
+ import { mockData } from './mockData';
8
+
9
+ let store;
10
+ beforeAll(() => {
11
+ store = configureStore({}, browserHistory);
12
+ });
13
+
14
+ describe('Creatives Whatsapp test/>', () => {
15
+ let renderedComponent;
16
+ const createWhatsappTemplate = jest.fn();
17
+ const clearCreateResponse = jest.fn();
18
+ const handleClose = jest.fn();
19
+ const onCreateComplete = jest.fn();
20
+ const formatMessage = jest.fn();
21
+ const location = mockData.location;
22
+ beforeEach(() => {
23
+ renderedComponent = mountWithIntl(
24
+ <Provider store={store}>
25
+ <Whatsapp
26
+ actions={{ createWhatsappTemplate, clearCreateResponse }}
27
+ onCreateComplete={onCreateComplete}
28
+ handleClose={handleClose}
29
+ location={location}
30
+ intl={{ formatMessage }}
31
+ isFullMode={true}
32
+ selectedWeChatAccount={{
33
+ name: 'Test Account',
34
+ configs: { accessToken: '123' },
35
+ sourceAccountIdentifier: 'A123',
36
+ }}
37
+ />
38
+ </Provider>,
39
+ );
40
+ });
41
+
42
+ it('should render', () => {
43
+ expect(renderedComponent).toMatchSnapshot();
44
+ });
45
+
46
+ it('template name change', () => {
47
+ const templateNameRenderHelper = (val) => {
48
+ let event = { target: { value: val } };
49
+ renderedComponent
50
+ .find('#whatsapp_template_name_input')
51
+ .at(3)
52
+ .simulate('change', event);
53
+ };
54
+ templateNameRenderHelper('template_name');
55
+ expect(renderedComponent).toMatchSnapshot();
56
+ templateNameRenderHelper('');
57
+ expect(renderedComponent).toMatchSnapshot();
58
+ templateNameRenderHelper('TEMP');
59
+ expect(renderedComponent).toMatchSnapshot();
60
+ });
61
+
62
+ it('template category change', () => {
63
+ renderedComponent
64
+ .find('CapSelect#select-whatsapp-category')
65
+ .props()
66
+ .onChange('RESERVATION_UPDATE');
67
+ expect(renderedComponent).toMatchSnapshot();
68
+ });
69
+
70
+ it('template message', () => {
71
+ const templateMessageRenderHelper = (val) => {
72
+ let event = { target: { value: val } };
73
+ renderedComponent
74
+ .find('TextArea#whatsapp-template-message-input')
75
+ .at(1)
76
+ .simulate('change', event);
77
+ };
78
+ templateMessageRenderHelper('');
79
+ expect(renderedComponent).toMatchSnapshot();
80
+ templateMessageRenderHelper('Hi {{1}}');
81
+ expect(renderedComponent).toMatchSnapshot();
82
+ templateMessageRenderHelper('Hi {{1}}{{2}}');
83
+ expect(renderedComponent).toMatchSnapshot();
84
+ templateMessageRenderHelper('Hi {{var}}');
85
+ expect(renderedComponent).toMatchSnapshot();
86
+ templateMessageRenderHelper('Hi {{1}}, offer {{3}}');
87
+ expect(renderedComponent).toMatchSnapshot();
88
+ templateMessageRenderHelper('Hi {{1}}{{1}}');
89
+ expect(renderedComponent).toMatchSnapshot();
90
+ });
91
+
92
+ it('send for approval should be disabled', () => {
93
+ const sendForApprovalBtn = renderedComponent
94
+ .find('CapButton.whatsapp-create-btn')
95
+ .props();
96
+ expect(sendForApprovalBtn.children.props.defaultMessage).toBe(
97
+ 'Send for approval',
98
+ );
99
+ expect(sendForApprovalBtn.disabled).toBe(true);
100
+ });
101
+
102
+ it('Cancel Btn', () => {
103
+ const cancelBtn = renderedComponent
104
+ .find('CapButton.whatsapp-cancel-btn')
105
+ .props();
106
+ expect(cancelBtn.children.props.defaultMessage).toBe('Cancel');
107
+ cancelBtn.onClick();
108
+ expect(renderedComponent).toMatchSnapshot();
109
+ });
110
+
111
+ it('set all valid values and send for approval', () => {
112
+ let event = { target: { value: 'template_name' } };
113
+ createWhatsappTemplate.mockImplementation((obj, callback) => {
114
+ callback();
115
+ });
116
+ renderedComponent
117
+ .find('#whatsapp_template_name_input')
118
+ .at(3)
119
+ .simulate('change', event);
120
+ renderedComponent
121
+ .find('CapSelect#select-whatsapp-category')
122
+ .props()
123
+ .onChange('APPOINTMENT_UPDATE');
124
+ event = { target: { value: 'Hi {{1}}' } };
125
+ renderedComponent
126
+ .find('TextArea#whatsapp-template-message-input')
127
+ .at(1)
128
+ .simulate('change', event);
129
+ renderedComponent.find('CapButton.whatsapp-create-btn').props().onClick();
130
+ expect(renderedComponent).toMatchSnapshot();
131
+ });
132
+ });
@@ -0,0 +1,10 @@
1
+ export const mockData = {
2
+ location: {
3
+ pathname: '/whatsapp',
4
+ query: {
5
+ type: false,
6
+ module: 'default',
7
+ },
8
+ search: '',
9
+ },
10
+ };
@@ -0,0 +1,106 @@
1
+ import React from 'react';
2
+ import { CapRow, CapStatus, CapColoredTag } from '@capillarytech/cap-ui-library';
3
+ import { WHATSAPP } from '../CreativesContainer/constants';
4
+ import {
5
+ CATEGORY as WHATSAPP_CATEGORY,
6
+ STATUS as WHATSAPP_STATUS,
7
+ STATUS_OPTIONS,
8
+ CATEGORY_OPTIONS,
9
+ WHATSAPP_STATUSES,
10
+ } from '../Whatsapp/constants';
11
+
12
+ export const getWhatsappContent = (template) => {
13
+ const {
14
+ versions: {
15
+ base: {
16
+ content: {
17
+ [WHATSAPP.toLowerCase()]: {
18
+ languages = [{}],
19
+ 'var-mapped': varMapped = {},
20
+ } = {},
21
+ } = {},
22
+ } = {},
23
+ } = {},
24
+ } = template;
25
+ let text = languages[0]?.content?.slice(2, -1) || '';
26
+ let searchStartIndex = 0;
27
+
28
+ while (true) {
29
+ // starting position of {{x}}
30
+ const openIndex = text.indexOf("{{", searchStartIndex);
31
+ // closing position of {{x}}
32
+ const closeIndex = text.indexOf("}}", searchStartIndex);
33
+ if (openIndex > -1) {
34
+ // Number inside the current braces
35
+ const varDigit = text.substring(openIndex + 2, closeIndex);
36
+ // Var mapped value corresponding to current digit inside braces
37
+ const mappedValue = varMapped[varDigit];
38
+ let lengthDifference = 0;
39
+ if(mappedValue) {
40
+ // repacing the number inside braces with mapped value
41
+ text = text.slice(0, openIndex) + mappedValue + text.slice(closeIndex + 2);
42
+ lengthDifference = (mappedValue?.length - (varDigit?.length + 4));
43
+ }
44
+ // incrementing the searchStartIndex by difference between the length of mapped value and length of braces {{xx}}
45
+ searchStartIndex = closeIndex + lengthDifference + 2;
46
+ } else {
47
+ break;
48
+ }
49
+ }
50
+ return text;
51
+ }
52
+
53
+ export const getWhatsappCategory = (category) => {
54
+ return CATEGORY_OPTIONS.find((obj) => obj.value === category);
55
+ }
56
+
57
+ export const getWhatsappStatus = (status) => {
58
+ if ([WHATSAPP_STATUSES.pending, WHATSAPP_STATUSES.unsubmitted].includes(status)) {
59
+ status = WHATSAPP_STATUSES.awaitingApproval;
60
+ }
61
+ return STATUS_OPTIONS.find((obj) => obj.value === status);
62
+ }
63
+
64
+ export const getWhatsappStatusContainer = (template) => {
65
+ const {
66
+ versions: {
67
+ base: {
68
+ content: {
69
+ [WHATSAPP.toLowerCase()]: {
70
+ [WHATSAPP_STATUS]: status,
71
+ [WHATSAPP_CATEGORY]: category,
72
+ } = {},
73
+ } = {},
74
+ } = {},
75
+ } = {},
76
+ } = template;
77
+
78
+ const categoryObj = getWhatsappCategory(category) || {};
79
+ const {
80
+ label: categoryLabel,
81
+ tagColor: categoryTagColor,
82
+ tagTextColor: categoryTextColor,
83
+ } = categoryObj;
84
+ return (
85
+ <CapRow type="flex" align="middle" className="whatsapp-status-container">
86
+ <CapStatus
87
+ type={status}
88
+ text={getWhatsappStatus(status)?.label}
89
+ labelType="label3"
90
+ />
91
+ {
92
+ categoryLabel ? (
93
+ <CapColoredTag
94
+ tagColor={categoryTagColor}
95
+ tagTextColor={categoryTextColor}
96
+ tagHeight="20px"
97
+ tagFontSize="12px"
98
+ className="whatsapp-category-tag"
99
+ >
100
+ {categoryLabel}
101
+ </CapColoredTag>
102
+ ) : null
103
+ }
104
+ </CapRow>
105
+ )
106
+ }