@capillarytech/creatives-library 8.0.329 → 8.0.330

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 (122) hide show
  1. package/constants/unified.js +0 -14
  2. package/package.json +1 -1
  3. package/services/api.js +0 -17
  4. package/services/tests/api.test.js +0 -85
  5. package/utils/commonUtils.js +0 -10
  6. package/utils/tests/commonUtil.test.js +0 -169
  7. package/v2Components/CapTagList/index.js +0 -10
  8. package/v2Components/CommonTestAndPreview/CustomValuesEditor.js +49 -70
  9. package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +2 -8
  10. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +21 -207
  11. package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +0 -16
  12. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +10 -85
  13. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +0 -30
  14. package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +11 -79
  15. package/v2Components/CommonTestAndPreview/SendTestMessage.js +53 -87
  16. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -20
  17. package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +4 -133
  18. package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +34 -145
  19. package/v2Components/CommonTestAndPreview/actions.js +0 -10
  20. package/v2Components/CommonTestAndPreview/constants.js +1 -53
  21. package/v2Components/CommonTestAndPreview/index.js +168 -1006
  22. package/v2Components/CommonTestAndPreview/messages.js +3 -147
  23. package/v2Components/CommonTestAndPreview/reducer.js +0 -10
  24. package/v2Components/CommonTestAndPreview/sagas.js +6 -15
  25. package/v2Components/CommonTestAndPreview/tests/CustomValuesEditor.test.js +286 -328
  26. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +65 -231
  27. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +5 -118
  28. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +0 -341
  29. package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +24 -65
  30. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +1 -199
  31. package/v2Components/CommonTestAndPreview/tests/constants.test.js +1 -31
  32. package/v2Components/CommonTestAndPreview/tests/index.test.js +4 -168
  33. package/v2Components/CommonTestAndPreview/tests/reducer.test.js +0 -71
  34. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +2 -2
  35. package/v2Components/CommonTestAndPreview/tests/selectors.test.js +0 -17
  36. package/v2Components/FormBuilder/index.js +1 -7
  37. package/v2Components/TestAndPreviewSlidebox/index.js +1 -8
  38. package/v2Components/TestAndPreviewSlidebox/sagas.js +4 -11
  39. package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +1 -3
  40. package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -36
  41. package/v2Containers/CreativesContainer/SlideBoxFooter.js +1 -10
  42. package/v2Containers/CreativesContainer/SlideBoxHeader.js +4 -29
  43. package/v2Containers/CreativesContainer/constants.js +0 -9
  44. package/v2Containers/CreativesContainer/index.js +93 -286
  45. package/v2Containers/CreativesContainer/index.scss +1 -51
  46. package/v2Containers/CreativesContainer/tests/SlideBoxFooter.test.js +34 -78
  47. package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +16 -79
  48. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +0 -8
  49. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +98 -357
  50. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +10 -20
  51. package/v2Containers/CreativesContainer/tests/index.test.js +9 -71
  52. package/v2Containers/Rcs/constants.js +1 -34
  53. package/v2Containers/Rcs/index.js +884 -999
  54. package/v2Containers/Rcs/index.scss +6 -85
  55. package/v2Containers/Rcs/messages.js +1 -10
  56. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +2453 -41456
  57. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap +5 -0
  58. package/v2Containers/Rcs/tests/index.test.js +38 -41
  59. package/v2Containers/Rcs/tests/mockData.js +0 -38
  60. package/v2Containers/Rcs/tests/utils.test.js +1 -379
  61. package/v2Containers/Rcs/utils.js +10 -358
  62. package/v2Containers/Sms/Create/index.js +38 -100
  63. package/v2Containers/SmsTrai/Create/index.js +4 -9
  64. package/v2Containers/SmsTrai/Edit/constants.js +0 -2
  65. package/v2Containers/SmsTrai/Edit/index.js +128 -609
  66. package/v2Containers/SmsTrai/Edit/messages.js +4 -9
  67. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +2600 -4586
  68. package/v2Containers/SmsWrapper/index.js +8 -37
  69. package/v2Containers/TagList/index.js +0 -6
  70. package/v2Containers/Templates/_templates.scss +2 -63
  71. package/v2Containers/Templates/actions.js +0 -11
  72. package/v2Containers/Templates/constants.js +0 -2
  73. package/v2Containers/Templates/index.js +40 -90
  74. package/v2Containers/Templates/sagas.js +12 -57
  75. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1079 -1043
  76. package/v2Containers/Templates/tests/sagas.test.js +123 -193
  77. package/v2Containers/TemplatesV2/TemplatesV2.style.js +1 -72
  78. package/v2Containers/TemplatesV2/index.js +23 -86
  79. package/v2Containers/Whatsapp/index.js +20 -3
  80. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +4872 -5790
  81. package/utils/templateVarUtils.js +0 -172
  82. package/utils/tests/templateVarUtils.test.js +0 -160
  83. package/v2Components/CommonTestAndPreview/AddTestCustomer.js +0 -42
  84. package/v2Components/CommonTestAndPreview/CustomerCreationModal.js +0 -155
  85. package/v2Components/CommonTestAndPreview/ExistingCustomerModal.js +0 -93
  86. package/v2Components/CommonTestAndPreview/previewApiUtils.js +0 -59
  87. package/v2Components/CommonTestAndPreview/tests/AddTestCustomer.test.js +0 -66
  88. package/v2Components/CommonTestAndPreview/tests/CommonTestAndPreview.addTestCustomer.test.js +0 -648
  89. package/v2Components/CommonTestAndPreview/tests/CustomerCreationModal.test.js +0 -174
  90. package/v2Components/CommonTestAndPreview/tests/ExistingCustomerModal.test.js +0 -114
  91. package/v2Components/CommonTestAndPreview/tests/previewApiUtils.test.js +0 -67
  92. package/v2Components/SmsFallback/SmsFallbackLocalSelector.js +0 -87
  93. package/v2Components/SmsFallback/constants.js +0 -73
  94. package/v2Components/SmsFallback/index.js +0 -955
  95. package/v2Components/SmsFallback/index.scss +0 -265
  96. package/v2Components/SmsFallback/messages.js +0 -78
  97. package/v2Components/SmsFallback/smsFallbackUtils.js +0 -107
  98. package/v2Components/SmsFallback/tests/SmsFallbackLocalSelector.test.js +0 -50
  99. package/v2Components/SmsFallback/tests/rcsSmsFallback.acceptance.test.js +0 -147
  100. package/v2Components/SmsFallback/tests/smsFallbackHandlers.test.js +0 -304
  101. package/v2Components/SmsFallback/tests/smsFallbackUi.test.js +0 -197
  102. package/v2Components/SmsFallback/tests/smsFallbackUtils.test.js +0 -261
  103. package/v2Components/SmsFallback/tests/useLocalTemplateList.test.js +0 -422
  104. package/v2Components/SmsFallback/useLocalTemplateList.js +0 -92
  105. package/v2Components/VarSegmentMessageEditor/constants.js +0 -2
  106. package/v2Components/VarSegmentMessageEditor/index.js +0 -125
  107. package/v2Components/VarSegmentMessageEditor/index.scss +0 -46
  108. package/v2Containers/CreativesContainer/CreativesSlideBoxWrapper.js +0 -43
  109. package/v2Containers/CreativesContainer/embeddedSlideboxUtils.js +0 -67
  110. package/v2Containers/CreativesContainer/tests/SlideBoxContent.localTemplates.test.js +0 -90
  111. package/v2Containers/CreativesContainer/tests/embeddedSlideboxUtils.test.js +0 -258
  112. package/v2Containers/CreativesContainer/tests/useLocalTemplatesProp.test.js +0 -125
  113. package/v2Containers/Rcs/rcsLibraryHydrationUtils.js +0 -205
  114. package/v2Containers/Rcs/tests/rcsLibraryHydrationUtils.test.js +0 -251
  115. package/v2Containers/Sms/smsFormDataHelpers.js +0 -67
  116. package/v2Containers/Sms/tests/smsFormDataHelpers.test.js +0 -253
  117. package/v2Containers/SmsTrai/Edit/index.scss +0 -121
  118. package/v2Containers/Templates/TemplatesActionBar.js +0 -101
  119. package/v2Containers/Templates/tests/TemplatesActionBar.test.js +0 -120
  120. package/v2Containers/Templates/tests/smsTemplatesListApi.test.js +0 -180
  121. package/v2Containers/Templates/utils/smsTemplatesListApi.js +0 -79
  122. package/v2Containers/TemplatesV2/tests/TemplatesV2.localTemplates.test.js +0 -131
