Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MWPW-152549] BYO SUSI Options to pass in adobeIMS.signIn() #2850

Merged
merged 24 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
qiyundai marked this conversation as resolved.
Show resolved Hide resolved
});
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);
qiyundai marked this conversation as resolved.
Show resolved Hide resolved
});
}
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
Loading