Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-bogos committed Oct 21, 2024
1 parent b2f54da commit c34086a
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion test/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ const stageDomainsMap = {
},
'.business-graybox.adobe.com': { 'business.adobe.com': 'origin' },
};
const stageDomainsMapWRegex = {
hostname: 'stage--milo--owner.hlx.page',
map: {
'^https://.*--milo--owner.hlx.page': {
'^https://www.adobe.com/acrobat': 'https://main--dc--adobecom.hlx.page',
'^https://business.adobe.com/blog': 'https://main--bacom-blog--adobecom.hlx.page',
'^https://business.adobe.com': 'https://business.stage.adobe.com',
'^https://www.adobe.com': 'origin',
},
},

};
const prodDomains = ['www.adobe.com', 'business.adobe.com', 'blog.adobe.com', 'helpx.adobe.com', 'news.adobe.com'];
const externalDomains = ['external1.com', 'external2.com'];
const ogFetch = window.fetch;
Expand Down Expand Up @@ -521,7 +533,7 @@ describe('Utils', () => {
});

describe('stageDomainsMap', () => {
it('should convert links when stageDomainsMap provided', async () => {
it('should convert links when stageDomainsMap provided without regex', async () => {
const stageConfig = {
...config,
env: { name: 'stage' },
Expand All @@ -548,6 +560,34 @@ describe('Utils', () => {
});
});

it('should convert links when stageDomainsMap provided with regex', async () => {
const { hostname, map } = stageDomainsMapWRegex;
const stageConfigWRegex = {
...config,
env: { name: 'stage' },
stageDomainsMap: map,
};

Object.entries(map).forEach(([, domainsMap]) => {
const anchors = Object.keys(domainsMap).map((d) => utils.createTag('a', { href: d.replace('^', '') }));
const externalAnchors = externalDomains.map((url) => utils.createTag('a', { href: url }));

utils.convertStageLinks({
anchors: [...anchors, ...externalAnchors],
config: stageConfigWRegex,
hostname,
href: `https://${hostname}`,
});

anchors.forEach((a, index) => {
const expectedDomain = Object.values(domainsMap)[index];
expect(a.href).to.contain(expectedDomain === 'origin' ? hostname : expectedDomain);
});

externalAnchors.forEach((a) => expect(a.href).to.equal(a.href));
});
});

it('should not convert links when no stageDomainsMap provided', async () => {
const stageConfig = {
...config,
Expand Down

0 comments on commit c34086a

Please sign in to comment.