Skip to content

Commit a0a8725

Browse files
authored
MWPW-185132 [ABC] Milo changes to acomodate new ABC Web SDK changes to onboard on BC GA Version (#5414)
* Refactor script loading for brand concierge * Add getConfig to brand-concierge tests * Add support for new bootstrap API in brand concierge Implement new bootstrap API for loading scripts based on Alloy version. * Mock alloy version 2.31.0 in tests and update loading Added mock for alloy version 2.31.0 in multiple tests and updated script loading logic. * Refactor brand-concierge tests to remove alloy mocks and improve privacy consent handling * Add wait for openChatModal in brand-concierge tests to ensure bootstrap is called
1 parent 93e5704 commit a0a8725

File tree

2 files changed

+142
-7
lines changed

2 files changed

+142
-7
lines changed

libs/blocks/brand-concierge/brand-concierge.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getModal } from '../modal/modal.js';
2-
import { createTag, getConfig } from '../../utils/utils.js';
2+
import { createTag, getConfig, loadScript } from '../../utils/utils.js';
33
import chatUIConfig from './chat-ui-config.js';
44

55
const cardIcon = '<svg class="card-icon" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path d="M7.93446 10.5992C7.75946 10.5992 7.58289 10.5539 7.42352 10.4617C7.03836 10.239 6.84383 9.79763 6.93836 9.36325L7.52039 6.66404L5.6657 4.61794C5.36726 4.28825 5.3157 3.80856 5.53836 3.42341C5.76101 3.03748 6.20633 2.84294 6.6368 2.93825L9.33601 3.52028L11.3821 1.6656C11.7126 1.3656 12.1923 1.31638 12.5766 1.53825C12.9618 1.76091 13.1563 2.20232 13.0618 2.63669L12.4798 5.33591L14.3345 7.382C14.6329 7.71091 14.6837 8.1906 14.4618 8.57576C14.2391 8.96013 13.7993 9.15623 13.3641 9.06248L10.6649 8.47889L8.61806 10.3344C8.42509 10.5094 8.18054 10.5992 7.93446 10.5992ZM8.71336 6.82654L8.22977 9.06638L9.92742 7.52732C10.1696 7.30779 10.504 7.21716 10.8251 7.28591L13.0665 7.77028L11.5274 6.07263C11.3071 5.82888 11.2173 5.49216 11.2876 5.17184L11.7704 2.93356L10.0727 4.47263C9.82899 4.69294 9.49306 4.782 9.17196 4.71247L6.93368 4.22965L8.47274 5.92731C8.69305 6.17028 8.7829 6.50623 8.71336 6.82654Z" fill="currentColor"/><path d="M2.67645 14.6017C2.57333 14.6017 2.47021 14.5751 2.37645 14.5212C2.15067 14.3907 2.03505 14.1298 2.08973 13.8751L2.33505 12.7407L1.55536 11.8813C1.38036 11.6884 1.34989 11.404 1.48036 11.1782C1.61083 10.9524 1.87333 10.8399 2.12645 10.8915L3.26083 11.1368L4.12021 10.3571C4.31396 10.1813 4.59677 10.1516 4.82333 10.2821C5.04912 10.4126 5.16474 10.6735 5.11005 10.9282L4.86474 12.0626L5.64443 12.922C5.81943 13.1149 5.8499 13.3993 5.71943 13.6251C5.58896 13.8509 5.32568 13.9618 5.07333 13.9118L3.93896 13.6665L3.07958 14.4462C2.9663 14.5485 2.82177 14.6017 2.67645 14.6017Z" fill="currentColor"/></svg>';
@@ -70,11 +70,29 @@ async function openChatModal(initialMessage, el) {
7070
updateReplicatedValue(textareaWrapper, textarea);
7171

7272
// eslint-disable-next-line no-underscore-dangle
73-
window._satellite?.track('bootstrapConversationalExperience', {
74-
selector: `#${mountId}`,
75-
src: 'https://cdn.experience.adobe.net/solutions/experience-platform-brand-concierge-web-agent/static-assets/main.js',
76-
stylingConfigurations: getUpdatedChatUIConfig(textarea.placeholder),
77-
});
73+
const alloyVersion = window.alloy_all?.data?._adobe_corpnew?.digitalData?.page?.libraryVersions;
74+
const useNewBootstrapAPI = alloyVersion === '2.31.0';
75+
76+
if (useNewBootstrapAPI) {
77+
// New method: Load script and use bootstrap API
78+
const { env } = getConfig();
79+
const base = env.name === 'prod' ? 'experience.adobe.net' : 'experience-stage.adobe.net';
80+
const src = `https://${base}/solutions/experience-platform-brand-concierge-web-agent/static-assets/main.js`;
81+
await loadScript(src);
82+
window.adobe.concierge.bootstrap({
83+
instanceName: 'alloy',
84+
stylingConfigurations: getUpdatedChatUIConfig(textarea.placeholder),
85+
selector: `#${mountId}`,
86+
});
87+
} else {
88+
// Legacy method: Use _satellite.track
89+
// eslint-disable-next-line no-underscore-dangle
90+
window._satellite?.track('bootstrapConversationalExperience', {
91+
selector: `#${mountId}`,
92+
src: 'https://cdn.experience.adobe.net/solutions/experience-platform-brand-concierge-web-agent/static-assets/main.js',
93+
stylingConfigurations: getUpdatedChatUIConfig(textarea.placeholder),
94+
});
95+
}
7896

7997
const handleViewportResize = () => updateModalHeight();
8098
const handleOrientationChange = () => setTimeout(updateModalHeight, 100);

test/blocks/brand-concierge/brand-concierge.test.js

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { readFile } from '@web/test-runner-commands';
33
import { expect } from '@esm-bundle/chai';
44
import sinon from 'sinon';
55
import { waitForElement } from '../../helpers/waitfor.js';
6-
import { setConfig } from '../../../libs/utils/utils.js';
6+
import { setConfig, getConfig } from '../../../libs/utils/utils.js';
77

88
setConfig({ codeRoot: '/libs', brandConciergeAA: 'testAA' });
99

@@ -209,4 +209,121 @@ describe('Brand Concierge', () => {
209209
expect(textareaWrapper.dataset.replicatedValue).to.equal('Actual input');
210210
});
211211
});
212+
213+
it('uses bootstrap API when alloy version is exactly 2.31.0', async () => {
214+
setConfig({ codeRoot: '/libs', brandConciergeAA: 'testAA' });
215+
document.body.innerHTML = await readFile({ path: './mocks/default.html' });
216+
const block = document.querySelector('.brand-concierge');
217+
218+
// Mock alloy version 2.31.0
219+
window.alloy_all = { data: { _adobe_corpnew: { digitalData: { page: { libraryVersions: '2.31.0' } } } } };
220+
221+
window.adobe = window.adobe || {};
222+
window.adobe.concierge = { bootstrap: sinon.spy() };
223+
224+
// Pre-load script to bypass loadScript await
225+
const { env } = getConfig();
226+
const base = env.name === 'prod' ? 'experience.adobe.net' : 'experience-stage.adobe.net';
227+
const src = `https://${base}/solutions/experience-platform-brand-concierge-web-agent/static-assets/main.js`;
228+
const script = document.createElement('script');
229+
script.src = src;
230+
script.dataset.loaded = 'true';
231+
document.head.append(script);
232+
233+
await init(block);
234+
235+
const input = block.querySelector('#bc-input-field');
236+
input.value = 'Test message';
237+
input.dispatchEvent(new Event('input'));
238+
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
239+
240+
const modal = await waitForElement('#brand-concierge-modal');
241+
expect(modal).to.exist;
242+
243+
// Wait for openChatModal
244+
await new Promise((resolve) => {
245+
const check = () => {
246+
if (window.adobe.concierge.bootstrap.calledOnce) resolve();
247+
else setTimeout(check, 10);
248+
};
249+
check();
250+
});
251+
252+
// Verify bootstrap was called
253+
expect(window.adobe.concierge.bootstrap.calledOnce).to.be.true;
254+
expect(window.adobe.concierge.bootstrap.firstCall.args[0]).to.deep.include({
255+
selector: '#brand-concierge-mount',
256+
instanceName: 'alloy',
257+
});
258+
259+
// Clean up
260+
script.remove();
261+
delete window.adobe.concierge;
262+
delete window.alloy_all;
263+
});
264+
265+
it('uses _satellite.track when alloy version is < 2.31.0', async () => {
266+
setConfig({ codeRoot: '/libs', brandConciergeAA: 'testAA' });
267+
document.body.innerHTML = await readFile({ path: './mocks/default.html' });
268+
const block = document.querySelector('.brand-concierge');
269+
270+
// Mock alloy version 2.30.0
271+
window.alloy_all = { data: { _adobe_corpnew: { digitalData: { page: { libraryVersions: '2.30.0' } } } } };
272+
273+
window._satellite = { track: sinon.spy() };
274+
275+
await init(block);
276+
277+
const input = block.querySelector('#bc-input-field');
278+
input.value = 'Test message';
279+
input.dispatchEvent(new Event('input'));
280+
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
281+
282+
const modal = await waitForElement('#brand-concierge-modal');
283+
expect(modal).to.exist;
284+
285+
// Verify _satellite.track was called
286+
expect(window._satellite.track.calledOnce).to.be.true;
287+
expect(window._satellite.track.firstCall.args[0]).to.equal('bootstrapConversationalExperience');
288+
expect(window._satellite.track.firstCall.args[1]).to.deep.include({
289+
selector: '#brand-concierge-mount',
290+
src: 'https://cdn.experience.adobe.net/solutions/experience-platform-brand-concierge-web-agent/static-assets/main.js',
291+
});
292+
293+
// Verify script was NOT loaded via loadScript (no script tag should exist)
294+
const script = document.querySelector('script[src*="experience.adobe.net/solutions/experience-platform-brand-concierge-web-agent"]');
295+
expect(script).to.not.exist;
296+
297+
// Clean up
298+
delete window._satellite;
299+
delete window.alloy_all;
300+
});
301+
302+
it('uses _satellite.track when alloy version is missing', async () => {
303+
setConfig({ codeRoot: '/libs', brandConciergeAA: 'testAA' });
304+
document.body.innerHTML = await readFile({ path: './mocks/default.html' });
305+
const block = document.querySelector('.brand-concierge');
306+
307+
// Don't set window.alloy_all to simulate missing version
308+
delete window.alloy_all;
309+
310+
window._satellite = { track: sinon.spy() };
311+
312+
await init(block);
313+
314+
const input = block.querySelector('#bc-input-field');
315+
input.value = 'Test message';
316+
input.dispatchEvent(new Event('input'));
317+
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
318+
319+
const modal = await waitForElement('#brand-concierge-modal');
320+
expect(modal).to.exist;
321+
322+
// Verify _satellite.track was called (fallback to legacy)
323+
expect(window._satellite.track.calledOnce).to.be.true;
324+
expect(window._satellite.track.firstCall.args[0]).to.equal('bootstrapConversationalExperience');
325+
326+
// Clean up
327+
delete window._satellite;
328+
});
212329
});

0 commit comments

Comments
 (0)