Skip to content

Commit

Permalink
[MWPW-152549] BYO SUSI Options to pass in adobeIMS.signIn() (#2850)
Browse files Browse the repository at this point in the history
* Adding the ability to pass dctx_id to global-navigation block

* fix test error

* susi options

* quit getSusiOptions if no options passed

* refactor

* fallback on no envName val

* try catch

* unit tests added

* test client side declaration

* more clean up

* Adding fallback value

* const signInOptions

* Update utils.js

* revert changes for OST

* Update ost.js

* adding it to jarvis chat too

* updated unit test

* Update global-navigation.test.js

* Update global-navigation.test.js

* Update global-navigation.test.js
  • Loading branch information
qiyundai authored Oct 21, 2024
1 parent 179732a commit e5b7867
Show file tree
Hide file tree
Showing 8 changed files with 318 additions and 13 deletions.
15 changes: 8 additions & 7 deletions libs/blocks/global-navigation/global-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import {

import { replaceKey, replaceKeyArray } from '../../features/placeholders.js';

const SIGNIN_CONTEXT = getConfig()?.signInContext;

function getHelpChildren() {
const { unav } = getConfig();
return unav?.unavHelpChildren || [
Expand Down Expand Up @@ -94,8 +96,8 @@ export const CONFIG = {
},
},
callbacks: {
onSignIn: () => { window.adobeIMS?.signIn(); },
onSignUp: () => { window.adobeIMS?.signIn(); },
onSignIn: () => { window.adobeIMS?.signIn(SIGNIN_CONTEXT); },
onSignUp: () => { window.adobeIMS?.signIn(SIGNIN_CONTEXT); },
},
},
},
Expand Down Expand Up @@ -147,13 +149,12 @@ export const LANGMAP = {
};

// signIn, decorateSignIn and decorateProfileTrigger can be removed if IMS takes over the profile
const signIn = () => {
const signIn = (options = {}) => {
if (typeof window.adobeIMS?.signIn !== 'function') {
lanaLog({ message: 'IMS signIn method not available', tags: 'errorType=warn,module=gnav' });
return;
}

window.adobeIMS.signIn();
window.adobeIMS.signIn(options);
};

const decorateSignIn = async ({ rawElem, decoratedElem }) => {
Expand All @@ -166,7 +167,7 @@ const decorateSignIn = async ({ rawElem, decoratedElem }) => {

signInElem.addEventListener('click', (e) => {
e.preventDefault();
signIn();
signIn(SIGNIN_CONTEXT);
});
} else {
signInElem = toFragment`<button daa-ll="${signInLabel}" class="feds-signIn" aria-expanded="false" aria-haspopup="true">${signInLabel}</button>`;
Expand All @@ -183,7 +184,7 @@ const decorateSignIn = async ({ rawElem, decoratedElem }) => {
dropdownSignInAnchor.replaceWith(dropdownSignInButton);
dropdownSignInButton.addEventListener('click', (e) => {
e.preventDefault();
signIn();
signIn(SIGNIN_CONTEXT);
});
} else {
lanaLog({ message: 'Sign in link not found in dropdown.', tags: 'errorType=warn,module=gnav' });
Expand Down
3 changes: 2 additions & 1 deletion libs/blocks/gnav/gnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ class Gnav {
}
signInEl.addEventListener('click', (e) => {
e.preventDefault();
window.adobeIMS.signIn();
const { signInContext } = getConfig();
window.adobeIMS.signIn(signInContext);
});
profileEl.append(signIn);
};
Expand Down
2 changes: 1 addition & 1 deletion libs/features/jarvis-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const startInitialization = async (config, event, onDemand) => {
initErrorCallback: () => {},
chatStateCallback: () => {},
getContextCallback: () => {},
signInProvider: window.adobeIMS?.signIn,
signInProvider: () => window.adobeIMS?.signIn(config.signInContext),
analyticsCallback: (eventData) => {
if (!window.alloy_all || !window.digitalData) return;
const data = eventData?.events?.[0]?.data;
Expand Down
4 changes: 3 additions & 1 deletion libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export const [setConfig, updateConfig, getConfig] = (() => {
config.base = config.miloLibs || config.codeRoot;
config.locale = pathname ? getLocale(conf.locales, pathname) : getLocale(conf.locales);
config.autoBlocks = conf.autoBlocks ? [...AUTO_BLOCKS, ...conf.autoBlocks] : AUTO_BLOCKS;
config.signInContext = conf.signInContext || {};
config.doNotInline = conf.doNotInline
? [...DO_NOT_INLINE, ...conf.doNotInline]
: DO_NOT_INLINE;
Expand Down Expand Up @@ -691,7 +692,8 @@ export function decorateLinks(el) {
a.href = a.href.replace(loginEvent, '');
a.addEventListener('click', (e) => {
e.preventDefault();
window.adobeIMS?.signIn();
const { signInContext } = config;
window.adobeIMS?.signIn(signInContext);
});
}
const copyEvent = '#_evt-copy';
Expand Down
18 changes: 18 additions & 0 deletions test/blocks/global-navigation/global-navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import longNav from './mocks/global-navigation-long.plain.js';
import darkNav from './mocks/dark-global-navigation.plain.js';
import navigationWithCustomLinks from './mocks/navigation-with-custom-links.plain.js';
import globalNavigationMock from './mocks/global-navigation.plain.js';
import noDropdownNav from './mocks/global-navigation-no-dropdown.plain.js';
import { getConfig } from '../../../tools/send-to-caas/send-utils.js';

// TODO
Expand Down Expand Up @@ -73,6 +74,23 @@ describe('global navigation', () => {
expect(window.lana.log.getCalls().find((c) => c.args[0].includes('Sign in link not found in dropdown.'))).to.exist;
});

it('should render backup signInElem if no dropdown div is found', async () => {
const ogIms = window.adobeIMS;
const gnav = await createFullGlobalNavigation({
signedIn: false,
globalNavigation: noDropdownNav,
});
const signInElem = document.querySelector(selectors.imsSignIn);
expect(isElementVisible(signInElem)).to.equal(true);

let signInClicked = false;
window.adobeIMS = { signIn: () => { signInClicked = true; }, isSignedInUser: () => false };
await gnav.imsReady();
signInElem.click();
expect(signInClicked).to.be.true;
window.adobeIMS = ogIms;
});

it("should log when there's issues within onReady", async () => {
const ogIms = window.adobeIMS;
const gnav = await createFullGlobalNavigation({});
Expand Down
Loading

0 comments on commit e5b7867

Please sign in to comment.