Skip to content

Commit

Permalink
Merge branch 'stage' into MWPW-140481-delayed-modal-stage
Browse files Browse the repository at this point in the history
  • Loading branch information
mirafedas committed Mar 7, 2024
2 parents 8fc763f + 8b1ecb3 commit 7e05127
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ const consolidateObjects = (arr, prop) => arr.reduce((propMap, item) => {
return propMap;
}, {});

const matchGlob = (searchStr, inputStr) => {
export const matchGlob = (searchStr, inputStr) => {
const pattern = searchStr.replace(/\*\*/g, '.*');
const reg = new RegExp(`^${pattern}$`, 'i'); // devtool bug needs this backtick: `
const reg = new RegExp(`^${pattern}(\\.html)?$`, 'i'); // devtool bug needs this backtick: `
return reg.test(inputStr);
};

Expand Down
24 changes: 23 additions & 1 deletion test/features/personalization/personalization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { readFile } from '@web/test-runner-commands';
import { stub } from 'sinon';
import { getConfig, setConfig, loadBlock } from '../../../libs/utils/utils.js';
import initFragments from '../../../libs/blocks/fragment/fragment.js';
import { applyPers, normalizePath, isDelayedModal } from '../../../libs/features/personalization/personalization.js';
import { applyPers, normalizePath, isDelayedModal, matchGlob } from '../../../libs/features/personalization/personalization.js';

document.head.innerHTML = await readFile({ path: './mocks/metadata.html' });
document.body.innerHTML = await readFile({ path: './mocks/personalization.html' });
Expand Down Expand Up @@ -306,3 +306,25 @@ describe('normalizePath function', () => {
expect(isDelayedModal('/fragments/path/to/fragment')).to.be.false;
});
});

describe('matchGlob function', () => {
it('should match page', async () => {
const result = matchGlob('/products/special-offers', '/products/special-offers');
expect(result).to.be.true;
});

it('should match page with HTML extension', async () => {
const result = matchGlob('/products/special-offers', '/products/special-offers.html');
expect(result).to.be.true;
});

it('should not match child page', async () => {
const result = matchGlob('/products/special-offers', '/products/special-offers/free-download');
expect(result).to.be.false;
});

it('should match child page', async () => {
const result = matchGlob('/products/special-offers**', '/products/special-offers/free-download');
expect(result).to.be.true;
});
});

0 comments on commit 7e05127

Please sign in to comment.