@capillarytech/creatives-library 9.1.7 → 9.1.8-alpha.sprint-cap-214249.38

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 (81) hide show
  1. package/constants/unified.js +0 -1
  2. package/index.js +0 -13
  3. package/package.json +1 -1
  4. package/services/getSchema.js +1 -4
  5. package/services/tests/getSchema.test.js +2 -2
  6. package/utils/common.js +0 -6
  7. package/utils/createMobilePushPayload.js +47 -33
  8. package/utils/tests/createMobilePushPayload.test.js +102 -8
  9. package/v2Components/CapMpushCTA/index.js +10 -9
  10. package/v2Components/CapMpushCTA/index.scss +29 -3
  11. package/v2Components/CapMpushCTA/tests/index.test.js +89 -0
  12. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +26 -13
  13. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
  14. package/v2Components/CommonTestAndPreview/constants.js +2 -0
  15. package/v2Components/CommonTestAndPreview/index.js +49 -11
  16. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +79 -5
  17. package/v2Components/CommonTestAndPreview/tests/index.test.js +86 -0
  18. package/v2Components/FormBuilder/Functional/tests/mpush.crossFlowParity.test.js +1 -1
  19. package/v2Components/FormBuilder/Functional/tests/mpush.shellEvents.test.js +1 -1
  20. package/v2Components/FormBuilder/Functional/tests/mpush.singlePlatform.test.js +1 -1
  21. package/v2Components/FormBuilder/tests/mpush.characterization.test.js +2 -2
  22. package/v2Components/TemplatePreview/_templatePreview.scss +12 -2
  23. package/v2Components/TemplatePreview/index.js +30 -17
  24. package/v2Components/TemplatePreview/tests/index.test.js +61 -0
  25. package/v2Containers/Cap/index.js +0 -3
  26. package/v2Containers/CreativesContainer/SlideBoxContent.js +70 -151
  27. package/v2Containers/CreativesContainer/index.js +3 -6
  28. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +29 -0
  29. package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
  30. package/v2Containers/MobilePushNew/components/MediaUploaders.js +207 -192
  31. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +116 -121
  32. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
  33. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +316 -72
  34. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +45 -16
  35. package/v2Containers/MobilePushNew/constants.js +5 -0
  36. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
  37. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +52 -0
  38. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +38 -1
  39. package/v2Containers/MobilePushNew/hooks/useUpload.js +29 -39
  40. package/v2Containers/MobilePushNew/index.js +453 -188
  41. package/v2Containers/MobilePushNew/index.scss +188 -4
  42. package/v2Containers/MobilePushNew/messages.js +86 -6
  43. package/v2Containers/MobilePushNew/tests/index.test.js +450 -1
  44. package/v2Containers/MobilePushNew/tests/utils.test.js +25 -0
  45. package/v2Containers/MobilePushNew/utils.js +8 -0
  46. package/v2Containers/Templates/_templates.scss +10 -2
  47. package/v2Containers/Templates/index.js +84 -90
  48. package/v2Containers/Templates/tests/index.test.js +68 -0
  49. package/v2Components/FormBuilder/Functional/tests/manual.typingPerf.test.js +0 -135
  50. package/v2Components/FormBuilder/Functional/tests/mpush.ctaFlows.parity.test.js +0 -320
  51. package/v2Components/FormBuilder/Functional/tests/mpush.editContainer.parity.test.js +0 -148
  52. package/v2Components/FormBuilder/Functional/tests/mpush.libraryValidity.parity.test.js +0 -152
  53. package/v2Containers/MobilePush/Create/_mobilePushCreate.scss +0 -70
  54. package/v2Containers/MobilePush/Create/actions.js +0 -52
  55. package/v2Containers/MobilePush/Create/constants.js +0 -26
  56. package/v2Containers/MobilePush/Create/index.js +0 -2149
  57. package/v2Containers/MobilePush/Create/messages.js +0 -349
  58. package/v2Containers/MobilePush/Create/reducer.js +0 -72
  59. package/v2Containers/MobilePush/Create/sagas.js +0 -79
  60. package/v2Containers/MobilePush/Create/selectors.js +0 -29
  61. package/v2Containers/MobilePush/Create/test/contentValidity.test.js +0 -154
  62. package/v2Containers/MobilePush/Create/test/saga.test.js +0 -19
  63. package/v2Containers/MobilePush/Create/test/stayOpenOnSave.test.js +0 -80
  64. package/v2Containers/MobilePush/Edit/_mobilePushCreate.scss +0 -65
  65. package/v2Containers/MobilePush/Edit/actions.js +0 -94
  66. package/v2Containers/MobilePush/Edit/constants.js +0 -37
  67. package/v2Containers/MobilePush/Edit/index.js +0 -2407
  68. package/v2Containers/MobilePush/Edit/messages.js +0 -341
  69. package/v2Containers/MobilePush/Edit/reducer.js +0 -113
  70. package/v2Containers/MobilePush/Edit/sagas.js +0 -113
  71. package/v2Containers/MobilePush/Edit/selectors.js +0 -33
  72. package/v2Containers/MobilePush/Edit/test/contentValidity.test.js +0 -149
  73. package/v2Containers/MobilePush/Edit/test/saga.test.js +0 -255
  74. package/v2Containers/MobilePush/Edit/test/stayOpenOnSave.test.js +0 -60
  75. package/v2Containers/MobilePush/commonMethods.js +0 -333
  76. package/v2Containers/MobilePush/eventsMap.js +0 -130
  77. package/v2Containers/MobilePush/tests/commonMethods.test.js +0 -401
  78. package/v2Containers/MobilepushWrapper/_mobilepushWrapper.scss +0 -22
  79. package/v2Containers/MobilepushWrapper/index.js +0 -178
  80. package/v2Containers/MobilepushWrapper/messages.js +0 -29
  81. /package/{v2Containers/MobilePush/initialSchema.js → v2Components/FormBuilder/Functional/tests/fixtures/mpushInitialSchema.js} +0 -0