@@ -1,101 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import CapInput from '@capillarytech/cap-ui-library/CapInput';
4
- import CapButton from '@capillarytech/cap-ui-library/CapButton';
5
-
6
- /**
7
- * Reusable action bar for template pickers.
8
- * Layout and spacing live in `_templates.scss` (`.action-container`, `.action-container__toolbar-row`).
9
- * Default search field width: `.action-container__toolbar-row .search-text` (13.125rem).
10
- * Pass `searchInputClassName` / `searchInputStyle` to override (defaults match Templates list: 210px per master).
11
- */
12
- const TemplatesActionBar = ({
13
- searchValue,
14
- onSearchChange,
15
- onSearch,
16
- onClear,
17
- searchPlaceholder,
18
- searchInputClassName,
19
- searchInputStyle,
20
- ctaLabel,
21
- onCtaClick,
22
- ctaDisabled,
23
- ctaClassName,
24
- ctaNode,
25
- children,
26
- showCta = true,
27
- }) => (
28
- <div className="action-container">
29
- <div className="action-container__toolbar-row">
30
- {searchPlaceholder && (
31
- <CapInput.Search
32
- className={['search-text', searchInputClassName].filter(Boolean).join(' ')}
33
- placeholder={searchPlaceholder}
34
- value={searchValue}
35
- onChange={onSearchChange}
36
- /* antd `Input` (used by CapInput.Search) has no `onSearch`; only `Input.Search` does. */
37
- onPressEnter={(e) => {
38
- if (onSearch) {
39
- const v = e?.target && 'value' in e.target ? e.target.value : searchValue;
40
- onSearch(v);
41
- }
42
- }}
43
- onSearch={onSearch}
44
- onClear={onClear}
45
- onScroll={(e) => e.stopPropagation()}
46
- />
47
- )}
48
- {children}
49
- </div>
50
- {showCta && (
51
- <div>
52
- {ctaNode || (
53
- <CapButton
54
- className={ctaClassName}
55
- type="primary"
56
- disabled={ctaDisabled}
57
- onClick={onCtaClick}
58
- >
59
- {ctaLabel}
60
- </CapButton>
61
- )}
62
- </div>
63
- )}
64
- </div>
65
- );
66
-
67
- TemplatesActionBar.propTypes = {
68
- searchValue: PropTypes.string,
69
- onSearchChange: PropTypes.func,
70
- onSearch: PropTypes.func,
71
- onClear: PropTypes.func,
72
- searchPlaceholder: PropTypes.string,
73
- searchInputClassName: PropTypes.string,
74
- searchInputStyle: PropTypes.object,
75
- ctaLabel: PropTypes.node,
76
- onCtaClick: PropTypes.func,
77
- ctaDisabled: PropTypes.bool,
78
- ctaClassName: PropTypes.string,
79
- ctaNode: PropTypes.node,
80
- children: PropTypes.node,
81
- showCta: PropTypes.bool,
82
- };
83
-
84
- TemplatesActionBar.defaultProps = {
85
- searchValue: '',
86
- onSearchChange: () => {},
87
- onSearch: () => {},
88
- onClear: () => {},
89
- searchPlaceholder: '',
90
- searchInputClassName: '',
91
- searchInputStyle: { width: '210px' },
92
- ctaLabel: null,
93
- onCtaClick: () => {},
94
- ctaDisabled: false,
95
- ctaClassName: '',
96
- ctaNode: null,
97
- children: null,
98
- };
99
-
100
- export default TemplatesActionBar;
101
-
@@ -1,120 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- import React from 'react';
5
- import { render, screen, fireEvent } from '@testing-library/react';
6
- import '@testing-library/jest-dom';
7
- import TemplatesActionBar from '../TemplatesActionBar';
8
-
9
- jest.mock('@capillarytech/cap-ui-library/CapInput', () => {
10
- const React = require('react');
11
- function Search(props) {
12
- return React.createElement('input', {
13
- 'data-testid': 'cap-input-search',
14
- value: props?.value,
15
- placeholder: props?.placeholder,
16
- onChange: props?.onChange,
17
- onKeyDown: (e) => {
18
- if (e.key === 'Enter' && props.onPressEnter) {
19
- props.onPressEnter(e);
20
- }
21
- },
22
- });
23
- }
24
- function CapInput() {
25
- return null;
26
- }
27
- CapInput.Search = Search;
28
- return { __esModule: true, default: CapInput };
29
- });
30
-
31
- jest.mock('@capillarytech/cap-ui-library/CapButton', () => {
32
- const React = require('react');
33
- return function CapButton(props) {
34
- return React.createElement('button', {
35
- type: 'button',
36
- 'data-testid': 'cta',
37
- onClick: props?.onClick,
38
- disabled: props?.disabled,
39
- }, props?.children);
40
- };
41
- });
42
-
43
- describe('TemplatesActionBar', () => {
44
- it('renders search when searchPlaceholder is set', () => {
45
- render(
46
- <TemplatesActionBar
47
- searchPlaceholder="Find templates"
48
- searchValue="hi"
49
- ctaLabel="Create"
50
- />,
51
- );
52
- expect(screen.getByTestId('cap-input-search')).toHaveAttribute('placeholder', 'Find templates');
53
- });
54
-
55
- it('omits search when searchPlaceholder is empty', () => {
56
- const { container } = render(
57
- <TemplatesActionBar searchPlaceholder="" ctaLabel="Go" />,
58
- );
59
- expect(container.querySelector('[data-testid="cap-input-search"]')).toBeNull();
60
- });
61
-
62
- it('fires onSearchChange and onCtaClick', () => {
63
- const onSearchChange = jest.fn();
64
- const onCtaClick = jest.fn();
65
- render(
66
- <TemplatesActionBar
67
- searchPlaceholder="S"
68
- onSearchChange={onSearchChange}
69
- ctaLabel="New"
70
- onCtaClick={onCtaClick}
71
- />,
72
- );
73
- fireEvent.change(screen.getByTestId('cap-input-search'), { target: { value: 'x' } });
74
- fireEvent.click(screen.getByTestId('cta'));
75
- expect(onSearchChange).toHaveBeenCalled();
76
- expect(onCtaClick).toHaveBeenCalled();
77
- });
78
-
79
- it('fires onSearch when Enter is pressed (antd Input has no native onSearch)', () => {
80
- const onSearch = jest.fn();
81
- render(
82
- <TemplatesActionBar
83
- searchPlaceholder="S"
84
- searchValue="query"
85
- onSearch={onSearch}
86
- ctaLabel="New"
87
- />,
88
- );
89
- const input = screen.getByTestId('cap-input-search');
90
- fireEvent.keyDown(input, { key: 'Enter', code: 'Enter' });
91
- expect(onSearch).toHaveBeenCalledWith('query');
92
- });
93
-
94
- it('renders ctaNode instead of default button when provided', () => {
95
- render(
96
- <TemplatesActionBar
97
- searchPlaceholder="S"
98
- ctaNode={<span data-testid="custom-cta">Custom</span>}
99
- />,
100
- );
101
- expect(screen.getByTestId('custom-cta')).toBeInTheDocument();
102
- expect(screen.queryByTestId('cta')).toBeNull();
103
- });
104
-
105
- it('hides CTA area when showCta is false', () => {
106
- const { container } = render(
107
- <TemplatesActionBar searchPlaceholder="S" showCta={false} ctaLabel="X" />,
108
- );
109
- expect(container.querySelector('[data-testid="cta"]')).toBeNull();
110
- });
111
-
112
- it('renders children in toolbar row', () => {
113
- render(
114
- <TemplatesActionBar searchPlaceholder="S" ctaLabel="C">
115
- <span data-testid="child">extra</span>
116
- </TemplatesActionBar>,
117
- );
118
- expect(screen.getByTestId('child')).toBeInTheDocument();
119
- });
120
- });
@@ -1,180 +0,0 @@
1
- import * as Api from '../../../services/api';
2
- import { isTraiDLTEnable } from '../../../utils/common';
3
-
4
- jest.mock('../../../services/api', () => ({
5
- getAllTemplates: jest.fn(),
6
- }));
7
-
8
- jest.mock('../../../utils/common', () => ({
9
- isTraiDLTEnable: jest.fn(),
10
- }));
11
-
12
- import {
13
- buildSmsTemplatesListQueryParams,
14
- fetchSmsTemplatesFromQuery,
15
- fetchSmsTemplatesListPage,
16
- SMS_TEMPLATES_LIST_SORT_MOST_RECENT,
17
- } from '../utils/smsTemplatesListApi';
18
-
19
- describe('smsTemplatesListApi', () => {
20
- beforeEach(() => {
21
- jest.clearAllMocks();
22
- });
23
-
24
- describe('buildSmsTemplatesListQueryParams', () => {
25
- it('includes traiEnable when TRAI DLT is enabled', () => {
26
- isTraiDLTEnable.mockReturnValue(true);
27
- const q = buildSmsTemplatesListQueryParams({
28
- page: 1,
29
- perPage: 25,
30
- name: 'x',
31
- sortBy: SMS_TEMPLATES_LIST_SORT_MOST_RECENT,
32
- isFullMode: true,
33
- smsRegister: {},
34
- });
35
- expect(q).toEqual({
36
- page: 1,
37
- perPage: 25,
38
- sortBy: SMS_TEMPLATES_LIST_SORT_MOST_RECENT,
39
- name: 'x',
40
- traiEnable: true,
41
- });
42
- });
43
-
44
- it('omits traiEnable when TRAI DLT is disabled', () => {
45
- isTraiDLTEnable.mockReturnValue(false);
46
- const q = buildSmsTemplatesListQueryParams({
47
- page: 2,
48
- perPage: 10,
49
- isFullMode: false,
50
- smsRegister: null,
51
- });
52
- expect(q.traiEnable).toBeUndefined();
53
- expect(q.name).toBe('');
54
- expect(q.sortBy).toBe(SMS_TEMPLATES_LIST_SORT_MOST_RECENT);
55
- });
56
- });
57
-
58
- describe('fetchSmsTemplatesFromQuery', () => {
59
- it('returns channelTemplates, weCRMTemplate, and raw; maps intl copy on names', async () => {
60
- Api.getAllTemplates.mockResolvedValue({
61
- response: {
62
- templates: [{ name: 'Copy of A', _id: '1' }],
63
- unMapped: { u: 1 },
64
- totalCount: 5,
65
- },
66
- });
67
-
68
- const out = await fetchSmsTemplatesFromQuery(
69
- { page: 1, perPage: 25 },
70
- 'Kopie',
71
- );
72
-
73
- expect(Api.getAllTemplates).toHaveBeenCalledWith({
74
- channel: 'Sms',
75
- queryParams: { page: 1, perPage: 25 },
76
- });
77
- expect(out.weCRMTemplate).toEqual({ u: 1 });
78
- expect(out.raw.response.templates[0].name).toBe('Copy of A');
79
- expect(out.channelTemplates.templates[0].name).toBe('Kopie A');
80
- expect(out.channelTemplates.totalCount).toBe(5);
81
- });
82
-
83
- it('skips name mapping when intlCopyOf is empty', async () => {
84
- Api.getAllTemplates.mockResolvedValue({
85
- response: {
86
- templates: [{ name: 'Copy of A' }],
87
- },
88
- });
89
- const out = await fetchSmsTemplatesFromQuery({ page: 1 }, '');
90
- expect(out.channelTemplates.templates[0].name).toBe('Copy of A');
91
- });
92
-
93
- it('handles missing response.templates', async () => {
94
- Api.getAllTemplates.mockResolvedValue({ response: {} });
95
- const out = await fetchSmsTemplatesFromQuery({}, '');
96
- expect(out.channelTemplates.templates).toEqual([]);
97
- });
98
-
99
- it('uses empty response when raw.response is missing', async () => {
100
- Api.getAllTemplates.mockResolvedValue({});
101
- const out = await fetchSmsTemplatesFromQuery({}, '');
102
- expect(out.channelTemplates.templates).toEqual([]);
103
- expect(out.weCRMTemplate).toBeUndefined();
104
- });
105
-
106
- it('does not map names when intlCopyOf is set but templates list is empty', async () => {
107
- Api.getAllTemplates.mockResolvedValue({
108
- response: { templates: [] },
109
- });
110
- const out = await fetchSmsTemplatesFromQuery({ page: 1 }, 'X');
111
- expect(out.channelTemplates.templates).toEqual([]);
112
- });
113
-
114
- it('uses empty string when template name is missing during intl mapping', async () => {
115
- Api.getAllTemplates.mockResolvedValue({
116
- response: {
117
- templates: [{ _id: 'n', name: undefined }],
118
- },
119
- });
120
- const out = await fetchSmsTemplatesFromQuery({ page: 1 }, 'Lbl');
121
- expect(out.channelTemplates.templates[0].name).toBe('');
122
- });
123
- });
124
-
125
- describe('fetchSmsTemplatesListPage', () => {
126
- it('falls back to total when totalCount is absent', async () => {
127
- isTraiDLTEnable.mockReturnValue(false);
128
- Api.getAllTemplates.mockResolvedValue({
129
- response: {
130
- templates: [{ _id: 'a' }],
131
- total: 7,
132
- },
133
- });
134
-
135
- const page = await fetchSmsTemplatesListPage({
136
- page: 1,
137
- perPage: 25,
138
- name: '',
139
- sortBy: SMS_TEMPLATES_LIST_SORT_MOST_RECENT,
140
- isFullMode: true,
141
- smsRegister: {},
142
- intlCopyOf: '',
143
- });
144
-
145
- expect(page.templates).toEqual([{ _id: 'a' }]);
146
- expect(page.totalCount).toBe(7);
147
- });
148
-
149
- it('uses totalCount when set', async () => {
150
- isTraiDLTEnable.mockReturnValue(false);
151
- Api.getAllTemplates.mockResolvedValue({
152
- response: {
153
- templates: [],
154
- totalCount: 12,
155
- },
156
- });
157
- const page = await fetchSmsTemplatesListPage({
158
- page: 1,
159
- perPage: 25,
160
- isFullMode: false,
161
- smsRegister: {},
162
- });
163
- expect(page.totalCount).toBe(12);
164
- });
165
-
166
- it('normalizes total to 0 when missing counts', async () => {
167
- isTraiDLTEnable.mockReturnValue(false);
168
- Api.getAllTemplates.mockResolvedValue({
169
- response: { templates: [] },
170
- });
171
- const page = await fetchSmsTemplatesListPage({
172
- page: 1,
173
- perPage: 25,
174
- isFullMode: false,
175
- smsRegister: {},
176
- });
177
- expect(page.totalCount).toBe(0);
178
- });
179
- });
180
- });
@@ -1,79 +0,0 @@
1
- import get from 'lodash/get';
2
- import * as Api from '../../../services/api';
3
- import { COPY_OF } from '../../../constants/unified';
4
- import { isTraiDLTEnable } from '../../../utils/common';
5
-
6
- /** Matches Templates `getAllTemplates` default for SMS. */
7
- export const SMS_TEMPLATES_LIST_SORT_MOST_RECENT = 'Most Recent';
8
-
9
- /**
10
- * Same query shape as Redux `GET_ALL_TEMPLATES` for channel Sms (DLT vs non-DLT via traiEnable).
11
- */
12
- export function buildSmsTemplatesListQueryParams({
13
- page,
14
- perPage,
15
- name = '',
16
- sortBy = SMS_TEMPLATES_LIST_SORT_MOST_RECENT,
17
- isFullMode,
18
- smsRegister,
19
- }) {
20
- const traiDlt = isTraiDLTEnable(isFullMode, smsRegister);
21
- return {
22
- page,
23
- perPage,
24
- sortBy,
25
- name: name || '',
26
- ...(traiDlt ? { traiEnable: true } : {}),
27
- };
28
- }
29
-
30
- /**
31
- * SMS list for Redux saga: uses queryParams already built by Templates (incl. traiEnable).
32
- * Applies the same "Copy of" → intl label as the former inline saga logic.
33
- */
34
- export async function fetchSmsTemplatesFromQuery(queryParams, intlCopyOf = '') {
35
- const raw = await Api.getAllTemplates({ channel: 'Sms', queryParams });
36
- const response = raw.response || {};
37
- let templates = get(response, 'templates', []) || [];
38
- if (intlCopyOf && templates.length) {
39
- templates = templates.map((template) => ({
40
- ...template,
41
- name: (template.name || '').replace(new RegExp(COPY_OF, 'g'), intlCopyOf),
42
- }));
43
- }
44
- const channelTemplates = { ...response, templates };
45
- return {
46
- channelTemplates,
47
- weCRMTemplate: response.unMapped,
48
- raw,
49
- };
50
- }
51
-
52
- /**
53
- * SMS list for the RCS SMS fallback picker only.
54
- * Called from `useLocalTemplateList` in SmsFallback — keeps data in component state and pairs with
55
- * `localTemplatesConfig` / `useLocalTemplates` in TemplatesV2. Does **not** use GET_ALL_TEMPLATES saga.
56
- * Same HTTP call shape as `fetchSmsTemplatesFromQuery` (used by the main SMS GET_ALL_TEMPLATES saga).
57
- */
58
- export async function fetchSmsTemplatesListPage({
59
- page,
60
- perPage,
61
- name,
62
- sortBy,
63
- isFullMode,
64
- smsRegister,
65
- intlCopyOf = '',
66
- }) {
67
- const queryParams = buildSmsTemplatesListQueryParams({
68
- page,
69
- perPage,
70
- name,
71
- sortBy,
72
- isFullMode,
73
- smsRegister,
74
- });
75
- const { channelTemplates } = await fetchSmsTemplatesFromQuery(queryParams, intlCopyOf);
76
- const templates = channelTemplates.templates || [];
77
- const totalCount = get(channelTemplates, 'totalCount', get(channelTemplates, 'total', 0)) || 0;
78
- return { templates, totalCount };
79
- }
@@ -1,131 +0,0 @@
1
- /**
2
- * Embedded SMS template list: localTemplatesConfig + SMS-only channel visibility (RCS SMS fallback).
3
- */
4
- import React from 'react';
5
- import { injectIntl } from 'react-intl';
6
- import '@testing-library/jest-dom';
7
- import cloneDeep from 'lodash/cloneDeep';
8
- import { Provider } from 'react-redux';
9
- import { configureStore } from '@capillarytech/vulcan-react-sdk/utils';
10
- import history from '../../../utils/history';
11
- import { initialReducer } from '../../../initialReducer';
12
- import { render, screen } from '../../../utils/test-utils';
13
- import { TemplatesV2 } from '../index';
14
- import { Templates, authData, currentOrgDetails as currentOrgDetailsMock } from './mockData';
15
- import { CHANNELS_TO_HIDE_FOR_SMS_ONLY } from '../../../v2Components/SmsFallback/constants';
16
-
17
- const mockTemplates = jest.fn(() => <div data-testid="templates-mock">Templates</div>);
18
- jest.mock('v2Containers/Templates', () => ({
19
- __esModule: true,
20
- default: (props) => mockTemplates(props),
21
- }));
22
-
23
- jest.mock('../../../utils/authWrapper', () => ({
24
- UserIsAuthenticated: jest.fn((config) => config),
25
- }));
26
-
27
- const ComponentToRender = injectIntl(TemplatesV2);
28
- const renderComponent = (p) => {
29
- const store = configureStore({}, initialReducer, history);
30
- return render(
31
- <Provider store={store}>
32
- <ComponentToRender {...p} />
33
- </Provider>,
34
- );
35
- };
36
-
37
- describe('TemplatesV2 local SMS templates (embedded)', () => {
38
- const templateActions = {
39
- templateActions: jest.fn(),
40
- deleteTemplate: jest.fn(),
41
- getAccountsSettings: jest.fn(),
42
- getAllTemplates: jest.fn(),
43
- getCdnTransformationConfig: jest.fn(),
44
- getDefaultBeeTemplates: jest.fn(),
45
- getSenderDetails: jest.fn(),
46
- getTemplateDetails: jest.fn(),
47
- getUserList: jest.fn(),
48
- getWeCrmAccounts: jest.fn(),
49
- handleHtmlUpload: jest.fn(),
50
- handleZipUpload: jest.fn(),
51
- resetAccount: jest.fn(),
52
- resetTemplate: jest.fn(),
53
- resetTemplateData: jest.fn(),
54
- resetTemplateStoreData: jest.fn(),
55
- resetUploadData: jest.fn(),
56
- setBEETemplate: jest.fn(),
57
- setChannelAccount: jest.fn(),
58
- setEdmTemplate: jest.fn(),
59
- setFacebookAccount: jest.fn(),
60
- setViberAccount: jest.fn(),
61
- setWeChatAccount: jest.fn(),
62
- };
63
-
64
- const baseProps = {
65
- cap: {
66
- user: { accessiblePermissions: ['CREATIVES_UI_VIEW'] },
67
- },
68
- actions: { defaultAction: jest.fn(), getTemplates: jest.fn() },
69
- Templates,
70
- TemplatesList: Templates?.templates,
71
- authData,
72
- templateActions,
73
- isFullMode: false,
74
- className: 'embed-test',
75
- channel: 'sms',
76
- channelsToHide: CHANNELS_TO_HIDE_FOR_SMS_ONLY,
77
- channelsToDisable: [],
78
- onChannelChange: jest.fn(),
79
- enableNewChannels: [],
80
- /** Without JP_LOCALE_HIDE_FEATURE so SMS panes are not stripped to Email/Line/Gallery only */
81
- currentOrgDetails: {
82
- ...currentOrgDetailsMock,
83
- accessibleFeatures: (currentOrgDetailsMock.accessibleFeatures || []).filter(
84
- (f) => f !== 'JP_LOCALE_HIDE_FEATURE',
85
- ),
86
- },
87
- location: {
88
- pathname: 'v2',
89
- basename: '/creatives/ui/',
90
- query: {},
91
- },
92
- router: { push: jest.fn() },
93
- };
94
-
95
- beforeEach(() => {
96
- mockTemplates.mockClear();
97
- });
98
-
99
- it('adds local-sms container class and single-pane layout when only SMS is visible', () => {
100
- const p = cloneDeep(baseProps);
101
- p.localTemplatesConfig = {
102
- useLocalTemplates: true,
103
- localTemplates: [],
104
- localTemplatesLoading: false,
105
- };
106
- renderComponent(p);
107
-
108
- const wrapper = screen.getByTestId('cap-wrapper');
109
- expect(wrapper).toHaveClass('creatives-templates-container--local-sms');
110
- expect(document.querySelector('.templates-v2-local-sms-pane')).toBeTruthy();
111
- expect(mockTemplates).toHaveBeenCalled();
112
- });
113
-
114
- it('passes localTemplatesConfig into Templates for the SMS pane', () => {
115
- const localConfig = {
116
- useLocalTemplates: true,
117
- localTemplates: [{ _id: '1', name: 'A' }],
118
- localTemplatesLoading: false,
119
- };
120
- const p = cloneDeep(baseProps);
121
- p.localTemplatesConfig = localConfig;
122
- renderComponent(p);
123
-
124
- expect(mockTemplates).toHaveBeenCalled();
125
- const passed = mockTemplates.mock.calls.find(
126
- (call) => call[0] && call[0].localTemplatesConfig && call[0].localTemplatesConfig.useLocalTemplates,
127
- );
128
- expect(passed).toBeTruthy();
129
- expect(passed[0].localTemplatesConfig).toMatchObject(localConfig);
130
- });
131
- });