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

Fixing unit tests for branch-quick-links.js #3515

Merged
merged 1 commit into from
Jan 23, 2025
Merged
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
30 changes: 20 additions & 10 deletions test/features/branch-quick-links/branch-quick-links.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { expect } from '@esm-bundle/chai';
import sinon from 'sinon';
import processQuickLink from '../../../libs/features/branch-quick-links/branch-quick-links.js';

window.lana = { log: sinon.stub() };

describe('branch quick links', () => {
beforeEach(async () => {
window.adobePrivacy = {
Expand All @@ -18,24 +20,32 @@ describe('branch quick links', () => {
});

it('should add a class to the quick link', async () => {
window.alloy = new Promise(() => {});
const alloyS = sinon.stub(window, 'alloy');
alloyS.resolves({ identity: { ECID: '123' } });
const quickLink = document.querySelector('a');
window.alloy = () => Promise.resolve({ identity: { ECID: '123' } });
const quickLink = document.querySelector('a[href*="app.link"]');
processQuickLink(quickLink);
quickLink.href = '#';
await quickLink.click();
window.dispatchEvent(new CustomEvent('adobePrivacy:PrivacyConsent'));
window.dispatchEvent(new CustomEvent('adobePrivacy:PrivacyCustom'));
window.dispatchEvent(new CustomEvent('adobePrivacy:PrivacyReject'));
expect(quickLink.classList.contains('quick-link')).to.be.true;
alloyS.restore();
});

it('should not add ecid if alloy is undefined', async () => {
window.alloy = undefined;
const quickLink = document.querySelector('a');
it('should throw an error while fetching ecid', async () => {
window.alloy = () => Promise.reject(new Error('Error fetching ECID'));
const quickLink = document.querySelector('a[href*="app.link"]');
processQuickLink(quickLink);
quickLink.click();
expect(quickLink.href.includes('ecid')).to.be.false;
quickLink.href = '#';
await quickLink.click();
});

describe('case: alloy is undefined', async () => {
it('should not add ecid if alloy is undefined', async () => {
window.alloy = undefined;
const quickLink = document.querySelector('a');
processQuickLink(quickLink);
await quickLink.click();
expect(quickLink.href.includes('ecid')).to.be.false;
});
});
});
Loading