Skip to content

Commit

Permalink
Adding unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Snehal Sonawane authored and Snehal Sonawane committed Dec 2, 2024
1 parent 26f55fb commit 77550e6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/blocks/global-navigation/global-navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ describe('global navigation', () => {
});
window.UniversalNav = sinon.spy(() => Promise.resolve());
window.UniversalNav.reload = sinon.spy(() => Promise.resolve());
window.adobeProfile = { getUserProfile: sinon.spy(() => Promise.resolve({})) };
// eslint-disable-next-line no-underscore-dangle
window._satellite = { track: sinon.spy() };
window.alloy = () => new Promise((resolve) => {
Expand Down Expand Up @@ -430,6 +431,22 @@ describe('global navigation', () => {
expect(window.UniversalNav.reload.getCall(0)).to.exist;
});

it('should handle message events correctly', async () => {
// eslint-disable-next-line max-len
const mockEvent = (name, payload) => ({ detail: { name, payload, executeDefaultAction: sinon.spy(() => Promise.resolve({})) } });
await createFullGlobalNavigation({ unavContent: 'on' });
const { messageEventListener } = window.UniversalNav.getCall(0).args[0].children
.find((c) => c.name === 'profile').attributes;

const appInitiatedEvent = mockEvent('System', { subType: 'AppInitiated' });
messageEventListener(appInitiatedEvent);
expect(window.adobeProfile.getUserProfile.called).to.be.true;

const signOutEvent = mockEvent('System', { subType: 'SignOut' });
messageEventListener(signOutEvent);
expect(signOutEvent.detail.executeDefaultAction.called).to.be.true;
});

it('should send the correct analytics events', async () => {
await createFullGlobalNavigation({ unavContent: 'on' });
const analyticsFn = window.UniversalNav.getCall(0)
Expand Down Expand Up @@ -484,6 +501,14 @@ describe('global navigation', () => {
expect(getUniversalNavLocale({ prefix: data.prefix })).to.equal(data.expectedLocale);
}
});

it('should pass enableProfileSwitcher to the profile component configuration', async () => {
await createFullGlobalNavigation({ unavContent: 'on' });
const profileConfig = window.UniversalNav.getCall(0).args[0].children
.find((c) => c.name === 'profile').attributes.componentLoaderConfig.config;

expect(profileConfig.enableProfileSwitcher).to.be.true;
});
});

describe('small desktop', () => {
Expand Down

0 comments on commit 77550e6

Please sign in to comment.