@capillarytech/creatives-library 7.10.65 → 7.10.67

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 (31) hide show
  1. package/package.json +2 -1
  2. package/utils/tests/v2Common.test.js +11 -0
  3. package/utils/v2common.js +7 -0
  4. package/v2Components/TemplatePreview/_templatePreview.scss +0 -7
  5. package/v2Components/TemplatePreview/index.js +4 -3
  6. package/v2Components/TemplatePreview/tests/__snapshots__/index.test.js.snap +95 -0
  7. package/v2Components/TemplatePreview/tests/index.test.js +20 -6
  8. package/v2Components/WhatsappStatusContainer/tests/__snapshots__/index.test.js.snap +37 -0
  9. package/v2Components/WhatsappStatusContainer/tests/index.test.js +23 -0
  10. package/v2Components/mockdata.js +39 -0
  11. package/v2Containers/Cap/messages.js +5 -0
  12. package/v2Containers/CreativesContainer/SlideBoxContent.js +1 -1
  13. package/v2Containers/CreativesContainer/SlideBoxHeader.js +2 -3
  14. package/v2Containers/CreativesContainer/index.js +5 -5
  15. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +49 -0
  16. package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +50 -0
  17. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +125 -0
  18. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +166 -0
  19. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +145 -0
  20. package/v2Containers/CreativesContainer/tests/index.test.js +54 -6
  21. package/v2Containers/Templates/index.js +2 -8
  22. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +5604 -0
  23. package/v2Containers/Templates/tests/index.test.js +121 -6
  24. package/v2Containers/TemplatesV2/index.js +7 -7
  25. package/v2Containers/Whatsapp/constants.js +7 -1
  26. package/v2Containers/Whatsapp/index.js +23 -18
  27. package/v2Containers/Whatsapp/messages.js +0 -8
  28. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +10594 -730
  29. package/v2Containers/Whatsapp/tests/index.test.js +1 -1
  30. package/v2Containers/Whatsapp/tests/utils.test.js +23 -0
  31. package/v2Containers/mockdata.js +2208 -0
@@ -1,10 +1,125 @@
1
- // import React from 'react';
2
- // import { shallow } from 'enzyme';
1
+ import React from 'react';
2
+ import { shallowWithIntl } from '../../../helpers/intl-enzym-test-helpers';
3
3
 
4
- // import { Templates } from '../index';
4
+ import { Templates } from '../index';
5
+ import mockdata from '../../mockdata';
5
6
 
