@capillarytech/creatives-library 9.1.7-alpha.sprint-bee-free-load-fix.34 → 9.1.7
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.
- package/AppRoot.js +7 -4
- package/package.json +1 -1
- package/services/api.js +6 -2
- package/services/tests/api.test.js +24 -0
- package/v2Containers/BeeEditor/index.js +17 -58
- package/v2Containers/BeeEditor/index.scss +0 -12
- package/v2Containers/BeeEditor/messages.js +0 -8
- package/v2Containers/BeePopupEditor/index.js +11 -28
- package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/ChannelSelectionStep.js +1 -0
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/DeliverySettingsSection.js +5 -1
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/Tests/DeliverySettingsSection.test.js +23 -4
- package/v2Containers/CreativesContainer/SlideBoxContent.js +1 -3
- package/v2Containers/Email/index.js +2 -2
- package/v2Containers/EmailWrapper/hooks/useEmailWrapper.js +23 -25
- package/utils/beePluginLoader.js +0 -73
- package/utils/tests/beePluginLoader.test.js +0 -135
- package/v2Containers/BeeEditor/test/index.test.js +0 -87
package/AppRoot.js
CHANGED
|
@@ -14,7 +14,6 @@ import { translationMessages } from './i18n';
|
|
|
14
14
|
import initialState from './initialState';
|
|
15
15
|
import pathConfig from './config/path';
|
|
16
16
|
import { isMFEMode } from './utils/mfeDetect';
|
|
17
|
-
import { loadBeePlugin } from './utils/beePluginLoader';
|
|
18
17
|
import { emitFirstPaintReadyIfNotDataLanding } from './utils/mfeFirstPaintReady';
|
|
19
18
|
import rebaseHistory from './utils/mfeHistory';
|
|
20
19
|
import { MFEEventBus } from '@capillarytech/cap-ui-utils';
|
|
@@ -87,10 +86,14 @@ const AppRoot = ({ basename: _basename = '/creatives/ui', history: hostHistory }
|
|
|
87
86
|
}
|
|
88
87
|
}, []);
|
|
89
88
|
|
|
90
|
-
//
|
|
89
|
+
// In MFE mode the HOST's index.html is served, not creatives' — so BeePlugin.js
|
|
90
|
+
// (declared in creatives/index.html) is never loaded. Inject it here so BeeEditor works.
|
|
91
91
|
useEffect(() => {
|
|
92
|
-
if (isMFEMode()) {
|
|
93
|
-
|
|
92
|
+
if (isMFEMode() && !window.BeePlugin && !document.querySelector('script[src*="BeePlugin.js"]')) {
|
|
93
|
+
const script = document.createElement('script');
|
|
94
|
+
script.src = 'https://app-rsrc.getbee.io/plugin/BeePlugin.js';
|
|
95
|
+
script.type = 'text/javascript';
|
|
96
|
+
document.head.appendChild(script);
|
|
94
97
|
}
|
|
95
98
|
}, []);
|
|
96
99
|
|
package/package.json
CHANGED
package/services/api.js
CHANGED
|
@@ -343,9 +343,13 @@ export const getTemplateDetails = async ({id, channel}) => {
|
|
|
343
343
|
return { ...compressedTemplatesData, response: decompressData};
|
|
344
344
|
};
|
|
345
345
|
|
|
346
|
-
|
|
346
|
+
// When `priority` is supplied (e.g. CapNotify passes 'HIGH'), fetch priority-scoped domains instead.
|
|
347
|
+
export const getDomainProperties = (channels, orgUnitId, priority) => {
|
|
347
348
|
const queryString = channels?.map((channel) => `channel=${channel?.toUpperCase()}`)?.join('&');
|
|
348
|
-
const
|
|
349
|
+
const path = priority
|
|
350
|
+
? `domainPropertiesByPriority?${queryString}&priority=${priority}`
|
|
351
|
+
: `domainProperties?${queryString}`;
|
|
352
|
+
const url = `${CAMPAIGNS_API_ORG_ENDPOINT}/meta/${path}`;
|
|
349
353
|
return request(url, getAPICallObject('GET', null, false, true, orgUnitId));
|
|
350
354
|
};
|
|
351
355
|
|
|
@@ -64,6 +64,30 @@ describe('getDomainProperties -- Test with valid responses', () => {
|
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
+
describe('getDomainProperties -- endpoint selection', () => {
|
|
68
|
+
const originalFetch = global.fetch;
|
|
69
|
+
beforeEach(() => {
|
|
70
|
+
global.fetch = jest.fn(() => Promise.resolve({ status: 200, json: () => Promise.resolve({}) }));
|
|
71
|
+
});
|
|
72
|
+
afterEach(() => {
|
|
73
|
+
global.fetch = originalFetch;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('calls domainProperties when no priority is given', () => {
|
|
77
|
+
getDomainProperties(['sms', 'EMAIL'], null);
|
|
78
|
+
const [url] = global.fetch.mock.calls[0];
|
|
79
|
+
expect(url).toContain('/meta/domainProperties?channel=SMS&channel=EMAIL&time=');
|
|
80
|
+
expect(url).not.toContain('domainPropertiesByPriority');
|
|
81
|
+
expect(url).not.toContain('priority=');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('calls domainPropertiesByPriority with the priority param when priority is given', () => {
|
|
85
|
+
getDomainProperties(['EMAIL'], null, 'HIGH');
|
|
86
|
+
const [url] = global.fetch.mock.calls[0];
|
|
87
|
+
expect(url).toContain('/meta/domainPropertiesByPriority?channel=EMAIL&priority=HIGH&time=');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
67
91
|
describe('getCdnTransformationConfigs -- Test with valid responses', () => {
|
|
68
92
|
it('Should return correct response', () =>
|
|
69
93
|
expect(getCdnTransformationConfig()).toEqual(Promise.resolve()));
|
|
@@ -19,10 +19,7 @@ import CapInput from "@capillarytech/cap-ui-library/CapInput";
|
|
|
19
19
|
import CapSelect from "@capillarytech/cap-ui-library/CapSelect";
|
|
20
20
|
import CapSpin from "@capillarytech/cap-ui-library/CapSpin";
|
|
21
21
|
import CapNotification from "@capillarytech/cap-ui-library/CapNotification";
|
|
22
|
-
import CapError from "@capillarytech/cap-ui-library/CapError";
|
|
23
|
-
import CapColumn from "@capillarytech/cap-ui-library/CapColumn";
|
|
24
22
|
import config from '../../config/app';
|
|
25
|
-
import { destroyBeeInstance, loadBeePlugin, startBeePlugin } from '../../utils/beePluginLoader';
|
|
26
23
|
import makeSelectBEE from './selectors';
|
|
27
24
|
import messages from './messages';
|
|
28
25
|
import * as beeActions from './actions';
|
|
@@ -78,9 +75,6 @@ function BeeEditor(props) {
|
|
|
78
75
|
const [rowMetaInfo, setRowMetaInfo] = useState({});
|
|
79
76
|
const [rowName, setRowName] = useState('');
|
|
80
77
|
const [rowCategory, setRowCategory] = useState('');
|
|
81
|
-
const [isBeePluginLoading, setIsBeePluginLoading] = useState(false);
|
|
82
|
-
const [hasBeePluginLoadError, setHasBeePluginLoadError] = useState(false);
|
|
83
|
-
const [beePluginLoadAttempt, setBeePluginLoadAttempt] = useState(0);
|
|
84
78
|
const beePluginInstanceRef = useRef(null);
|
|
85
79
|
const initializedBeeJsonRef = useRef(null); // Track which beeJson we've initialized for
|
|
86
80
|
const isInitializingRef = useRef(false); // Track if initialization is in progress
|
|
@@ -264,44 +258,23 @@ function BeeEditor(props) {
|
|
|
264
258
|
beePluginInstanceRef.current = null;
|
|
265
259
|
}
|
|
266
260
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return startBeePlugin(BeePlugin, {
|
|
277
|
-
tokenData: currentTokenData,
|
|
278
|
-
beeConfig,
|
|
279
|
-
getBeeJson: () => beeJson,
|
|
280
|
-
}).then((instance) => {
|
|
281
|
-
// Cleanup already ran (unmount or new beeJson), so this editor is obsolete
|
|
282
|
-
if (isEffectCancelled) {
|
|
283
|
-
destroyBeeInstance(instance);
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
beePluginInstance = instance;
|
|
287
|
-
beePluginInstanceRef.current = instance;
|
|
288
|
-
saveBeeInstance(beePluginInstance);
|
|
289
|
-
// Mark this beeJson as initialized and clear initialization flag
|
|
290
|
-
initializedBeeJsonRef.current = initializationKey;
|
|
291
|
-
isInitializingRef.current = false;
|
|
292
|
-
});
|
|
293
|
-
})
|
|
294
|
-
.catch((error) => {
|
|
295
|
-
if (isEffectCancelled) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
console.error('[BeeEditor] Error creating BEE plugin:', error);
|
|
299
|
-
setIsBeePluginLoading(false);
|
|
300
|
-
setHasBeePluginLoadError(true);
|
|
261
|
+
try {
|
|
262
|
+
window.BeePlugin.create(currentTokenData, beeConfig, (instance) => {
|
|
263
|
+
beePluginInstance = instance;
|
|
264
|
+
beePluginInstanceRef.current = instance;
|
|
265
|
+
const parseJson = typeof beeJson === 'string' ? JSON.parse(beeJson) : beeJson;
|
|
266
|
+
beePluginInstance.start(parseJson);
|
|
267
|
+
saveBeeInstance(beePluginInstance);
|
|
268
|
+
// Mark this beeJson as initialized and clear initialization flag
|
|
269
|
+
initializedBeeJsonRef.current = initializationKey;
|
|
301
270
|
isInitializingRef.current = false;
|
|
302
271
|
});
|
|
272
|
+
} catch (error) {
|
|
273
|
+
// Reset flag on error
|
|
274
|
+
console.error('[BeeEditor] Error creating BEE plugin:', error);
|
|
275
|
+
isInitializingRef.current = false;
|
|
276
|
+
}
|
|
303
277
|
return () => {
|
|
304
|
-
isEffectCancelled = true;
|
|
305
278
|
clearInterval(intervalTimer);
|
|
306
279
|
// Reset initialization flag on cleanup
|
|
307
280
|
isInitializingRef.current = false;
|
|
@@ -320,12 +293,7 @@ function BeeEditor(props) {
|
|
|
320
293
|
};
|
|
321
294
|
// Only depend on beeJson, uid, and id - not tokenData
|
|
322
295
|
// tokenData is accessed via ref to prevent re-initialization when it changes
|
|
323
|
-
}, [beeJson, uid, id
|
|
324
|
-
|
|
325
|
-
const onRetryBeePluginLoad = () => {
|
|
326
|
-
setBeePluginLoadAttempt((attempt) => attempt + 1);
|
|
327
|
-
};
|
|
328
|
-
|
|
296
|
+
}, [beeJson, uid, id]);
|
|
329
297
|
const callbackSaveRow = (status, errorMsg) => {
|
|
330
298
|
if (status === 'success') {
|
|
331
299
|
CapNotification.success({message: formatMessage(messages.rowCreationSuccessMgs), key: 'create-custom-row-success'});
|
|
@@ -399,17 +367,8 @@ function BeeEditor(props) {
|
|
|
399
367
|
</>
|
|
400
368
|
);
|
|
401
369
|
return (
|
|
402
|
-
<CapSpin spinning={saveRowRequest ||
|
|
403
|
-
{
|
|
404
|
-
<CapColumn className="bee-plugin-load-error">
|
|
405
|
-
<CapError type="error">{formatMessage(messages.beePluginLoadError)}</CapError>
|
|
406
|
-
<CapButton type="secondary" onClick={onRetryBeePluginLoad}>
|
|
407
|
-
{formatMessage(messages.retry)}
|
|
408
|
-
</CapButton>
|
|
409
|
-
</CapColumn>
|
|
410
|
-
) : (
|
|
411
|
-
<CapColumn id="bee-plugin-container" className="bee-plugin-container" />
|
|
412
|
-
)}
|
|
370
|
+
<CapSpin spinning={saveRowRequest || false}>
|
|
371
|
+
<div id="bee-plugin-container" style={{ height: "650px" }}></div>
|
|
413
372
|
<TagList
|
|
414
373
|
moduleFilterEnabled={moduleFilterEnabled}
|
|
415
374
|
label={label}
|
|
@@ -64,12 +64,4 @@ export default defineMessages({
|
|
|
64
64
|
id: `${prefix}.rowCreationFailureMgs`,
|
|
65
65
|
defaultMessage: 'Error in row creation',
|
|
66
66
|
},
|
|
67
|
-
beePluginLoadError: {
|
|
68
|
-
id: `${prefix}.beePluginLoadError`,
|
|
69
|
-
defaultMessage: 'Unable to load the drag & drop editor. Check your network connection and try again.',
|
|
70
|
-
},
|
|
71
|
-
retry: {
|
|
72
|
-
id: `${prefix}.retry`,
|
|
73
|
-
defaultMessage: 'Retry',
|
|
74
|
-
},
|
|
75
67
|
});
|
|
@@ -6,7 +6,6 @@ import { connect } from 'react-redux';
|
|
|
6
6
|
import { createStructuredSelector } from 'reselect';
|
|
7
7
|
import CapRow from '@capillarytech/cap-ui-library/CapRow';
|
|
8
8
|
import { UserIsAuthenticated } from '../../utils/authWrapper';
|
|
9
|
-
import { destroyBeeInstance, loadBeePlugin, startBeePlugin } from '../../utils/beePluginLoader';
|
|
10
9
|
import TagList from '../TagList';
|
|
11
10
|
import {
|
|
12
11
|
ANDROID, BEE_LAYOUT_OPTIONS, MOBILE, UNSUBSCRIBE,
|
|
@@ -114,34 +113,18 @@ function BeePopupEditor(props) {
|
|
|
114
113
|
saveBeeData(jsonFile, htmlFile, device);
|
|
115
114
|
},
|
|
116
115
|
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}).then((instance) => {
|
|
129
|
-
// Cleanup already ran (unmount or layout change), so this editor is obsolete
|
|
130
|
-
if (isEffectCancelled) {
|
|
131
|
-
destroyBeeInstance(instance);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
beePluginInstance = instance;
|
|
135
|
-
beeInstanceRef.current = instance;
|
|
136
|
-
saveBeeInstance(beePluginInstance, device);
|
|
137
|
-
isInitializedRef.current = true;
|
|
138
|
-
});
|
|
139
|
-
})
|
|
140
|
-
.catch((error) => {
|
|
141
|
-
console.error('[BeePopupEditor] Error creating BEE plugin:', error);
|
|
142
|
-
});
|
|
116
|
+
window.BeePlugin.create(tokenData, beeConfig, (instance) => {
|
|
117
|
+
beePluginInstance = instance;
|
|
118
|
+
beeInstanceRef.current = instance;
|
|
119
|
+
// Use ref to get the latest beeJson — the closure captures the value at effect time,
|
|
120
|
+
// but beeJsonRef.current is always up-to-date (e.g. when template data loads async)
|
|
121
|
+
const latestBeeJson = beeJsonRef.current;
|
|
122
|
+
const parseJson = typeof latestBeeJson === 'string' ? JSON.parse(latestBeeJson) : latestBeeJson;
|
|
123
|
+
beePluginInstance.start(parseJson);
|
|
124
|
+
saveBeeInstance(beePluginInstance, device);
|
|
125
|
+
isInitializedRef.current = true;
|
|
126
|
+
});
|
|
143
127
|
return () => {
|
|
144
|
-
isEffectCancelled = true;
|
|
145
128
|
clearInterval(intervalTimer);
|
|
146
129
|
// Reset initialization flag when component unmounts or layout changes
|
|
147
130
|
isInitializedRef.current = false;
|
|
@@ -491,6 +491,7 @@ const ChannelSelectionStep = ({
|
|
|
491
491
|
onDeliverySettingChange={(deliverySetting) => onChange({ deliverySetting })}
|
|
492
492
|
onDomainPropertiesLoaded={setDomainPropertiesData}
|
|
493
493
|
orgUnitId={config?.context?.ouId}
|
|
494
|
+
domainPropertiesPriority={config?.context?.domainPropertiesPriority}
|
|
494
495
|
intl={intl}
|
|
495
496
|
/>
|
|
496
497
|
)}
|
package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/DeliverySettingsSection.js
CHANGED
|
@@ -37,6 +37,7 @@ const DeliverySettingsSection = ({
|
|
|
37
37
|
onDeliverySettingChange,
|
|
38
38
|
onDomainPropertiesLoaded,
|
|
39
39
|
orgUnitId,
|
|
40
|
+
domainPropertiesPriority,
|
|
40
41
|
intl,
|
|
41
42
|
}) => {
|
|
42
43
|
const [showSlidebox, setShowSlidebox] = useState(false);
|
|
@@ -119,7 +120,7 @@ const DeliverySettingsSection = ({
|
|
|
119
120
|
// uses) so both screens fetch domains for the same org unit; fall back to the logged-in
|
|
120
121
|
// user's own cached OU only when a consumer hasn't supplied one.
|
|
121
122
|
const resolvedOrgUnitId = orgUnitId ?? (loadItem('ouId') || loadItem('orgID'));
|
|
122
|
-
const response = await getDomainProperties(deliveryFetchChannels, resolvedOrgUnitId);
|
|
123
|
+
const response = await getDomainProperties(deliveryFetchChannels, resolvedOrgUnitId, domainPropertiesPriority);
|
|
123
124
|
if (!cancelled) {
|
|
124
125
|
const raw = response?.entity || response;
|
|
125
126
|
// Normalize channel keys to uppercase (API may return Viber, viber, etc.)
|
|
@@ -365,6 +366,8 @@ DeliverySettingsSection.propTypes = {
|
|
|
365
366
|
onDeliverySettingChange: PropTypes.func,
|
|
366
367
|
onDomainPropertiesLoaded: PropTypes.func,
|
|
367
368
|
orgUnitId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
369
|
+
// Consumer opt-in (config.context.domainPropertiesPriority) — switches to domainPropertiesByPriority.
|
|
370
|
+
domainPropertiesPriority: PropTypes.string,
|
|
368
371
|
intl: PropTypes.object.isRequired,
|
|
369
372
|
};
|
|
370
373
|
|
|
@@ -374,6 +377,7 @@ DeliverySettingsSection.defaultProps = {
|
|
|
374
377
|
deliverySetting: null,
|
|
375
378
|
onDeliverySettingChange: null,
|
|
376
379
|
orgUnitId: undefined,
|
|
380
|
+
domainPropertiesPriority: undefined,
|
|
377
381
|
};
|
|
378
382
|
|
|
379
383
|
export default injectIntl(DeliverySettingsSection);
|
|
@@ -154,6 +154,7 @@ function renderSection(props = {}) {
|
|
|
154
154
|
deliverySetting = {},
|
|
155
155
|
onDeliverySettingChange,
|
|
156
156
|
orgUnitId,
|
|
157
|
+
domainPropertiesPriority,
|
|
157
158
|
} = props;
|
|
158
159
|
return render(
|
|
159
160
|
<IntlProvider locale="en" messages={{}} defaultLocale="en">
|
|
@@ -163,6 +164,7 @@ function renderSection(props = {}) {
|
|
|
163
164
|
deliverySetting={deliverySetting}
|
|
164
165
|
onDeliverySettingChange={onDeliverySettingChange}
|
|
165
166
|
orgUnitId={orgUnitId}
|
|
167
|
+
domainPropertiesPriority={domainPropertiesPriority}
|
|
166
168
|
/>
|
|
167
169
|
</IntlProvider>,
|
|
168
170
|
);
|
|
@@ -298,7 +300,7 @@ describe('DeliverySettingsSection — marketer flows', () => {
|
|
|
298
300
|
|
|
299
301
|
renderSection({ contentItems: [{ channel: 'SMS' }] });
|
|
300
302
|
|
|
301
|
-
await waitFor(() => expect(getDomainProperties).toHaveBeenCalledWith(['SMS'], 'fallback-org'));
|
|
303
|
+
await waitFor(() => expect(getDomainProperties).toHaveBeenCalledWith(['SMS'], 'fallback-org', undefined));
|
|
302
304
|
});
|
|
303
305
|
|
|
304
306
|
it('prefers the consumer-supplied orgUnitId (config.context.ouId) over local storage — same source Preview-and-test uses, so both fetch the same org unit', async () => {
|
|
@@ -307,7 +309,24 @@ describe('DeliverySettingsSection — marketer flows', () => {
|
|
|
307
309
|
|
|
308
310
|
renderSection({ contentItems: [{ channel: 'SMS' }], orgUnitId: 'consumer-ou' });
|
|
309
311
|
|
|
310
|
-
await waitFor(() => expect(getDomainProperties).toHaveBeenCalledWith(['SMS'], 'consumer-ou'));
|
|
312
|
+
await waitFor(() => expect(getDomainProperties).toHaveBeenCalledWith(['SMS'], 'consumer-ou', undefined));
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('forwards the consumer-supplied domainPropertiesPriority (e.g. CapNotify HIGH) to the domain-properties fetch', async () => {
|
|
316
|
+
getDomainProperties.mockResolvedValue({ entity: apiEntity.SMS });
|
|
317
|
+
|
|
318
|
+
renderSection({ contentItems: [{ channel: 'SMS' }], orgUnitId: 'consumer-ou', domainPropertiesPriority: 'HIGH' });
|
|
319
|
+
|
|
320
|
+
await waitFor(() => expect(getDomainProperties).toHaveBeenCalledWith(['SMS'], 'consumer-ou', 'HIGH'));
|
|
321
|
+
expect(await screen.findByText('+1002003001')).toBeInTheDocument();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('does not pass a priority when the consumer has not opted in', async () => {
|
|
325
|
+
getDomainProperties.mockResolvedValue({ entity: apiEntity.SMS });
|
|
326
|
+
|
|
327
|
+
renderSection({ contentItems: [{ channel: 'SMS' }], orgUnitId: 'consumer-ou' });
|
|
328
|
+
|
|
329
|
+
await waitFor(() => expect(getDomainProperties).toHaveBeenCalledWith(['SMS'], 'consumer-ou', undefined));
|
|
311
330
|
});
|
|
312
331
|
|
|
313
332
|
it('accepts the whole response as the entity when `entity` is omitted (some clients)', async () => {
|
|
@@ -611,7 +630,7 @@ describe('DeliverySettingsSection — marketer flows', () => {
|
|
|
611
630
|
|
|
612
631
|
renderSection({ contentItems: [rcsWithFallbackContentItem] });
|
|
613
632
|
|
|
614
|
-
await waitFor(() => expect(getDomainProperties).toHaveBeenCalledWith(['RCS', 'SMS'], 'test-ou'));
|
|
633
|
+
await waitFor(() => expect(getDomainProperties).toHaveBeenCalledWith(['RCS', 'SMS'], 'test-ou', undefined));
|
|
615
634
|
});
|
|
616
635
|
|
|
617
636
|
it('does not fetch SMS domains when the RCS content has no SMS-fallback content', async () => {
|
|
@@ -619,7 +638,7 @@ describe('DeliverySettingsSection — marketer flows', () => {
|
|
|
619
638
|
|
|
620
639
|
renderSection({ contentItems: [{ channel: 'RCS' }] });
|
|
621
640
|
|
|
622
|
-
await waitFor(() => expect(getDomainProperties).toHaveBeenCalledWith(['RCS'], 'test-ou'));
|
|
641
|
+
await waitFor(() => expect(getDomainProperties).toHaveBeenCalledWith(['RCS'], 'test-ou', undefined));
|
|
623
642
|
});
|
|
624
643
|
|
|
625
644
|
it('shows a "Fallback SMS sender ID" summary row sourced from the SMS domain default sender', async () => {
|
|
@@ -756,8 +756,6 @@ export function SlideBoxContent(props) {
|
|
|
756
756
|
const isBEETemplate = templateData?.base?.is_drag_drop === true
|
|
757
757
|
|| templateData?.base?.is_drag_drop === 1;
|
|
758
758
|
if (supportCKEditor || isBEETemplate) {
|
|
759
|
-
// Host-supplied BEE content is the latest edit; fetching by _id would reload the original template over it
|
|
760
|
-
const hasHostBEEContent = isBEETemplate && !isEmpty(templateData?.base?.json_content);
|
|
761
759
|
return (
|
|
762
760
|
<Email
|
|
763
761
|
key="cretives-container-email-edit"
|
|
@@ -769,7 +767,7 @@ export function SlideBoxContent(props) {
|
|
|
769
767
|
route={{ name: 'email' }}
|
|
770
768
|
isGetFormData={isGetFormData}
|
|
771
769
|
getFormdata={getFormData}
|
|
772
|
-
params={{ id:
|
|
770
|
+
params={{ id: templateData._id }}
|
|
773
771
|
templateData={templateData}
|
|
774
772
|
getFormSubscriptionData={getFormData}
|
|
775
773
|
getDefaultTags={type}
|
|
@@ -580,7 +580,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
580
580
|
const beeJson = `BEEeditor${currentTab > 1 ? currentTab : ''}json`;
|
|
581
581
|
const beeToken = `BEEeditor${currentTab > 1 ? currentTab : ''}token`;
|
|
582
582
|
let beeJsonValue = '';
|
|
583
|
-
const selectedId = _.get(
|
|
583
|
+
const selectedId = _.get(this.props, 'Email.templateDetails._id', '') || '';
|
|
584
584
|
|
|
585
585
|
// Get beeJsonValue from template data - check multiple sources
|
|
586
586
|
// First check if it's already in formData (from setEditData)
|
|
@@ -637,7 +637,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
637
637
|
is_drag_drop: true,
|
|
638
638
|
[beeJson]: finalBeeJsonValue,
|
|
639
639
|
[beeToken]: nextProps.Email.CmsSettings.tokenData,
|
|
640
|
-
id: selectedId
|
|
640
|
+
id: selectedId,
|
|
641
641
|
// Also store json-content for reference
|
|
642
642
|
'json-content': finalBeeJsonValue,
|
|
643
643
|
};
|
|
@@ -83,8 +83,6 @@ const useEmailWrapper = ({
|
|
|
83
83
|
pathname: `/email/create`,
|
|
84
84
|
query: { module: 'library', type: 'embedded' },
|
|
85
85
|
});
|
|
86
|
-
// On create, `location` is the host app's route (e.g. a promotion /edit/:id URL), so it must not mark the email as an edit
|
|
87
|
-
const routeLocation = isEditEmail ? location : undefined;
|
|
88
86
|
|
|
89
87
|
// Cleanup effect
|
|
90
88
|
useEffect(() => () => {
|
|
@@ -157,7 +155,7 @@ const useEmailWrapper = ({
|
|
|
157
155
|
}
|
|
158
156
|
|
|
159
157
|
// Check if we're in edit mode (need to check BEE status for editor selection)
|
|
160
|
-
const hasParamsId = params?.id ||
|
|
158
|
+
const hasParamsId = params?.id || location?.query?.id || location?.params?.id || location?.pathname?.includes('/edit/');
|
|
161
159
|
const isEditMode = hasParamsId;
|
|
162
160
|
|
|
163
161
|
// Only check BEE enabled status for new flow (when supportCKEditor is false)
|
|
@@ -175,7 +173,7 @@ const useEmailWrapper = ({
|
|
|
175
173
|
// Make API call to check BEE enabled status using new endpoint
|
|
176
174
|
emailActions.getCmsAccounts('BEE_PLUGIN');
|
|
177
175
|
}
|
|
178
|
-
}, [currentStep, emailActions, params?.id,
|
|
176
|
+
}, [currentStep, emailActions, params?.id, location?.query?.id, location?.params?.id, location?.pathname]);
|
|
179
177
|
|
|
180
178
|
// Effect to update isBeeEditorEnabled based on new API response
|
|
181
179
|
// This effect watches for isBeeEnabled from the new API response
|
|
@@ -207,23 +205,23 @@ const useEmailWrapper = ({
|
|
|
207
205
|
if (!isEditEmail) {
|
|
208
206
|
return;
|
|
209
207
|
}
|
|
210
|
-
const hasParamsId = params?.id ||
|
|
208
|
+
const hasParamsId = params?.id || location?.query?.id || location?.params?.id || location?.pathname?.includes('/edit/');
|
|
211
209
|
const hasTemplateDetails = Email?.templateDetails && !isEmpty(Email.templateDetails);
|
|
212
210
|
const hasTemplateDataProp = templateData && !isEmpty(templateData);
|
|
213
211
|
const isTemplateLoading = Email?.getTemplateDetailsInProgress;
|
|
214
212
|
|
|
215
213
|
// Only fetch if we have an ID, don't have template data yet, and not already loading
|
|
216
214
|
if (hasParamsId && !hasTemplateDetails && !hasTemplateDataProp && !isTemplateLoading && emailActions?.getTemplateDetails) {
|
|
217
|
-
let templateId = params?.id ||
|
|
218
|
-
if (!templateId &&
|
|
219
|
-
const [, extractedId] =
|
|
215
|
+
let templateId = params?.id || location?.query?.id || location?.params?.id;
|
|
216
|
+
if (!templateId && location?.pathname?.includes('/edit/')) {
|
|
217
|
+
const [, extractedId] = location.pathname.match(/\/edit\/([^/]+)/) || [];
|
|
220
218
|
if (extractedId) templateId = extractedId;
|
|
221
219
|
}
|
|
222
220
|
if (templateId) {
|
|
223
221
|
emailActions.getTemplateDetails(templateId, 'email');
|
|
224
222
|
}
|
|
225
223
|
}
|
|
226
|
-
}, [isEditEmail, params?.id,
|
|
224
|
+
}, [isEditEmail, params?.id, location?.query?.id, location?.params?.id, location?.pathname, Email?.templateDetails, Email?.getTemplateDetailsInProgress, templateData, emailActions]);
|
|
227
225
|
|
|
228
226
|
// Effect to set BEETemplate when template details are loaded for BEE templates
|
|
229
227
|
// This ensures Email component can properly initialize BEE editor
|
|
@@ -281,9 +279,9 @@ const useEmailWrapper = ({
|
|
|
281
279
|
const isBEEAppEnable = checkBeeEditorEnabled();
|
|
282
280
|
// Check if we're in edit mode - check multiple sources for id
|
|
283
281
|
const hasParamsId = params?.id
|
|
284
|
-
||
|
|
285
|
-
||
|
|
286
|
-
|| (
|
|
282
|
+
|| location?.query?.id
|
|
283
|
+
|| location?.params?.id
|
|
284
|
+
|| (location?.pathname && location.pathname.includes('/edit/'));
|
|
287
285
|
const cmsMode = hasParamsId ? 'open' : 'create';
|
|
288
286
|
// Extract langId from active tab
|
|
289
287
|
const activeTabForLang = get(editTemplateData, 'versions.base.activeTab', 'en');
|
|
@@ -548,9 +546,9 @@ const useEmailWrapper = ({
|
|
|
548
546
|
useEffect(() => {
|
|
549
547
|
// If templateData is cleared/null and we're not in edit mode, reset selectedCreateMode
|
|
550
548
|
const hasParamsId = params?.id
|
|
551
|
-
||
|
|
552
|
-
||
|
|
553
|
-
||
|
|
549
|
+
|| location?.query?.id
|
|
550
|
+
|| location?.params?.id
|
|
551
|
+
|| location?.pathname?.includes('/edit/');
|
|
554
552
|
const hasTemplateData = templateData && !isEmpty(templateData);
|
|
555
553
|
const isEditMode = hasParamsId || hasTemplateData;
|
|
556
554
|
|
|
@@ -563,7 +561,7 @@ const useEmailWrapper = ({
|
|
|
563
561
|
// This preserves user selection while in content creation
|
|
564
562
|
setSelectedCreateMode('');
|
|
565
563
|
}
|
|
566
|
-
}, [templateData, params?.id,
|
|
564
|
+
}, [templateData, params?.id, location?.query?.id, location?.params?.id, location?.pathname, selectedCreateMode, templateName, currentStep, emailCreateMode]);
|
|
567
565
|
|
|
568
566
|
// Derived state
|
|
569
567
|
const supportCKEditorFlag = hasSupportCKEditor();
|
|
@@ -591,7 +589,7 @@ const useEmailWrapper = ({
|
|
|
591
589
|
// Check if we're editing an existing template
|
|
592
590
|
// CRITICAL: Only treat as edit mode if we have params.id (actual edit URL) or templateData prop
|
|
593
591
|
// Don't use templateDetails existence alone, as it might persist from previous template
|
|
594
|
-
const hasParamsId = params?.id ||
|
|
592
|
+
const hasParamsId = params?.id || location?.query?.id || location?.params?.id || location?.pathname?.includes('/edit/');
|
|
595
593
|
const hasTemplateDataProp = templateData && !isEmpty(templateData);
|
|
596
594
|
// CRITICAL: Consider it edit mode if we have params.id OR templateData prop (library mode)
|
|
597
595
|
// This allows editor type determination even when template data is still loading
|
|
@@ -708,13 +706,13 @@ const useEmailWrapper = ({
|
|
|
708
706
|
const emailParams = {};
|
|
709
707
|
if (params?.id) {
|
|
710
708
|
emailParams.id = params.id;
|
|
711
|
-
} else if (
|
|
712
|
-
emailParams.id =
|
|
713
|
-
} else if (
|
|
714
|
-
emailParams.id =
|
|
715
|
-
} else if (
|
|
709
|
+
} else if (location?.query?.id) {
|
|
710
|
+
emailParams.id = location.query.id;
|
|
711
|
+
} else if (location?.params?.id) {
|
|
712
|
+
emailParams.id = location.params.id;
|
|
713
|
+
} else if (location?.pathname?.includes('/edit/')) {
|
|
716
714
|
// Extract id from pathname if it's in the format /edit/:id
|
|
717
|
-
const match =
|
|
715
|
+
const match = location.pathname.match(/\/edit\/([^/]+)/);
|
|
718
716
|
// Reject sentinel strings that come from unguarded template literals
|
|
719
717
|
// (e.g. `/edit/${maybeUndefined}` → "/edit/undefined"), so they don't
|
|
720
718
|
// get treated as real template ids downstream.
|
|
@@ -802,7 +800,7 @@ const useEmailWrapper = ({
|
|
|
802
800
|
// Check if we're in edit mode (templateDetails or BEETemplate exists, or params.id exists)
|
|
803
801
|
const hasTemplateDetails = Email?.templateDetails && !isEmpty(Email.templateDetails);
|
|
804
802
|
const hasBEETemplate = Email?.BEETemplate && !isEmpty(Email.BEETemplate);
|
|
805
|
-
const hasParamsId = params?.id ||
|
|
803
|
+
const hasParamsId = params?.id || location?.query?.id || location?.params?.id || location?.pathname?.includes('/edit/');
|
|
806
804
|
const isEditMode = hasTemplateDetails || hasBEETemplate || hasParamsId;
|
|
807
805
|
|
|
808
806
|
// In edit mode (when supportCKEditor is false), always show editor
|
|
@@ -844,7 +842,7 @@ const useEmailWrapper = ({
|
|
|
844
842
|
|
|
845
843
|
// For Editor: Show editor when template is selected
|
|
846
844
|
return !isEmpty(SelectedEdmDefaultTemplate);
|
|
847
|
-
}, [currentStep, selectedCreateMode, supportCKEditorFlag, emailCreateMode, EmailLayout, SelectedEdmDefaultTemplate, Email?.templateDetails, Email?.BEETemplate, params?.id,
|
|
845
|
+
}, [currentStep, selectedCreateMode, supportCKEditorFlag, emailCreateMode, EmailLayout, SelectedEdmDefaultTemplate, Email?.templateDetails, Email?.BEETemplate, params?.id, location?.query?.id, location?.params?.id, location?.pathname, emailProps?.editor, emailProps?.selectedEditorMode]);
|
|
848
846
|
|
|
849
847
|
// Memoize static data
|
|
850
848
|
const modes = useMemo(() => {
|
package/utils/beePluginLoader.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export const BEE_PLUGIN_SCRIPT_URL = 'https://app-rsrc.getbee.io/plugin/BeePlugin.js';
|
|
2
|
-
export const BEE_PLUGIN_LOAD_TIMEOUT_MS = 30000;
|
|
3
|
-
|
|
4
|
-
let beePluginPromise = null;
|
|
5
|
-
|
|
6
|
-
// Hosts consuming creatives as a library or MFE may not ship BeePlugin.js, so load it on demand
|
|
7
|
-
export const loadBeePlugin = () => {
|
|
8
|
-
if (window.BeePlugin) {
|
|
9
|
-
return Promise.resolve(window.BeePlugin);
|
|
10
|
-
}
|
|
11
|
-
if (beePluginPromise) {
|
|
12
|
-
return beePluginPromise;
|
|
13
|
-
}
|
|
14
|
-
beePluginPromise = new Promise((resolve, reject) => {
|
|
15
|
-
const existingScript = document.querySelector('script[src*="BeePlugin.js"]');
|
|
16
|
-
const script = existingScript || document.createElement('script');
|
|
17
|
-
let timeoutId = null;
|
|
18
|
-
const fail = (error) => {
|
|
19
|
-
clearTimeout(timeoutId);
|
|
20
|
-
beePluginPromise = null;
|
|
21
|
-
// Drop the tag so a retry injects a fresh one instead of waiting on a dead script
|
|
22
|
-
script.remove();
|
|
23
|
-
reject(error);
|
|
24
|
-
};
|
|
25
|
-
const onLoad = () => {
|
|
26
|
-
if (window.BeePlugin) {
|
|
27
|
-
clearTimeout(timeoutId);
|
|
28
|
-
resolve(window.BeePlugin);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
fail(new Error('BeePlugin.js loaded but window.BeePlugin is undefined'));
|
|
32
|
-
};
|
|
33
|
-
const onError = () => fail(new Error(`Failed to load ${BEE_PLUGIN_SCRIPT_URL}`));
|
|
34
|
-
timeoutId = setTimeout(
|
|
35
|
-
() => fail(new Error(`Timed out loading ${BEE_PLUGIN_SCRIPT_URL}`)),
|
|
36
|
-
BEE_PLUGIN_LOAD_TIMEOUT_MS,
|
|
37
|
-
);
|
|
38
|
-
script.addEventListener('load', onLoad, { once: true });
|
|
39
|
-
script.addEventListener('error', onError, { once: true });
|
|
40
|
-
if (!existingScript) {
|
|
41
|
-
script.src = BEE_PLUGIN_SCRIPT_URL;
|
|
42
|
-
script.type = 'text/javascript';
|
|
43
|
-
script.async = true;
|
|
44
|
-
document.head.appendChild(script);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
return beePluginPromise;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// Tears down an editor that will not be used; destroy can throw if BEE never finished mounting
|
|
51
|
-
export const destroyBeeInstance = (instance) => {
|
|
52
|
-
try {
|
|
53
|
-
if (typeof instance?.destroy === 'function') {
|
|
54
|
-
instance.destroy();
|
|
55
|
-
}
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.warn('[beePluginLoader] Error destroying BEE plugin:', error);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// Creates a BEE editor and starts it with the template JSON (string or object) returned by getBeeJson
|
|
62
|
-
export const startBeePlugin = (BeePlugin, { tokenData, beeConfig, getBeeJson }) => new Promise((resolve, reject) => {
|
|
63
|
-
BeePlugin.create(tokenData, beeConfig, (instance) => {
|
|
64
|
-
try {
|
|
65
|
-
const beeJson = getBeeJson();
|
|
66
|
-
instance.start(typeof beeJson === 'string' ? JSON.parse(beeJson) : beeJson);
|
|
67
|
-
resolve(instance);
|
|
68
|
-
} catch (error) {
|
|
69
|
-
destroyBeeInstance(instance);
|
|
70
|
-
reject(error);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
const SCRIPT_SELECTOR = 'script[src*="BeePlugin.js"]';
|
|
2
|
-
|
|
3
|
-
const getLoader = () => {
|
|
4
|
-
let loader;
|
|
5
|
-
jest.isolateModules(() => {
|
|
6
|
-
loader = require('../beePluginLoader');
|
|
7
|
-
});
|
|
8
|
-
return loader;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
describe('loadBeePlugin', () => {
|
|
12
|
-
const mockBeePlugin = { create: jest.fn() };
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
delete window.BeePlugin;
|
|
16
|
-
document.head.innerHTML = '';
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
jest.useRealTimers();
|
|
21
|
-
delete window.BeePlugin;
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('resolves immediately without injecting a script when BeePlugin is already loaded', async () => {
|
|
25
|
-
window.BeePlugin = mockBeePlugin;
|
|
26
|
-
const { loadBeePlugin } = getLoader();
|
|
27
|
-
await expect(loadBeePlugin()).resolves.toBe(mockBeePlugin);
|
|
28
|
-
expect(document.querySelector(SCRIPT_SELECTOR)).toBeNull();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('injects the script once and resolves when it loads', async () => {
|
|
32
|
-
const { loadBeePlugin, BEE_PLUGIN_SCRIPT_URL } = getLoader();
|
|
33
|
-
const firstLoad = loadBeePlugin();
|
|
34
|
-
const secondLoad = loadBeePlugin();
|
|
35
|
-
const scripts = document.querySelectorAll(SCRIPT_SELECTOR);
|
|
36
|
-
expect(scripts).toHaveLength(1);
|
|
37
|
-
expect(scripts[0].src).toBe(BEE_PLUGIN_SCRIPT_URL);
|
|
38
|
-
expect(secondLoad).toBe(firstLoad);
|
|
39
|
-
window.BeePlugin = mockBeePlugin;
|
|
40
|
-
scripts[0].dispatchEvent(new Event('load'));
|
|
41
|
-
await expect(firstLoad).resolves.toBe(mockBeePlugin);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('waits on a host-provided script instead of injecting another', async () => {
|
|
45
|
-
const hostScript = document.createElement('script');
|
|
46
|
-
hostScript.src = 'https://app-rsrc.getbee.io/plugin/BeePlugin.js';
|
|
47
|
-
document.head.appendChild(hostScript);
|
|
48
|
-
const { loadBeePlugin } = getLoader();
|
|
49
|
-
const load = loadBeePlugin();
|
|
50
|
-
expect(document.querySelectorAll(SCRIPT_SELECTOR)).toHaveLength(1);
|
|
51
|
-
window.BeePlugin = mockBeePlugin;
|
|
52
|
-
hostScript.dispatchEvent(new Event('load'));
|
|
53
|
-
await expect(load).resolves.toBe(mockBeePlugin);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('rejects on script error, removes the tag and allows a retry', async () => {
|
|
57
|
-
const { loadBeePlugin } = getLoader();
|
|
58
|
-
const failedLoad = loadBeePlugin();
|
|
59
|
-
document.querySelector(SCRIPT_SELECTOR).dispatchEvent(new Event('error'));
|
|
60
|
-
await expect(failedLoad).rejects.toThrow('Failed to load');
|
|
61
|
-
expect(document.querySelector(SCRIPT_SELECTOR)).toBeNull();
|
|
62
|
-
|
|
63
|
-
const retryLoad = loadBeePlugin();
|
|
64
|
-
expect(retryLoad).not.toBe(failedLoad);
|
|
65
|
-
window.BeePlugin = mockBeePlugin;
|
|
66
|
-
document.querySelector(SCRIPT_SELECTOR).dispatchEvent(new Event('load'));
|
|
67
|
-
await expect(retryLoad).resolves.toBe(mockBeePlugin);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('rejects when the script loads but does not define BeePlugin', async () => {
|
|
71
|
-
const { loadBeePlugin } = getLoader();
|
|
72
|
-
const load = loadBeePlugin();
|
|
73
|
-
document.querySelector(SCRIPT_SELECTOR).dispatchEvent(new Event('load'));
|
|
74
|
-
await expect(load).rejects.toThrow('window.BeePlugin is undefined');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('rejects after the timeout when the script never settles', async () => {
|
|
78
|
-
jest.useFakeTimers();
|
|
79
|
-
const { loadBeePlugin, BEE_PLUGIN_LOAD_TIMEOUT_MS } = getLoader();
|
|
80
|
-
const load = loadBeePlugin();
|
|
81
|
-
jest.advanceTimersByTime(BEE_PLUGIN_LOAD_TIMEOUT_MS);
|
|
82
|
-
await expect(load).rejects.toThrow('Timed out');
|
|
83
|
-
expect(document.querySelector(SCRIPT_SELECTOR)).toBeNull();
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('startBeePlugin', () => {
|
|
88
|
-
const tokenData = { access_token: 'token' };
|
|
89
|
-
const beeConfig = { uid: 'uid' };
|
|
90
|
-
let instance;
|
|
91
|
-
let BeePlugin;
|
|
92
|
-
|
|
93
|
-
beforeEach(() => {
|
|
94
|
-
instance = { start: jest.fn(), destroy: jest.fn() };
|
|
95
|
-
BeePlugin = { create: jest.fn((token, config, onCreated) => onCreated(instance)) };
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('creates the editor and starts it with parsed JSON when given a string', async () => {
|
|
99
|
-
const { startBeePlugin } = getLoader();
|
|
100
|
-
const result = await startBeePlugin(BeePlugin, { tokenData, beeConfig, getBeeJson: () => '{"page":{}}' });
|
|
101
|
-
expect(BeePlugin.create).toHaveBeenCalledWith(tokenData, beeConfig, expect.any(Function));
|
|
102
|
-
expect(instance.start).toHaveBeenCalledWith({ page: {} });
|
|
103
|
-
expect(result).toBe(instance);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('starts the editor with an object template as-is', async () => {
|
|
107
|
-
const { startBeePlugin } = getLoader();
|
|
108
|
-
const template = { page: { rows: [] } };
|
|
109
|
-
await startBeePlugin(BeePlugin, { tokenData, beeConfig, getBeeJson: () => template });
|
|
110
|
-
expect(instance.start).toHaveBeenCalledWith(template);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('rejects without starting when the template JSON is invalid', async () => {
|
|
114
|
-
const { startBeePlugin } = getLoader();
|
|
115
|
-
await expect(
|
|
116
|
-
startBeePlugin(BeePlugin, { tokenData, beeConfig, getBeeJson: () => '{invalid' }),
|
|
117
|
-
).rejects.toThrow(SyntaxError);
|
|
118
|
-
expect(instance.start).not.toHaveBeenCalled();
|
|
119
|
-
expect(instance.destroy).toHaveBeenCalledTimes(1);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe('destroyBeeInstance', () => {
|
|
124
|
-
it('destroys the editor and tolerates a missing or failing destroy', () => {
|
|
125
|
-
const { destroyBeeInstance } = getLoader();
|
|
126
|
-
const instance = { destroy: jest.fn() };
|
|
127
|
-
destroyBeeInstance(instance);
|
|
128
|
-
expect(instance.destroy).toHaveBeenCalledTimes(1);
|
|
129
|
-
|
|
130
|
-
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
131
|
-
expect(() => destroyBeeInstance({ destroy: () => { throw new Error('not mounted'); } })).not.toThrow();
|
|
132
|
-
expect(() => destroyBeeInstance(undefined)).not.toThrow();
|
|
133
|
-
warn.mockRestore();
|
|
134
|
-
});
|
|
135
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import '@testing-library/jest-dom';
|
|
3
|
-
import { render, screen, fireEvent, waitFor } from '../../../utils/test-utils';
|
|
4
|
-
import { loadBeePlugin } from '../../../utils/beePluginLoader';
|
|
5
|
-
import BeeEditor from '../index';
|
|
6
|
-
|
|
7
|
-
jest.mock('../../../utils/beePluginLoader', () => ({
|
|
8
|
-
...jest.requireActual('../../../utils/beePluginLoader'),
|
|
9
|
-
loadBeePlugin: jest.fn(),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
jest.mock('../../TagList', () => () => null);
|
|
13
|
-
|
|
14
|
-
const mockBeePluginInstance = { start: jest.fn(), destroy: jest.fn() };
|
|
15
|
-
const mockBeePlugin = { create: jest.fn() };
|
|
16
|
-
|
|
17
|
-
const defaultProps = {
|
|
18
|
-
uid: 'test-uid',
|
|
19
|
-
id: 'bee-editor',
|
|
20
|
-
beeJson: '{"page":{}}',
|
|
21
|
-
tokenData: { access_token: 'token' },
|
|
22
|
-
saveBeeInstance: jest.fn(),
|
|
23
|
-
saveBeeData: jest.fn(),
|
|
24
|
-
tags: [],
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
describe('BeeEditor BeePlugin loading', () => {
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
mockBeePlugin.create.mockImplementation((tokenData, beeConfig, onCreated) => onCreated(mockBeePluginInstance));
|
|
30
|
-
jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
afterEach(() => {
|
|
34
|
-
console.error.mockRestore();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('creates the BEE editor once the plugin script has loaded', async () => {
|
|
38
|
-
loadBeePlugin.mockResolvedValue(mockBeePlugin);
|
|
39
|
-
const { container } = render(<BeeEditor {...defaultProps} />);
|
|
40
|
-
await waitFor(() => expect(mockBeePlugin.create).toHaveBeenCalledTimes(1));
|
|
41
|
-
expect(mockBeePluginInstance.start).toHaveBeenCalledWith({ page: {} });
|
|
42
|
-
expect(defaultProps.saveBeeInstance).toHaveBeenCalledWith(mockBeePluginInstance);
|
|
43
|
-
expect(container.querySelector('#bee-plugin-container')).toBeInTheDocument();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('shows an error with retry when the plugin script fails, and recovers on retry', async () => {
|
|
47
|
-
loadBeePlugin
|
|
48
|
-
.mockRejectedValueOnce(new Error('Failed to load'))
|
|
49
|
-
.mockResolvedValueOnce(mockBeePlugin);
|
|
50
|
-
const { container } = render(<BeeEditor {...defaultProps} />);
|
|
51
|
-
|
|
52
|
-
expect(await screen.findByText(/Unable to load the drag & drop editor/)).toBeInTheDocument();
|
|
53
|
-
expect(container.querySelector('#bee-plugin-container')).not.toBeInTheDocument();
|
|
54
|
-
expect(mockBeePlugin.create).not.toHaveBeenCalled();
|
|
55
|
-
|
|
56
|
-
fireEvent.click(screen.getByRole('button', { name: 'Retry' }));
|
|
57
|
-
|
|
58
|
-
await waitFor(() => expect(mockBeePlugin.create).toHaveBeenCalledTimes(1));
|
|
59
|
-
expect(screen.queryByText(/Unable to load the drag & drop editor/)).not.toBeInTheDocument();
|
|
60
|
-
expect(container.querySelector('#bee-plugin-container')).toBeInTheDocument();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('does not create the editor if it unmounts before the plugin loads', async () => {
|
|
64
|
-
let resolveLoad;
|
|
65
|
-
loadBeePlugin.mockReturnValue(new Promise((resolve) => { resolveLoad = resolve; }));
|
|
66
|
-
const { unmount } = render(<BeeEditor {...defaultProps} />);
|
|
67
|
-
unmount();
|
|
68
|
-
resolveLoad(mockBeePlugin);
|
|
69
|
-
await Promise.resolve();
|
|
70
|
-
expect(mockBeePlugin.create).not.toHaveBeenCalled();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('destroys an editor that finishes starting after unmount instead of saving it', async () => {
|
|
74
|
-
let finishCreate;
|
|
75
|
-
loadBeePlugin.mockResolvedValue(mockBeePlugin);
|
|
76
|
-
mockBeePlugin.create.mockImplementation((tokenData, beeConfig, onCreated) => {
|
|
77
|
-
finishCreate = () => onCreated(mockBeePluginInstance);
|
|
78
|
-
});
|
|
79
|
-
const { unmount } = render(<BeeEditor {...defaultProps} />);
|
|
80
|
-
await waitFor(() => expect(mockBeePlugin.create).toHaveBeenCalledTimes(1));
|
|
81
|
-
unmount();
|
|
82
|
-
finishCreate();
|
|
83
|
-
|
|
84
|
-
await waitFor(() => expect(mockBeePluginInstance.destroy).toHaveBeenCalledTimes(1));
|
|
85
|
-
expect(defaultProps.saveBeeInstance).not.toHaveBeenCalled();
|
|
86
|
-
});
|
|
87
|
-
});
|