@@ -1,320 +0,0 @@
1
- /**
2
- * MPUSH CTA flows parity — the REAL (unconnected) MobilePush Create container
3
- * over the REAL gated FormBuilder, driving the CTA surface end-to-end through
4
- * the DOM the way a user does:
5
- *
6
- * fill both platforms -> "Add action link to content" (add-pri-cta)
7
- * -> deeplink option with/without params | External Link radio switch
8
- * -> press Create (isGetFormData transition, full mode)
9
- *
10
- * Pins manual-QA fix #5: switching the link-type radio Deeplink <-> External
11
- * Link REPLACES the `cta-deeplink-select` schema row with `cta-deeplink-text`.
12
- * Classic's initialiseForm PRUNES formData keys that left the schema walk
13
- * (Classic.js:1889-1897); before reconcileFormState ported that prune, the
14
- * orphaned seeded-'' `cta-deeplink-select` failed validateMobilePush's empty
15
- * rule and the container toasted "Validation error / Validation failed for
16
- * android" on a form Classic saves.
17
- *
18
- * Outcome contract per flow: NO validation stop (onValidationFail), and the
19
- * save proceeds — createTemplate fires, or the single-platform confirm modal
20
- * opens (a legitimate Classic outcome when the iOS tab stayed empty).
21
- */
22
- import React from 'react';
23
- import '@testing-library/jest-dom';
24
- import _ from 'lodash';
25
- import { notification } from 'antd';
26
- import { Router } from 'react-router-dom';
27
- import { render, act, fireEvent } from '../../../../utils/test-utils';
28
- import history from '../../../../utils/history';
29
- import { response as mpushSchemaResponse } from '../../../../v2Containers/MobilePush/initialSchema';
30
- import { Create } from '../../../../v2Containers/MobilePush/Create';
31
-
32
- jest.mock('redux-auth-wrapper/history4/redirect', () => ({
33
- connectedRouterRedirect: jest.fn(() => (Component) => Component),
34
- }));
35
- jest.mock('../../../../services/api', () => ({
36
- ...jest.requireActual('../../../../services/api'),
37
- getUnsubscribeUrl: () => Promise.resolve({ response: { response: '' } }),
38
- }));
39
-
40
- // The gate is purely org-flag controlled — drive the flow via the flag reader.
41
- let mockMpushFlag = false;
42
- jest.mock('../../../../utils/common', () => ({
43
- ...jest.requireActual('../../../../utils/common'),
44
- hasNewFormBuilderEnabledForMpush: () => mockMpushFlag,
45
- }));
46
-
47
- const fullDefinition = () => _.cloneDeep(mpushSchemaResponse.metaEntities[0].definition);
48
-
49
- const intl = {
50
- formatMessage: (descriptor) => (descriptor && (descriptor.defaultMessage || descriptor.id)) || '',
51
- locale: 'en',
52
- };
53
-
54
- const DEEPLINKS = JSON.stringify([
55
- { name: 'Home Page', link: 'app://home', keys: ['user_id'] },
56
- { name: 'Offers Page', link: 'app://offers', keys: [] },
57
- ]);
58
-
59
- const selectedAccount = {
60
- id: 'acc-1',
61
- name: 'Acc',
62
- sourceTypeName: 'SOME_SDK',
63
- sourceAccountIdentifier: 'lic-1',
64
- configs: { android: '1', ios: '1', deeplink: DEEPLINKS },
65
- };
66
-
67
- const buildProps = (overrides = {}) => ({
68
- intl,
69
- params: { mode: 'text' },
70
- route: { name: 'create' },
71
- location: { pathname: '/mobilepush/create/text', query: { module: 'default' } },
72
- router: { push: jest.fn() },
73
- isFullMode: true,
74
- isGetFormData: false,
75
- isLoadingMetaEntities: false,
76
- metaEntities: {},
77
- Create: { createTemplateInProgress: false },
78
- Edit: {},
79
- Templates: { selectedWeChatAccount: selectedAccount },
80
- // Any missing action becomes a jest.fn on demand (the container calls several).
81
- actions: new Proxy({}, { get: (target, name) => {
82
- if (!target[name]) target[name] = jest.fn(); // eslint-disable-line no-param-reassign
83
- return target[name];
84
- } }),
85
- globalActions: {
86
- fetchSchemaForEntity: jest.fn(),
87
- addMessageToQueue: jest.fn(),
88
- setInjectedTags: jest.fn(),
89
- },
90
- showTemplateName: jest.fn(),
91
- getFormLibraryData: jest.fn(),
92
- onValidationFail: jest.fn(),
93
- showLiquidErrorInFooter: jest.fn(),
94
- onPersonalizationTokensChange: jest.fn(),
95
- injectedTags: {},
96
- defaultData: { 'template-name': 'cta_test_1' },
97
- ...overrides,
98
- });
99
-
100
- const setNativeValue = (el, value) => {
101
- const proto = Object.getPrototypeOf(el);
102
- const setter = Object.getOwnPropertyDescriptor(proto, 'value').set;
103
- setter.call(el, value);
104
- };
105
-
106
- const typeInto = (id, value) => {
107
- const el = document.getElementById(id);
108
- if (!el) throw new Error(`no #${id} in DOM`);
109
- setNativeValue(el, value);
110
- fireEvent.change(el, { target: { value } });
111
- fireEvent.blur(el);
112
- };
113
-
114
- const runCreateFlow = ({
115
- optionLabel = 'Offers Page', fillCustomValue = false, useCopy = false, iosCta = false,
116
- externalLink = false,
117
- } = {}) => {
118
- const props = buildProps();
119
- let containerRef = null;
120
- const ui = (p) => (
121
- <Router history={history}>
122
- <Create ref={(r) => { if (r) containerRef = r; }} {...p} />
123
- </Router>
124
- );
125
- const utils = render(ui(props));
126
- const meta = { layouts: [{ definition: fullDefinition() }], tags: { standard: [] } };
127
- act(() => {
128
- utils.rerender(ui({ ...props, metaEntities: meta }));
129
- });
130
-
131
- // 1. fill mandatory fields (template-name comes via defaultData in full mode).
132
- act(() => { typeInto('message-title', 'Hello title'); });
133
- act(() => { typeInto('message-editor', 'Hello body'); });
134
- const tabHeaders = () => Array.from(document.querySelectorAll('.ant-tabs-tab'));
135
- if (useCopy) {
136
- // the user's habitual step: switch to iOS, "copy content from Android"
137
- act(() => { fireEvent.click(tabHeaders()[1]); });
138
- const copyLink = document.getElementById('copy-android-content2')
139
- || document.getElementById('copy-android-content');
140
- if (!copyLink) throw new Error('no copy-android-content link found');
141
- act(() => { fireEvent.click(copyLink); });
142
- act(() => { fireEvent.click(tabHeaders()[0]); });
143
- } else {
144
- act(() => { fireEvent.click(tabHeaders()[1]); }); // switch to iOS
145
- act(() => { typeInto('message-title2', 'Hello ios title'); });
146
- act(() => { typeInto('message-editor2', 'Hello ios body'); });
147
- act(() => { fireEvent.click(tabHeaders()[0]); }); // back to Android
148
- }
149
-
150
- if (iosCta) {
151
- // run the whole CTA flow on the iOS pane instead (suffixed ids)
152
- act(() => { fireEvent.click(tabHeaders()[1]); });
153
- }
154
- const ctaCheckboxId = iosCta ? 'add-pri-cta-ios' : 'add-pri-cta';
155
- const selectId = iosCta ? 'cta-deeplink2-select' : 'cta-deeplink-select';
156
- const customValueId = iosCta
157
- ? 'custom-value-user_id-cta-deeplink2-select'
158
- : 'custom-value-user_id-cta-deeplink-select';
159
-
160
- // 2. click "Add action link to content" — the checkbox carries no DOM id in
161
- // either flow, so find it by label text inside the right platform pane.
162
- const pane = document.querySelectorAll('.ant-tabs-tabpane')[iosCta ? 1 : 0] || document;
163
- const label = Array.from(pane.querySelectorAll('label'))
164
- .find((l) => /action link/i.test(l.textContent || ''));
165
- const cb = (label && label.querySelector('input[type="checkbox"]'))
166
- || pane.querySelector('input[type="checkbox"]');
167
- if (!cb) throw new Error(`no ${ctaCheckboxId} checkbox found`);
168
- act(() => { fireEvent.click(cb); });
169
-
170
- // the deeplink dropdown must have been spliced in
171
- let selectHost = document.getElementById(selectId);
172
- const info = { selectRendered: Boolean(selectHost) };
173
-
174
- if (externalLink) {
175
- // switch the link-type radio to "External Link": the dropdown row must be
176
- // REPLACED by a text input (container onLinkTypeChange splice)
177
- const radios = Array.from(pane.querySelectorAll('input[type="radio"]'));
178
- const external = radios.find((rd) => rd.value === 'External Link');
179
- if (!external) throw new Error(`no External Link radio (found ${radios.map((rd) => rd.value)})`);
180
- act(() => { fireEvent.click(external); });
181
- selectHost = document.getElementById(selectId);
182
- info.selectStillRendered = Boolean(selectHost);
183
- const textId = iosCta ? 'cta-deeplink2-text' : 'cta-deeplink-text';
184
- info.externalInputRendered = Boolean(document.getElementById(textId));
185
- if (info.externalInputRendered) {
186
- act(() => { typeInto(textId, 'https://example.com/offer'); });
187
- }
188
- }
189
-
190
- // 3. open the CapSelect and choose the requested option
191
- if (selectHost && !externalLink) {
192
- const trigger = selectHost.querySelector('.ant-select-selector')
193
- || selectHost.closest('.ant-select')?.querySelector('.ant-select-selector')
194
- || selectHost;
195
- act(() => { fireEvent.mouseDown(trigger); });
196
- const options = Array.from(document.querySelectorAll('.ant-select-item-option'));
197
- const wanted = options.find((o) => o.textContent.includes(optionLabel));
198
- if (wanted) act(() => { fireEvent.click(wanted); });
199
- info.pickedOption = Boolean(wanted);
200
- }
201
-
202
- // For a deeplink with params, the containers splice in a custom-value input.
203
- const customInput = document.getElementById(customValueId);
204
- info.customInputRendered = Boolean(customInput);
205
- if (customInput && fillCustomValue) {
206
- act(() => { typeInto(customValueId, '42'); });
207
- }
208
-
209
- // 4. press Create: isGetFormData transition in full mode -> startValidation
210
- act(() => {
211
- utils.rerender(ui({ ...props, metaEntities: meta, isGetFormData: true }));
212
- });
213
-
214
- const result = {
215
- ...info,
216
- createCalled: props.actions.createTemplate.mock.calls.length,
217
- validationFailCalled: props.onValidationFail.mock.calls.length,
218
- modalShown: containerRef ? containerRef.state.showModal : null,
219
- errorTab0: containerRef
220
- ? Object.entries(containerRef.state.errorData?.[0] || {}).filter(([, v]) => v === true).map(([k]) => k)
221
- : null,
222
- };
223
- utils.unmount();
224
- return result;
225
- };
226
-
227
- // Success = the save flow proceeds: either createTemplate fired, or the
228
- // single-platform confirm modal opened. A validation STOP (onValidationFail)
229
- // is the bug class this suite pins.
230
- const expectSaveProceeds = (r) => {
231
- expect(r.validationFailCalled).toBe(0);
232
- expect(r.createCalled + (r.modalShown ? 1 : 0)).toBeGreaterThanOrEqual(1);
233
- };
234
-
235
- const expectDeeplinkPicked = (r) => {
236
- expect(r.selectRendered).toBe(true);
237
- expect(r.pickedOption).toBe(true);
238
- };
239
-
240
- describe.each([
241
- ['Classic', 'false'],
242
- ['Functional', 'true'],
243
- ])('CTA flows parity — %s', (flow, flagValue) => {
244
- beforeEach(() => {
245
- mockMpushFlag = flagValue === 'true';
246
- });
247
- afterEach(() => {
248
- mockMpushFlag = false;
249
- });
250
-
251
- it('deeplink option WITHOUT params: no extra input, save proceeds', () => {
252
- const r = runCreateFlow({ optionLabel: 'Offers Page' });
253
- expectDeeplinkPicked(r);
254
- expect(r.customInputRendered).toBe(false);
255
- expectSaveProceeds(r);
256
- });
257
-
258
- it('deeplink option WITH params: custom-value input renders, save proceeds', () => {
259
- const r = runCreateFlow({ optionLabel: 'Home Page', fillCustomValue: true });
260
- expectDeeplinkPicked(r);
261
- expect(r.customInputRendered).toBe(true);
262
- expectSaveProceeds(r);
263
- });
264
-
265
- it('copy-content flow + CTA: save proceeds', () => {
266
- const r = runCreateFlow({ optionLabel: 'Offers Page', useCopy: true });
267
- expectDeeplinkPicked(r);
268
- expectSaveProceeds(r);
269
- });
270
-
271
- it('External Link radio: dropdown replaced by text input, orphaned select key does not fail validation', () => {
272
- const r = runCreateFlow({ externalLink: true });
273
- expect(r.selectRendered).toBe(true);
274
- expect(r.selectStillRendered).toBe(false);
275
- expect(r.externalInputRendered).toBe(true);
276
- expectSaveProceeds(r);
277
- });
278
-
279
- // iOS-pane CTA runs only on the Functional flow: Classic's tab switching scans
280
- // the real DOM (Classic.js:2526-2551), which a jsdom tab-header click does not
281
- // drive, so its container-side splice targets the wrong pane in this harness
282
- // (artifact, not a product behavior).
283
- if (flow === 'Functional') {
284
- it('iOS-pane CTA (suffixed ids): save proceeds', () => {
285
- const r = runCreateFlow({ optionLabel: 'Offers Page', iosCta: true });
286
- expectDeeplinkPicked(r);
287
- expectSaveProceeds(r);
288
- });
289
- }
290
-
291
- // Copy with EMPTY source fields must warn ("Cannot copy empty field values."):
292
- // the container handler reads its own formData copy (Create/index.js:1456-1465),
293
- // seeded by the builder's init onChange push (Classic.js:1906-1911 -> 740-748).
294
- it('copy from Android with empty fields shows the cannot-copy warning', () => {
295
- const warnSpy = jest.spyOn(notification, 'warning').mockImplementation(() => {});
296
- try {
297
- const props = buildProps();
298
- const ui = (p) => (
299
- <Router history={history}>
300
- <Create {...p} />
301
- </Router>
302
- );
303
- const utils = render(ui(props));
304
- const meta = { layouts: [{ definition: fullDefinition() }], tags: { standard: [] } };
305
- act(() => {
306
- utils.rerender(ui({ ...props, metaEntities: meta }));
307
- });
308
- act(() => { fireEvent.click(document.querySelectorAll('.ant-tabs-tab')[1]); });
309
- const copyLink = document.getElementById('copy-android-content2')
310
- || document.getElementById('copy-android-content');
311
- if (!copyLink) throw new Error('no copy-android-content link found');
312
- act(() => { fireEvent.click(copyLink); });
313
- expect(warnSpy).toHaveBeenCalledTimes(1);
314
- expect(warnSpy.mock.calls[0][0].description).toBe('Cannot copy empty field values.');
315
- utils.unmount();
316
- } finally {
317
- warnSpy.mockRestore();
318
- }
319
- });
320
- });
@@ -1,148 +0,0 @@
1
- /**
2
- * MPUSH edit parity — the REAL (unconnected) MobilePush Edit container driving
3
- * the REAL gated FormBuilder, with prop transitions exactly like production:
4
- * mount (account selected, no metaEntities yet)
5
- * -> metaEntities arrive (fullSchema + schema set, Edit CWRP 227-249)
6
- * -> templateDetails arrive (handleEditSchemaOnPropsChange -> setEditState
7
- * -> getSchemaForFormData -> injectEvents -> formData/tabCount setStates)
8
- *
9
- * This pins the bug the synthetic shell-level harnesses could NOT see: the
10
- * container's internal setState cascade commits the shell BEFORE a prior
11
- * dispatch has rendered, so a shell-side reconcile computed from stateRef was
12
- * STALE and clobbered the just-hydrated template (fields rendered but empty).
13
- * Fixed by running reconciliation inside the reducer (reconcileSchema action)
14
- * and emitting background validity from the settled state.
15
- */
16
- import React from 'react';
17
- import '@testing-library/jest-dom';
18
- import _ from 'lodash';
19
- import { Router } from 'react-router-dom';
20
- import { render, act } from '../../../../utils/test-utils';
21
- import history from '../../../../utils/history';
22
- import { response as mpushSchemaResponse } from '../../../../v2Containers/MobilePush/initialSchema';
23
- import { Edit } from '../../../../v2Containers/MobilePush/Edit';
24
-
25
- jest.mock('redux-auth-wrapper/history4/redirect', () => ({
26
- connectedRouterRedirect: jest.fn(() => (Component) => Component),
27
- }));
28
- jest.mock('../../../../services/api', () => ({
29
- ...jest.requireActual('../../../../services/api'),
30
- getUnsubscribeUrl: () => Promise.resolve({ response: { response: '' } }),
31
- }));
32
-
33
- // The gate is purely org-flag controlled — drive the flow via the flag reader.
34
- let mockMpushFlag = false;
35
- jest.mock('../../../../utils/common', () => ({
36
- ...jest.requireActual('../../../../utils/common'),
37
- hasNewFormBuilderEnabledForMpush: () => mockMpushFlag,
38
- }));
39
-
40
- const fullDefinition = () => _.cloneDeep(mpushSchemaResponse.metaEntities[0].definition);
41
-
42
- const intl = {
43
- formatMessage: (descriptor) => (descriptor && (descriptor.defaultMessage || descriptor.id)) || '',
44
- locale: 'en',
45
- };
46
-
47
- const templateDetails = () => ({
48
- name: 'test_push_12',
49
- mode: 'text',
50
- definition: { mode: 'text' },
51
- versions: {
52
- base: {
53
- ANDROID: { title: 'Saved A title', message: 'Saved A body' },
54
- IOS: { title: 'Saved I title', message: 'Saved I body' },
55
- },
56
- },
57
- });
58
-
59
- const selectedAccount = {
60
- id: 'acc-1',
61
- name: 'Acc',
62
- configs: { android: '1', ios: '1', deeplink: '[]' },
63
- };
64
-
65
- const buildProps = (overrides = {}) => ({
66
- intl,
67
- params: { id: '123' },
68
- location: { pathname: '/mobilepush/edit/123', query: { module: 'default' } },
69
- router: { push: jest.fn() },
70
- isFullMode: true,
71
- isLoadingMetaEntities: false,
72
- metaEntities: {},
73
- templateDetails: null,
74
- Edit: { weCrmAccounts: [] },
75
- Create: {},
76
- Templates: { selectedWeChatAccount: selectedAccount },
77
- // Any missing action becomes a jest.fn on demand (the container calls several).
78
- actions: new Proxy({}, { get: (target, name) => {
79
- if (!target[name]) target[name] = jest.fn(); // eslint-disable-line no-param-reassign
80
- return target[name];
81
- } }),
82
- globalActions: {
83
- fetchSchemaForEntity: jest.fn(),
84
- addMessageToQueue: jest.fn(),
85
- setInjectedTags: jest.fn(),
86
- },
87
- showTemplateName: jest.fn(),
88
- getFormLibraryData: jest.fn(),
89
- onValidationFail: jest.fn(),
90
- showLiquidErrorInFooter: jest.fn(),
91
- onPersonalizationTokensChange: jest.fn(),
92
- injectedTags: {},
93
- ...overrides,
94
- });
95
-
96
- const read = () => {
97
- const editor = document.getElementById('message-editor');
98
- const title = document.getElementById('message-title');
99
- return {
100
- titleValue: title ? title.value : '(no #message-title in DOM)',
101
- editorValue: editor ? editor.value : '(no #message-editor in DOM)',
102
- };
103
- };
104
-
105
- const runEditContainer = () => {
106
- const props = buildProps();
107
- const ui = (p) => (
108
- <Router history={history}>
109
- <Edit {...p} />
110
- </Router>
111
- );
112
- const utils = render(ui(props));
113
- // metaEntities arrive (bundled schema)
114
- act(() => {
115
- utils.rerender(ui({ ...props, metaEntities: { layouts: [{ definition: fullDefinition() }], tags: { standard: [] } } }));
116
- });
117
- // template details arrive
118
- act(() => {
119
- utils.rerender(ui({
120
- ...props,
121
- metaEntities: { layouts: [{ definition: fullDefinition() }], tags: { standard: [] } },
122
- templateDetails: templateDetails(),
123
- }));
124
- });
125
- const result = read();
126
- utils.unmount();
127
- return result;
128
- };
129
-
130
- describe('SCRATCH v3: REAL Edit container over the gated FormBuilder', () => {
131
- afterEach(() => {
132
- mockMpushFlag = false;
133
- });
134
-
135
- it('Functional path (flag on) populates the fields', () => {
136
- mockMpushFlag = true;
137
- const r = runEditContainer();
138
- expect(r.titleValue).toBe('Saved A title');
139
- expect(r.editorValue).toBe('Saved A body');
140
- });
141
-
142
- it('Classic path (flag off) populates the fields', () => {
143
- mockMpushFlag = false;
144
- const r = runEditContainer();
145
- expect(r.titleValue).toBe('Saved A title');
146
- expect(r.editorValue).toBe('Saved A body');
147
- });
148
- });
@@ -1,152 +0,0 @@
1
- /**
2
- * Library/embedded-mode validity parity — the campaigns-host Done/Preview gates.
3
- * Pins that the container's isFormValid tracks typing (Classic re-validates each change
4
- * via the container round-trip, Classic.js:516-537; the Done click early-returns on
5
- * !isFormValid) and the onContentValidityChange({isContentEmpty}) footer signal.
6
- */
7
- import React from 'react';
8
- import '@testing-library/jest-dom';
9
- import _ from 'lodash';
10
- import { Router } from 'react-router-dom';
11
- import { render, act, fireEvent } from '../../../../utils/test-utils';
12
- import history from '../../../../utils/history';
13
- import { response as mpushSchemaResponse } from '../../../../v2Containers/MobilePush/initialSchema';
14
- import { Create } from '../../../../v2Containers/MobilePush/Create';
15
-
16
- jest.mock('redux-auth-wrapper/history4/redirect', () => ({
17
- connectedRouterRedirect: jest.fn(() => (Component) => Component),
18
- }));
19
- jest.mock('../../../../services/api', () => ({
20
- ...jest.requireActual('../../../../services/api'),
21
- getUnsubscribeUrl: () => Promise.resolve({ response: { response: '' } }),
22
- }));
23
-
24
- // The gate is purely org-flag controlled — drive the flow via the flag reader.
25
- let mockMpushFlag = false;
26
- jest.mock('../../../../utils/common', () => ({
27
- ...jest.requireActual('../../../../utils/common'),
28
- hasNewFormBuilderEnabledForMpush: () => mockMpushFlag,
29
- }));
30
-
31
- const fullDefinition = () => _.cloneDeep(mpushSchemaResponse.metaEntities[0].definition);
32
-
33
- const intl = {
34
- formatMessage: (d) => (d && (d.defaultMessage || d.id)) || '',
35
- locale: 'en',
36
- };
37
-
38
- const selectedAccount = {
39
- id: 'acc-1',
40
- name: 'Acc',
41
- sourceTypeName: 'SOME_SDK',
42
- sourceAccountIdentifier: 'lic-1',
43
- configs: { android: '1', ios: '1', deeplink: '[]' },
44
- };
45
-
46
- const buildProps = () => ({
47
- intl,
48
- params: { mode: 'text' },
49
- route: { name: 'create' },
50
- location: { pathname: '/mobilepush/create/text', query: { module: 'default', type: 'embedded' } },
51
- router: { push: jest.fn() },
52
- isFullMode: false,
53
- isGetFormData: false,
54
- isLoadingMetaEntities: false,
55
- metaEntities: {},
56
- Create: { createTemplateInProgress: false },
57
- Edit: {},
58
- Templates: { selectedWeChatAccount: selectedAccount },
59
- actions: new Proxy({}, { get: (t, n) => { if (!t[n]) t[n] = jest.fn(); return t[n]; } }), // eslint-disable-line no-param-reassign
60
- globalActions: {
61
- fetchSchemaForEntity: jest.fn(),
62
- addMessageToQueue: jest.fn(),
63
- setInjectedTags: jest.fn(),
64
- },
65
- getFormLibraryData: jest.fn(),
66
- onValidationFail: jest.fn(),
67
- showLiquidErrorInFooter: jest.fn(),
68
- onPersonalizationTokensChange: jest.fn(),
69
- onContentValidityChange: jest.fn(),
70
- getLiquidTags: jest.fn(),
71
- injectedTags: {},
72
- });
73
-
74
- const setNativeValue = (el, value) => {
75
- const proto = Object.getPrototypeOf(el);
76
- Object.getOwnPropertyDescriptor(proto, 'value').set.call(el, value);
77
- };
78
- const typeInto = (id, value) => {
79
- const el = document.getElementById(id);
80
- if (!el) throw new Error(`no #${id} in DOM`);
81
- setNativeValue(el, value);
82
- fireEvent.change(el, { target: { value } });
83
- fireEvent.blur(el);
84
- };
85
-
86
- describe.each([
87
- ['Classic', 'false'],
88
- ['Functional', 'true'],
89
- ])('library-mode validity parity — %s', (flow, flagValue) => {
90
- beforeEach(() => {
91
- mockMpushFlag = flagValue === 'true';
92
- jest.useFakeTimers();
93
- });
94
- afterEach(() => {
95
- jest.useRealTimers();
96
- mockMpushFlag = false;
97
- });
98
-
99
- it('isFormValid flips true after typing valid content (Done gate) and content-emptiness reports live', () => {
100
- let containerRef = null;
101
- const props = buildProps();
102
- const ui = (p) => (
103
- <Router history={history}>
104
- <Create ref={(r) => { if (r) containerRef = r; }} {...p} />
105
- </Router>
106
- );
107
- const utils = render(ui(props));
108
- const meta = { layouts: [{ definition: fullDefinition() }], tags: { standard: [] } };
109
- act(() => { utils.rerender(ui({ ...props, metaEntities: meta })); });
110
- act(() => { jest.runOnlyPendingTimers(); });
111
-
112
- // mount: empty form — invalid, content empty
113
- expect(containerRef.state.isFormValid).toBe(false);
114
- expect(props.onContentValidityChange).toHaveBeenCalledWith({ isContentEmpty: true });
115
-
116
- act(() => { typeInto('message-title', 'Hello title'); });
117
- act(() => { typeInto('message-editor', 'Hello body'); });
118
- act(() => { jest.advanceTimersByTime(1000); }); // flush debounced emissions
119
-
120
- // the Done gate must see the typed content: valid + non-empty
121
- expect(containerRef.state.isFormValid).toBe(true);
122
- const contentCalls = props.onContentValidityChange.mock.calls.map((c) => c[0]);
123
- expect(contentCalls[contentCalls.length - 1]).toEqual({ isContentEmpty: false });
124
-
125
- // user repro: image write-back through the REAL prop path (Create's CWRP copies
126
- // uploadedAssetData.metaInfo.public_url into the current tab, Create/index.js:167-172)
127
- // then CTA check/uncheck — the create flow must not adopt the hardcoded tabCount={2}
128
- // or the check scans the empty iOS tab.
129
- act(() => {
130
- utils.rerender(ui({
131
- ...props,
132
- metaEntities: meta,
133
- Create: { createTemplateInProgress: false, uploadedAssetData: { metaInfo: { public_url: 'blob:uploaded' } } },
134
- }));
135
- });
136
- act(() => { jest.advanceTimersByTime(1000); });
137
- expect(containerRef.state.formData[0].image).toBe('blob:uploaded'); // write-back landed
138
- const pane = document.querySelectorAll('.ant-tabs-tabpane')[0] || document;
139
- const label = Array.from(pane.querySelectorAll('label')).find((l) => /action link/i.test(l.textContent || ''));
140
- const cta = (label && label.querySelector('input[type="checkbox"]')) || pane.querySelector('input[type="checkbox"]');
141
- act(() => { fireEvent.click(cta); });
142
- act(() => { jest.advanceTimersByTime(1000); });
143
- act(() => { fireEvent.click(cta); });
144
- act(() => { jest.advanceTimersByTime(1000); });
145
-
146
- expect(containerRef.state.tabCount).toBe(1); // create flow never adopts the prop
147
- const finalCalls = props.onContentValidityChange.mock.calls.map((c) => c[0]);
148
- expect(finalCalls[finalCalls.length - 1]).toEqual({ isContentEmpty: false }); // buttons stay enabled
149
-
150
- utils.unmount();
151
- });
152
- });
@@ -1,70 +0,0 @@
1
- @import "~@capillarytech/cap-ui-library/styles/_variables.scss";
2
-
3
- .creatives-mobilepush-create {
4
- .mobile-push-row{
5
- margin-bottom: 16px;
6
- }
7
- .mobile-push-img button {
8
- top: 212px;
9
- }
10
- .image-container{
11
- height: 200px;
12
- border: solid 1px #C2C2C2;
13
- border-radius: 5px;
14
- .image-placeholder{
15
- line-height: 150px;
16
- }
17
- &.error{
18
- border-color: #ea213a;
19
- }
20
- }
21
- .ant-tabs-bar{
22
- margin-bottom: 0 !important;
23
- display: flex;
24
- align-items: center;
25
- flex-direction: row-reverse;
26
- justify-content: flex-end;
27
- }
28
- .ant-tabs-tabpane{
29
- padding: 16px 16px 16px 0;
30
- border: solid 1px #D6D6D6;
31
- }
32
- .ant-tabs-nav-list {
33
- gap: 0 !important;
34
- .ant-tabs-tab {
35
- .form-tab-header{
36
- padding: $CAP_SPACE_04 $CAP_SPACE_16;
37
- .unsupported-channel {
38
- .ant-tabs-nav & {
39
- display: none;
40
-
41
- }
42
- }
43
- }
44
- }
45
- }
46
- .tag-container{
47
- .ant-col{
48
- flex: 0 0 100%;
49
-
50
- button{
51
- float: right;
52
- top: 8px;
53
- z-index: 100;
54
- padding: unset !important;
55
- }
56
- }
57
-
58
- .ant-col:first-child{
59
- display: flex;
60
- align-items: center;
61
- justify-content: flex-end;
62
- }
63
- }
64
-
65
- .ant-checkbox-label {
66
- .inductive-text {
67
- padding-left: 0.286rem;
68
- }
69
- }
70
- }