|
| 1 | +/* |
| 2 | + * Copyright 2025 Adobe. All rights reserved. |
| 3 | + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | + * of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | + * OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | + * governing permissions and limitations under the License. |
| 11 | + */ |
| 12 | + |
| 13 | +/* eslint-env mocha */ |
| 14 | + |
| 15 | +import { expect } from 'chai'; |
| 16 | +import { isDynamicPageUrl, filterOutDynamicUrls } from '../../../src/summarization/dynamic-content-filter.js'; |
| 17 | + |
| 18 | +describe('summarization dynamic-content-filter', () => { |
| 19 | + describe('isDynamicPageUrl', () => { |
| 20 | + it('returns false for empty or non-string', () => { |
| 21 | + expect(isDynamicPageUrl('')).to.be.false; |
| 22 | + expect(isDynamicPageUrl(null)).to.be.false; |
| 23 | + expect(isDynamicPageUrl(undefined)).to.be.false; |
| 24 | + expect(isDynamicPageUrl(123)).to.be.false; |
| 25 | + }); |
| 26 | + |
| 27 | + it('returns false for static content URLs', () => { |
| 28 | + expect(isDynamicPageUrl('https://example.com/')).to.be.false; |
| 29 | + expect(isDynamicPageUrl('https://example.com/about')).to.be.false; |
| 30 | + expect(isDynamicPageUrl('https://example.com/products/shoes')).to.be.false; |
| 31 | + expect(isDynamicPageUrl('/blog/post-1')).to.be.false; |
| 32 | + }); |
| 33 | + |
| 34 | + it('returns true for URLs with dynamic path segments', () => { |
| 35 | + expect(isDynamicPageUrl('https://example.com/search')).to.be.true; |
| 36 | + expect(isDynamicPageUrl('https://example.com/search?q=foo')).to.be.true; |
| 37 | + expect(isDynamicPageUrl('https://example.com/cart')).to.be.true; |
| 38 | + expect(isDynamicPageUrl('https://example.com/checkout')).to.be.true; |
| 39 | + expect(isDynamicPageUrl('https://example.com/login')).to.be.true; |
| 40 | + expect(isDynamicPageUrl('https://example.com/account')).to.be.true; |
| 41 | + expect(isDynamicPageUrl('https://example.com/admin')).to.be.true; |
| 42 | + expect(isDynamicPageUrl('https://example.com/feed')).to.be.true; |
| 43 | + expect(isDynamicPageUrl('https://example.com/dashboard')).to.be.true; |
| 44 | + expect(isDynamicPageUrl('https://example.com/filter/category')).to.be.true; |
| 45 | + expect(isDynamicPageUrl('/api/users')).to.be.true; |
| 46 | + }); |
| 47 | + |
| 48 | + it('matches segment case-insensitively', () => { |
| 49 | + expect(isDynamicPageUrl('https://example.com/SEARCH')).to.be.true; |
| 50 | + expect(isDynamicPageUrl('https://example.com/Cart')).to.be.true; |
| 51 | + }); |
| 52 | + |
| 53 | + it('matches segment anywhere in path', () => { |
| 54 | + expect(isDynamicPageUrl('https://example.com/shop/cart')).to.be.true; |
| 55 | + expect(isDynamicPageUrl('https://example.com/help/search')).to.be.true; |
| 56 | + }); |
| 57 | + |
| 58 | + it('returns false for invalid URL when used as path', () => { |
| 59 | + expect(isDynamicPageUrl('not-a-url')).to.be.false; |
| 60 | + }); |
| 61 | + |
| 62 | + it('returns false for invalid full URL (URL constructor throws)', () => { |
| 63 | + expect(isDynamicPageUrl('https://')).to.be.false; |
| 64 | + expect(isDynamicPageUrl('http://[')).to.be.false; |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + describe('filterOutDynamicUrls', () => { |
| 69 | + it('returns empty array for non-array input', () => { |
| 70 | + expect(filterOutDynamicUrls(null)).to.deep.equal([]); |
| 71 | + expect(filterOutDynamicUrls(undefined)).to.deep.equal([]); |
| 72 | + }); |
| 73 | + |
| 74 | + it('keeps only static URLs and preserves order', () => { |
| 75 | + const urls = [ |
| 76 | + 'https://example.com/', |
| 77 | + 'https://example.com/search', |
| 78 | + 'https://example.com/about', |
| 79 | + 'https://example.com/cart', |
| 80 | + 'https://example.com/products', |
| 81 | + ]; |
| 82 | + expect(filterOutDynamicUrls(urls)).to.deep.equal([ |
| 83 | + 'https://example.com/', |
| 84 | + 'https://example.com/about', |
| 85 | + 'https://example.com/products', |
| 86 | + ]); |
| 87 | + }); |
| 88 | + |
| 89 | + it('returns all URLs when none are dynamic', () => { |
| 90 | + const urls = ['https://example.com/', 'https://example.com/about', 'https://example.com/contact']; |
| 91 | + expect(filterOutDynamicUrls(urls)).to.deep.equal(urls); |
| 92 | + }); |
| 93 | + |
| 94 | + it('returns empty array when all URLs are dynamic', () => { |
| 95 | + const urls = ['https://example.com/search', 'https://example.com/cart', 'https://example.com/login']; |
| 96 | + expect(filterOutDynamicUrls(urls)).to.deep.equal([]); |
| 97 | + }); |
| 98 | + }); |
| 99 | +}); |
0 commit comments