6
- describe('<Templates />', () => {
7
- it('Expect to have unit tests specified', () => {
8
- expect(true).toEqual(false);
7
+ const { Templates: TemplatesProp, getCreativesParamsOutput } = mockdata;
8
+
9
+ jest.mock("../../CreativesContainer", () => ({
10
+ __esModule: true,
11
+ default: (props) => <div className="creatives-container-mock" {...props}>CreativesContainer</div>,
12
+ }));
13
+
14
+
15
+ describe('Test Templates container', () => {
16
+ const getWeCrmAccounts = jest.fn();
17
+ const setChannelAccount = jest.fn();
18
+ const getAllTemplates = jest.fn();
19
+ let renderedComponent;
20
+
21
+ beforeEach(() => {
22
+ jest.clearAllMocks();
23
+ });
24
+
25
+ const renderFunction = (isFullMode) => {
26
+ renderedComponent = shallowWithIntl(
27
+ <Templates
28
+ route={{
29
+ name: 'whatsapp',
30
+ }}
31
+ Templates={TemplatesProp}
32
+ actions={{
33
+ getWeCrmAccounts,
34
+ setChannelAccount,
35
+ getAllTemplates,
36
+ }}
37
+ location={{
38
+ pathname: "/whatsapp",
39
+ query: {},
40
+ search: '',
41
+ }}
42
+ EmailCreate={{
43
+ duplicateTemplateInProgress: false,
44
+ }}
45
+ isFullMode={isFullMode}
46
+ />
47
+ );
48
+ };
49
+
50
+ it('Should render correct component for whatsapp channel', () => {
51
+ renderFunction();
52
+ expect(renderedComponent).toMatchSnapshot();
53
+
54
+ expect(getWeCrmAccounts).toHaveBeenCalledTimes(1);
55
+ expect(getWeCrmAccounts).toHaveBeenCalledWith('Whatsapp');
56
+ });
57
+
58
+
59
+ it('Should render temlates when whatsapp templates are passed', () => {
60
+ renderFunction();
61
+ renderedComponent.setProps({TemplatesList: TemplatesProp.templates});
62
+ expect(renderedComponent).toMatchSnapshot();
63
+ });
64
+
65
+
66
+ it('Should render illustration when no templates are passed', () => {
67
+ renderFunction();
68
+ renderedComponent.setProps({TemplatesList: []});
69
+ expect(renderedComponent).toMatchSnapshot();
70
+ });
71
+
72
+ it('Should render temlates when whatsapp templates are passed in full mode', () => {
73
+ renderFunction(true);
74
+ renderedComponent.setProps({TemplatesList: TemplatesProp.templates});
75
+ renderedComponent.setState({selectedWhatsappStatus: 'approved'});
76
+ expect(renderedComponent).toMatchSnapshot();
77
+ });
78
+
79
+ it('Test getCreatives params in edit mode', () => {
80
+ renderFunction();
81
+ renderedComponent.setProps({TemplatesList: TemplatesProp.templates});
82
+ renderedComponent.setState({routeParams: { pathname: '/edit'}});
83
+ expect(renderedComponent.instance().getCreativesParams()).toEqual(getCreativesParamsOutput);
84
+ });
85
+
86
+ const getFilterContainer = () => {
87
+ const FilterContainer = () =>
88
+ renderedComponent.find(".selected-whatsapp-filters").props().children;
89
+ return shallowWithIntl(<FilterContainer />);
90
+ };
91
+ it('Test removing single filter', () => {
92
+ renderFunction();
93
+ renderedComponent.setProps({TemplatesList: TemplatesProp.templates});
94
+ renderedComponent.setState({selectedWhatsappStatus: 'approved'});
95
+ //remove status filter
96
+
97
+ getFilterContainer().find('CapTag').props().onClose();
98
+ expect(renderedComponent).toMatchSnapshot();
99
+ });
100
+
101
+
102
+ it('Test removing all whatsapp filters', () => {
103
+ renderFunction();
104
+ renderedComponent.setProps({TemplatesList: TemplatesProp.templates});
105
+ renderedComponent.setState({selectedWhatsappStatus: 'approved'});
106
+ renderedComponent.setState({selectedWhatsappCategory: 'ALERT_UPDATE'});
107
+ expect(renderedComponent).toMatchSnapshot();
108
+
109
+ //remove all filters
110
+ getFilterContainer().find('CapLink').props().onClick();
111
+ expect(renderedComponent).toMatchSnapshot();
112
+ });
113
+
114
+ it('Test max templates exceeded', () => {
115
+ renderFunction(true);
116
+ renderedComponent.setProps({TemplatesList: [{ ...TemplatesProp.templates[0], totalCount: 260 }]});
117
+ expect(renderedComponent).toMatchSnapshot();
118
+ });
119
+
120
+ it('Test max templates warning', () => {
121
+ renderFunction(true);
122
+ renderedComponent.setProps({TemplatesList: [{ ...TemplatesProp.templates[0], totalCount: 248 }]});
123
+ expect(renderedComponent).toMatchSnapshot();
9
124
  });
10
125
  });
@@ -23,13 +23,12 @@ import Templates from '../Templates';
23
23
  import CallTask from '../CallTask';
24
24
  import Facebook from '../Facebook';
25
25
  import Viber from '../Viber';
26
- import Whatsapp from '../Whatsapp';
27
26
  import Line from '../Line/Container';
28
27
  import FTP from '../FTP';
29
28
  import Gallery from '../Assets/Gallery';
30
29
  import withStyles from '../../hoc/withStyles';
31
30
  import styles, { CapTabStyle } from './TemplatesV2.style';
32
- import { CREATIVES_UI_VIEW, LOYALTY} from '../App/constants';
31
+ import { CREATIVES_UI_VIEW, LOYALTY, WHATSAPP } from '../App/constants';
33
32
  import AccessForbidden from '../../v2Components/AccessForbidden';
34
33
  import { getObjFromQueryParams } from '../../utils/v2common';
35
34
 
@@ -37,6 +36,8 @@ const {CapCustomCardList} = CapCustomCard;
37
36
 
38
37
  const StyledCapTab = withStyles(CapTab, CapTabStyle);
39
38
 
39
+ const WHATSAPP_LOWERCASE = WHATSAPP.toLowerCase();
40
+
40
41
  export class TemplatesV2 extends React.Component { // eslint-disable-line react/prefer-stateless-function
41
42
  constructor(props) {
42
43
  super(props);
@@ -63,7 +64,7 @@ export class TemplatesV2 extends React.Component { // eslint-disable-line react/
63
64
  line: {content: <></>, tab: intl.formatMessage(messages.line), key: 'line'},
64
65
  viber: {content: <></>, tab: intl.formatMessage(messages.viber), key: 'viber'},
65
66
  facebook: {content: <div></div>, tab: intl.formatMessage(messages.facebook), key: 'facebook'},
66
- whatsapp: { content: <></>, tab: intl.formatMessage(messages.whatsapp), key: 'whatsapp' },
67
+ whatsapp: { content: <></>, tab: intl.formatMessage(messages.whatsapp), key: WHATSAPP_LOWERCASE },
67
68
  };
68
69
  let filteredPanes = Object.keys(defaultPanes)
69
70
  .filter((key) => !channelsToHide.includes(key)).reduce((obj = [], key) => {
@@ -81,7 +82,7 @@ export class TemplatesV2 extends React.Component { // eslint-disable-line react/
81
82
  filteredPanes.push({content: <></>, tab: intl.formatMessage(messages.FTP), key: 'ftp'});
82
83
  defaultChannel = 'FTP';
83
84
  }
84
- if (!enableNewChannels.includes('WHATSAPP')) {
85
+ if (!enableNewChannels.includes(WHATSAPP)) {
85
86
  filteredPanes.splice(7, 1);
86
87
  }
87
88
  }
@@ -129,9 +130,8 @@ export class TemplatesV2 extends React.Component { // eslint-disable-line react/
129
130
  componentDidMount() {
130
131
  const queryItems = getObjFromQueryParams(location.search);
131
132
 
132
- if(queryItems.channel === 'whatsapp') {
133
- console.log("reached whatsapp content");
134
- this.channelChange('whatsapp');
133
+ if (queryItems.channel === WHATSAPP_LOWERCASE) {
134
+ this.channelChange(WHATSAPP_LOWERCASE);
135
135
  }
136
136
  }
137
137
 
@@ -122,4 +122,10 @@ export const EMBEDDED = 'embedded';
122
122
  export const DEFAULT = 'default';
123
123
  export const FULL = 'full';
124
124
  export const ALL = 'all';
125
- export const LIBRARY = 'library';
125
+ export const LIBRARY = 'library';
126
+
127
+ export const WHATSAPP_MEDIA_TYPES = {
128
+ TEXT: 'TEXT',
129
+ IMAGE: 'IMAGE',
130
+ VIDEO: 'VIDEO',
131
+ };
@@ -48,6 +48,7 @@ import {
48
48
  FULL,
49
49
  ALL,
50
50
  LIBRARY,
51
+ WHATSAPP_MEDIA_TYPES,
51
52
  } from './constants';
52
53
  import { DATE_DISPLAY_FORMAT, TIME_DISPLAY_FORMAT } from '../App/constants';
53
54
  import messages from './messages';
@@ -353,11 +354,11 @@ export const Whatsapp = (props) => {
353
354
 
354
355
  const mediaRadioOptions = [
355
356
  {
356
- value: 'text',
357
+ value: WHATSAPP_MEDIA_TYPES.TEXT,
357
358
  label: formatMessage(messages.mediaTextMessage),
358
359
  },
359
360
  {
360
- value: 'image',
361
+ value: WHATSAPP_MEDIA_TYPES.IMAGE,
361
362
  label: (
362
363
  <CapTooltip title={formatMessage(messages.disabledMediaTooltip)}>
363
364
  {formatMessage(messages.mediaImage)}
@@ -366,7 +367,7 @@ export const Whatsapp = (props) => {
366
367
  disabled: true,
367
368
  },
368
369
  {
369
- value: 'video',
370
+ value: WHATSAPP_MEDIA_TYPES.VIDEO,
370
371
  label: (
371
372
  <CapTooltip title={formatMessage(messages.disabledMediaTooltip)}>
372
373
  {formatMessage(messages.mediaVideo)}
@@ -488,6 +489,19 @@ export const Whatsapp = (props) => {
488
489
  return errorMessage;
489
490
  };
490
491
 
492
+ const getPayloadContent = () => (
493
+ (isEditFlow && !isFullMode)
494
+ ? `${updatedSmsEditor.join('')} ${formatMessage(
495
+ messages.templateMessageUnsubscribeText,
496
+ )}`
497
+ : `${templateMessage}\n${formatMessage(
498
+ messages.modifiedUnsubscribeText,
499
+ {
500
+ value: `{{${addedVarCount + 1}}}`,
501
+ },
502
+ )}`
503
+ );
504
+
491
505
  const createPayload = () => ({
492
506
  name: templateName,
493
507
  versions: {
@@ -498,21 +512,12 @@ export const Whatsapp = (props) => {
498
512
  languages: [
499
513
  {
500
514
  language: 'en',
501
- content: isEditFlow
502
- ? `${updatedSmsEditor.join('')} ${formatMessage(
503
- messages.templateMessageUnsubscribeText,
504
- )}`
505
- : `${templateMessage}\n${formatMessage(
506
- messages.modifiedUnsubscribeText,
507
- {
508
- value: `{{${addedVarCount + 1}}}`,
509
- },
510
- )}`,
515
+ content: getPayloadContent(),
511
516
  },
512
517
  ],
513
- mediaType: 'TEXT',
514
- varMapped: varMap,
515
- templateEditor: tempMsgArray.join(''),
518
+ mediaType: WHATSAPP_MEDIA_TYPES.TEXT,
519
+ varMapped: !isFullMode ? varMap : {},
520
+ templateEditor: !isFullMode && tempMsgArray.join(''),
516
521
  accountId,
517
522
  accessToken,
518
523
  accountName,
@@ -562,7 +567,7 @@ export const Whatsapp = (props) => {
562
567
  value: createPayload(),
563
568
  _id: params?.id,
564
569
  validity: true,
565
- type: 'WHATSAPP',
570
+ type: WHATSAPP,
566
571
  });
567
572
  };
568
573
 
@@ -825,7 +830,7 @@ export const Whatsapp = (props) => {
825
830
  const { unsupportedTags = [] } = tagValidationResponse;
826
831
  let tagError = '';
827
832
  if (unsupportedTags.length > 0) {
828
- tagError = formatMessage(messages.unsupportedTagsValidationError, {
833
+ tagError = formatMessage(globalMessages.unsupportedTagsValidationError, {
829
834
  unsupportedTags,
830
835
  });
831
836
  }
@@ -1,19 +1,11 @@
1
1
  import { defineMessages } from 'react-intl';
2
2
  const prefix = `creatives.containersV2.Whatsapp`;
3
3
  export default defineMessages({
4
- templateNameLabel: {
5
- id: `${prefix}.templateNameLabel`,
6
- defaultMessage: 'Template name',
7
- },
8
4
  templateNameDesc: {
9
5
  id: `${prefix}.templateNameDesc`,
10
6
  defaultMessage:
11
7
  'Must be a unique name and can only contain lowercase alphanumeric characters and underscores.',
12
8
  },
13
- templateNamePlaceholder: {
14
- id: `${prefix}.templateNamePlaceholder`,
15
- defaultMessage: 'Enter template name',
16
- },
17
9
  templateNameTooltip: {
18
10
  id: `${prefix}.templateNameTooltip`,
19
11
  defaultMessage: `Tip : Use a name that helps WhatsApp's reviewer understand the purpose of your message, for example "order_delivery" rather than "template_1"`,