@@ -3,7 +3,7 @@ import { readFile } from '@web/test-runner-commands';
33import { expect } from '@esm-bundle/chai' ;
44import sinon from 'sinon' ;
55import { waitForElement } from '../../helpers/waitfor.js' ;
6- import { setConfig } from '../../../libs/utils/utils.js' ;
6+ import { setConfig , getConfig } from '../../../libs/utils/utils.js' ;
77
88setConfig ( { 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