@capillarytech/creatives-library 9.0.70 → 9.0.71-alpha.sprint-cap-211543.18

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 (50) hide show
  1. package/constants/unified.js +0 -1
  2. package/package.json +1 -1
  3. package/utils/common.js +0 -6
  4. package/v2Components/CapTagListWithInput/__tests__/CapTagListWithInput.test.js +58 -1
  5. package/v2Components/CapTagListWithInput/index.js +64 -35
  6. package/v2Components/CapTagListWithInput/index.scss +9 -0
  7. package/v2Components/CommonTestAndPreview/UnifiedPreview/EmailPreviewContent.js +8 -0
  8. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +7 -0
  9. package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +1 -0
  10. package/v2Components/CommonTestAndPreview/actions.js +1 -1
  11. package/v2Components/CommonTestAndPreview/index.js +29 -13
  12. package/v2Components/CommonTestAndPreview/sagas.js +2 -1
  13. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/EmailPreviewContent.test.js +27 -0
  14. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +40 -0
  15. package/v2Components/CommonTestAndPreview/tests/index.test.js +95 -0
  16. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +24 -0
  17. package/v2Components/EmailMobilePreview/index.js +8 -1
  18. package/v2Components/EmailMobilePreview/index.scss +12 -3
  19. package/v2Components/EmailMobilePreview/tests/index.test.js +31 -0
  20. package/v2Components/EmailPreviewV2/_emailPreviewV2.scss +35 -5
  21. package/v2Components/EmailPreviewV2/index.js +18 -6
  22. package/v2Components/EmailPreviewV2/messages.js +4 -0
  23. package/v2Components/EmailPreviewV2/tests/index.test.js +43 -0
  24. package/v2Components/FormBuilder/Classic.js +119 -10
  25. package/v2Components/FormBuilder/_formBuilder.scss +21 -0
  26. package/v2Components/FormBuilder/messages.js +12 -0
  27. package/v2Containers/Cap/tests/index.test.js +1 -0
  28. package/v2Containers/CommunicationFlow/Tests/CommunicationFlow.test.js +2 -1
  29. package/v2Containers/CommunicationFlow/Tests/constants.test.js +4 -4
  30. package/v2Containers/CommunicationFlow/constants.js +1 -0
  31. package/v2Containers/CommunicationFlow/utils/Tests/mapCommDefinitionToStepData.test.js +2 -1
  32. package/v2Containers/CommunicationFlow/utils/mapCommDefinitionToStepData.js +1 -0
  33. package/v2Containers/CreativesContainer/index.js +9 -3
  34. package/v2Containers/CreativesContainer/tests/index.test.js +81 -0
  35. package/v2Containers/Email/index.js +31 -4
  36. package/v2Containers/Email/initialSchema.js +30 -0
  37. package/v2Containers/Email/messages.js +8 -0
  38. package/v2Containers/Email/tests/index.test.js +107 -0
  39. package/v2Containers/EmailWrapper/components/EmailHTMLEditor.js +172 -8
  40. package/v2Containers/EmailWrapper/components/__tests__/EmailHTMLEditor.test.js +264 -5
  41. package/v2Containers/EmailWrapper/components/_emailHTMLEditor.scss +29 -0
  42. package/v2Containers/EmailWrapper/constants.js +5 -0
  43. package/v2Containers/EmailWrapper/messages.js +24 -0
  44. package/v2Containers/TagList/index.js +7 -0
  45. package/v2Containers/TagList/tests/TagList.test.js +42 -0
  46. package/v2Containers/Templates/constants.js +1 -0
  47. package/v2Containers/Templates/index.js +31 -27
  48. package/v2Containers/Templates/messages.js +4 -0
  49. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +128 -4
  50. package/v2Containers/Templates/tests/archival.test.js +221 -0
@@ -813,7 +813,38 @@ exports[`Test Templates container Should render temlates when whatsapp templates
813
813
  <Component />
814
814
  <div
815
815
  className="template-listing-header-actions"
816
- />
816
+ >
817
+ <CapDropdownComponent
818
+ overlay={
819
+ <CapMenuComponent>
820
+ <withItemHOC
821
+ onClick={[Function]}
822
+ >
823
+ <FormattedMessage
824
+ defaultMessage="Archived templates"
825
+ id="creatives.containersV2.Templates.archivedTemplates"
826
+ values={Object {}}
827
+ />
828
+ </withItemHOC>
829
+ </CapMenuComponent>
830
+ }
831
+ placement="bottomRight"
832
+ trigger={
833
+ Array [
834
+ "click",
835
+ ]
836
+ }
837
+ >
838
+ <CapButton
839
+ className="template-listing-more-btn"
840
+ type="flat"
841
+ >
842
+ <CapIcon
843
+ type="more"
844
+ />
845
+ </CapButton>
846
+ </CapDropdownComponent>
847
+ </div>
817
848
  </div>
818
849
  <div>
819
850
  <div
@@ -1227,7 +1258,38 @@ exports[`Test Templates container Test max templates exceeded 1`] = `
1227
1258
  <Component />
1228
1259
  <div
1229
1260
  className="template-listing-header-actions"
1230
- />
1261
+ >
1262
+ <CapDropdownComponent
1263
+ overlay={
1264
+ <CapMenuComponent>
1265
+ <withItemHOC
1266
+ onClick={[Function]}
1267
+ >
1268
+ <FormattedMessage
1269
+ defaultMessage="Archived templates"
1270
+ id="creatives.containersV2.Templates.archivedTemplates"
1271
+ values={Object {}}
1272
+ />
1273
+ </withItemHOC>
1274
+ </CapMenuComponent>
1275
+ }
1276
+ placement="bottomRight"
1277
+ trigger={
1278
+ Array [
1279
+ "click",
1280
+ ]
1281
+ }
1282
+ >
1283
+ <CapButton
1284
+ className="template-listing-more-btn"
1285
+ type="flat"
1286
+ >
1287
+ <CapIcon
1288
+ type="more"
1289
+ />
1290
+ </CapButton>
1291
+ </CapDropdownComponent>
1292
+ </div>
1231
1293
  </div>
1232
1294
  <div>
1233
1295
  <div
@@ -1714,7 +1776,38 @@ exports[`Test Templates container Test max templates not exceeded 1`] = `
1714
1776
  <Component />
1715
1777
  <div
1716
1778
  className="template-listing-header-actions"
1717
- />
1779
+ >
1780
+ <CapDropdownComponent
1781
+ overlay={
1782
+ <CapMenuComponent>
1783
+ <withItemHOC
1784
+ onClick={[Function]}
1785
+ >
1786
+ <FormattedMessage
1787
+ defaultMessage="Archived templates"
1788
+ id="creatives.containersV2.Templates.archivedTemplates"
1789
+ values={Object {}}
1790
+ />
1791
+ </withItemHOC>
1792
+ </CapMenuComponent>
1793
+ }
1794
+ placement="bottomRight"
1795
+ trigger={
1796
+ Array [
1797
+ "click",
1798
+ ]
1799
+ }
1800
+ >
1801
+ <CapButton
1802
+ className="template-listing-more-btn"
1803
+ type="flat"
1804
+ >
1805
+ <CapIcon
1806
+ type="more"
1807
+ />
1808
+ </CapButton>
1809
+ </CapDropdownComponent>
1810
+ </div>
1718
1811
  </div>
1719
1812
  <div>
1720
1813
  <div
@@ -2201,7 +2294,38 @@ exports[`Test Templates container Test max templates warning 1`] = `
2201
2294
  <Component />
2202
2295
  <div
2203
2296
  className="template-listing-header-actions"
2204
- />
2297
+ >
2298
+ <CapDropdownComponent
2299
+ overlay={
2300
+ <CapMenuComponent>
2301
+ <withItemHOC
2302
+ onClick={[Function]}
2303
+ >
2304
+ <FormattedMessage
2305
+ defaultMessage="Archived templates"
2306
+ id="creatives.containersV2.Templates.archivedTemplates"
2307
+ values={Object {}}
2308
+ />
2309
+ </withItemHOC>
2310
+ </CapMenuComponent>
2311
+ }
2312
+ placement="bottomRight"
2313
+ trigger={
2314
+ Array [
2315
+ "click",
2316
+ ]
2317
+ }
2318
+ >
2319
+ <CapButton
2320
+ className="template-listing-more-btn"
2321
+ type="flat"
2322
+ >
2323
+ <CapIcon
2324
+ type="more"
2325
+ />
2326
+ </CapButton>
2327
+ </CapDropdownComponent>
2328
+ </div>
2205
2329
  </div>
2206
2330
  <div>
2207
2331
  <div
@@ -0,0 +1,221 @@
1
+ import React from 'react';
2
+ import { shallowWithIntl } from '../../../helpers/intl-enzym-test-helpers';
3
+ import { Templates } from '../index';
4
+ import mockdata from '../../mockdata';
5
+ import { DEFAULT_ARCHIVAL_LIMIT } from '../constants';
6
+ import { CREATIVE_CREATE, CREATIVE_DELETE, CREATIVE_EDIT } from '../../App/constants';
7
+
8
+ const { whatsappTemplates: TemplatesProp } = mockdata;
9
+
10
+ jest.mock('@capillarytech/cap-ui-library', () => ({
11
+ ...jest.requireActual('@capillarytech/cap-ui-library'),
12
+ CapNotification: { error: jest.fn(), success: jest.fn(), warning: jest.fn() },
13
+ }));
14
+
15
+ jest.mock('../../CreativesContainer', () => ({
16
+ __esModule: true,
17
+ default: () => null,
18
+ }));
19
+
20
+ const buildTemplateIds = count => Array.from({ length: count }, (_, index) => `template_${index}`);
21
+
22
+ // Walks a rendered element/plain-object tree (cards are never mounted) for a node by className.
23
+ const findByClassName = (node, className, seen = new Set()) => {
24
+ if (!node || typeof node !== 'object' || seen.has(node)) return null;
25
+ seen.add(node);
26
+ if (Array.isArray(node)) {
27
+ return node.reduce((found, child) => found || findByClassName(child, className, seen), null);
28
+ }
29
+ if (node.props && typeof node.props.className === 'string' && node.props.className.includes(className)) {
30
+ return node;
31
+ }
32
+ return Object.values(node.props || node).reduce(
33
+ (found, value) => found || findByClassName(value, className, seen),
34
+ null,
35
+ );
36
+ };
37
+
38
+ describe('Templates archival (enabled by default)', () => {
39
+ const actions = {
40
+ getWeCrmAccounts: jest.fn(),
41
+ setChannelAccount: jest.fn(),
42
+ getAllTemplates: jest.fn(),
43
+ getUserList: jest.fn(),
44
+ getSenderDetails: jest.fn(),
45
+ resetTemplate: jest.fn(),
46
+ setArchivedMode: jest.fn(),
47
+ clearTemplateSelection: jest.fn(),
48
+ toggleTemplateSelection: jest.fn(),
49
+ bulkArchiveTemplates: jest.fn(),
50
+ bulkUnarchiveTemplates: jest.fn(),
51
+ archiveTemplate: jest.fn(),
52
+ unarchiveTemplate: jest.fn(),
53
+ };
54
+ let renderedComponent;
55
+
56
+ const renderTemplates = ({ channel = 'email', isFullMode = true, templatesProps = {} } = {}) => {
57
+ renderedComponent = shallowWithIntl(
58
+ <Templates
59
+ route={{ name: channel }}
60
+ cap={{ user: { accessiblePermissions: [CREATIVE_CREATE, CREATIVE_EDIT, CREATIVE_DELETE] } }}
61
+ Templates={{ ...TemplatesProp, ...templatesProps }}
62
+ actions={actions}
63
+ location={{ pathname: `/${channel}`, query: {}, search: '' }}
64
+ EmailCreate={{ duplicateTemplateInProgress: false }}
65
+ isFullMode={isFullMode}
66
+ intl={{ formatMessage: ({ defaultMessage }) => defaultMessage }}
67
+ />,
68
+ );
69
+ return renderedComponent;
70
+ };
71
+
72
+ const getCardList = (templates, channel = 'email') =>
73
+ renderedComponent.instance().getTemplateDataForGrid({
74
+ templates,
75
+ handlers: { handlePreviewClick: jest.fn(), handleEditClick: jest.fn() },
76
+ filterContent: null,
77
+ channel,
78
+ isLoading: false,
79
+ isInitialLoading: false,
80
+ loadingTip: '',
81
+ previewTemplateId: null,
82
+ });
83
+
84
+ beforeEach(() => {
85
+ jest.clearAllMocks();
86
+ });
87
+
88
+ describe('bulk selection bar', () => {
89
+ const getBulkArchiveButton = () =>
90
+ renderedComponent
91
+ .find('.bulk-selection-bar')
92
+ .find('.archive-template-button');
93
+
94
+ it('renders without any feature flag once templates are selected', () => {
95
+ renderTemplates({ templatesProps: { selectedTemplateIds: buildTemplateIds(2) } });
96
+ expect(renderedComponent.find('.bulk-selection-bar')).toHaveLength(1);
97
+ expect(getBulkArchiveButton().prop('disabled')).toBe(false);
98
+ });
99
+
100
+ it('is not rendered when nothing is selected', () => {
101
+ renderTemplates({ templatesProps: { selectedTemplateIds: [] } });
102
+ expect(renderedComponent.find('.bulk-selection-bar')).toHaveLength(0);
103
+ });
104
+
105
+ it('is not rendered outside full mode', () => {
106
+ renderTemplates({ isFullMode: false, templatesProps: { selectedTemplateIds: buildTemplateIds(2) } });
107
+ expect(renderedComponent.find('.bulk-selection-bar')).toHaveLength(0);
108
+ });
109
+
110
+ it('keeps the action enabled at exactly the archival limit', () => {
111
+ renderTemplates({ templatesProps: { selectedTemplateIds: buildTemplateIds(DEFAULT_ARCHIVAL_LIMIT) } });
112
+ expect(getBulkArchiveButton().prop('disabled')).toBe(false);
113
+ });
114
+
115
+ it('disables the action and shows the limit message above the archival limit', () => {
116
+ renderTemplates({ templatesProps: { selectedTemplateIds: buildTemplateIds(DEFAULT_ARCHIVAL_LIMIT + 1) } });
117
+ expect(getBulkArchiveButton().prop('disabled')).toBe(true);
118
+ const tooltip = renderedComponent.find('.bulk-selection-bar').find('CapTooltip').first();
119
+ expect(tooltip.prop('title')).toContain('Archive limit exceeded');
120
+ expect(tooltip.prop('title')).toContain(String(DEFAULT_ARCHIVAL_LIMIT));
121
+ });
122
+
123
+ it('triggers bulk unarchive for the selection in archived mode', () => {
124
+ const selectedIds = buildTemplateIds(2);
125
+ renderTemplates({ templatesProps: { selectedTemplateIds: selectedIds, isArchivedMode: true } });
126
+ const handleBulkArchiveAction = jest
127
+ .spyOn(renderedComponent.instance(), 'handleBulkArchiveAction')
128
+ .mockImplementation(() => {});
129
+ getBulkArchiveButton().prop('onClick')();
130
+ expect(handleBulkArchiveAction).toHaveBeenCalledWith({ ids: selectedIds, count: 2, isUnarchive: true });
131
+ });
132
+ });
133
+
134
+ describe('handleBulkArchiveAction', () => {
135
+ it('opens the confirm modal and bulk archives the selected ids on confirm', () => {
136
+ renderTemplates();
137
+ const instance = renderedComponent.instance();
138
+ const showArchiveConfirm = jest.spyOn(instance, 'showArchiveConfirm').mockImplementation(() => {});
139
+ instance.handleBulkArchiveAction({ ids: ['a', 'b'], count: 2 });
140
+ expect(showArchiveConfirm).toHaveBeenCalledWith(expect.objectContaining({ count: 2, isUnarchive: false }));
141
+ showArchiveConfirm.mock.calls[0][0].onConfirm();
142
+ expect(actions.bulkArchiveTemplates).toHaveBeenCalledWith('Email', ['a', 'b'], expect.any(Function));
143
+ expect(actions.bulkUnarchiveTemplates).not.toHaveBeenCalled();
144
+ });
145
+
146
+ it('bulk unarchives when isUnarchive is set', () => {
147
+ renderTemplates();
148
+ const instance = renderedComponent.instance();
149
+ const showArchiveConfirm = jest.spyOn(instance, 'showArchiveConfirm').mockImplementation(() => {});
150
+ instance.handleBulkArchiveAction({ ids: ['a'], count: 1, isUnarchive: true });
151
+ showArchiveConfirm.mock.calls[0][0].onConfirm();
152
+ expect(actions.bulkUnarchiveTemplates).toHaveBeenCalledWith('Email', ['a'], expect.any(Function));
153
+ expect(actions.bulkArchiveTemplates).not.toHaveBeenCalled();
154
+ });
155
+ });
156
+
157
+ describe('single template card', () => {
158
+ const activeTemplate = { _id: 'tpl_1', name: 'Active template', versions: { base: {} } };
159
+ const archivedTemplate = { _id: 'tpl_2', name: 'Archived template', isArchived: true, versions: { base: {} } };
160
+
161
+ it('shows the archive menu action for an active template without any feature flag', () => {
162
+ renderTemplates();
163
+ const cardList = getCardList([activeTemplate]);
164
+ expect(findByClassName(cardList, 'archive-email')).not.toBeNull();
165
+ expect(findByClassName(cardList, 'unarchive-email')).toBeNull();
166
+ });
167
+
168
+ it('shows the unarchive menu action for an archived template', () => {
169
+ renderTemplates();
170
+ const cardList = getCardList([archivedTemplate]);
171
+ expect(findByClassName(cardList, 'unarchive-email')).not.toBeNull();
172
+ });
173
+
174
+ it('shows the archived tag and unarchive popover action for an archived template', () => {
175
+ renderTemplates({ channel: 'sms' });
176
+ const cardList = renderedComponent.instance().populateTemplatesList([archivedTemplate], false, false);
177
+ expect(findByClassName(cardList, 'archived-tag')).not.toBeNull();
178
+ expect(findByClassName(cardList, 'popover-archive-action')).not.toBeNull();
179
+ });
180
+
181
+ it('shows no archived tag for an active template', () => {
182
+ renderTemplates({ channel: 'sms' });
183
+ const cardList = renderedComponent.instance().populateTemplatesList([activeTemplate], false, false);
184
+ expect(findByClassName(cardList, 'archived-tag')).toBeNull();
185
+ expect(findByClassName(cardList, 'popover-archive-action')).not.toBeNull();
186
+ });
187
+
188
+ it('hides the archive actions outside full mode', () => {
189
+ renderTemplates({ isFullMode: false });
190
+ const cardList = getCardList([activeTemplate]);
191
+ expect(findByClassName(cardList, 'archive-email')).toBeNull();
192
+ });
193
+
194
+ it('archives a single template through the confirm modal', () => {
195
+ renderTemplates();
196
+ const instance = renderedComponent.instance();
197
+ const showArchiveConfirm = jest.spyOn(instance, 'showArchiveConfirm').mockImplementation(() => {});
198
+ instance.handleTemplateArchiveAction({ templateId: 'tpl_1', templateName: 'Active template' });
199
+ expect(showArchiveConfirm).toHaveBeenCalledTimes(1);
200
+ showArchiveConfirm.mock.calls[0][0].onConfirm();
201
+ expect(actions.archiveTemplate).toHaveBeenCalled();
202
+ });
203
+
204
+ it('unarchives a single template through the confirm modal', () => {
205
+ renderTemplates();
206
+ const instance = renderedComponent.instance();
207
+ const showArchiveConfirm = jest.spyOn(instance, 'showArchiveConfirm').mockImplementation(() => {});
208
+ instance.handleTemplateArchiveAction({ templateId: 'tpl_2', templateName: 'Archived template', isUnarchive: true });
209
+ showArchiveConfirm.mock.calls[0][0].onConfirm();
210
+ expect(actions.unarchiveTemplate).toHaveBeenCalled();
211
+ });
212
+ });
213
+
214
+ describe('isChannelArchiveEligible', () => {
215
+ it('does not allow archiving Zalo templates', () => {
216
+ renderTemplates();
217
+ expect(renderedComponent.instance().isChannelArchiveEligible('ZALO')).toBe(false);
218
+ expect(renderedComponent.instance().isChannelArchiveEligible('SMS')).toBe(true);
219
+ });
220
+ });
221
+ });