|
6 | 6 | isBadForMongo, |
7 | 7 | jsonStringifyExtended, |
8 | 8 | JsonVariable, |
| 9 | + markedSetNofollowLinks, |
9 | 10 | normalizeUrl, |
10 | 11 | splitFullName, |
11 | 12 | traverseObject, |
@@ -1203,4 +1204,46 @@ describe('utilities.client', () => { |
1203 | 1204 | expect(splitFullName('More Spaces Between')).toEqual(['More', 'Spaces Between']); |
1204 | 1205 | }); |
1205 | 1206 | }); |
| 1207 | + |
| 1208 | + describe('#markedSetNofollowLinks', () => { |
| 1209 | + it('should return a link without rel or target attributes for Apify links on the same hostname', () => { |
| 1210 | + const result = markedSetNofollowLinks('https://console.apify.com', 'Apify console', 'Apify Link', 'console.apify.com'); |
| 1211 | + expect(result).toBe('<a href="https://console.apify.com">Apify console</a>'); |
| 1212 | + }); |
| 1213 | + |
| 1214 | + it('should return a link with rel="noopener noreferrer" and target="_blank" for Apify links on a different hostname', () => { |
| 1215 | + const result = markedSetNofollowLinks('https://www.apify.com', 'Apify', 'Apify Link', 'different-hostname.com'); |
| 1216 | + expect(result).toBe('<a rel="noopener noreferrer" target="_blank" href="https://www.apify.com">Apify</a>'); |
| 1217 | + }); |
| 1218 | + |
| 1219 | + it('should return a link with rel="noopener noreferrer nofollow" and target="_blank" for non-Apify links', () => { |
| 1220 | + const result = markedSetNofollowLinks('https://www.example.com', 'Example', 'Example Link'); |
| 1221 | + expect(result).toBe('<a rel="noopener noreferrer nofollow" target="_blank" href="https://www.example.com">Example</a>'); |
| 1222 | + }); |
| 1223 | + |
| 1224 | + it('should return a link with rel="noopener noreferrer nofollow" and target="_blank" for invalid URLs', () => { |
| 1225 | + const result = markedSetNofollowLinks('invalid-url', 'Invalid', 'Invalid Link'); |
| 1226 | + expect(result).toBe('<a rel="noopener noreferrer nofollow" target="_blank" href="invalid-url">Invalid</a>'); |
| 1227 | + }); |
| 1228 | + |
| 1229 | + it('should handle a missing title and use the text instead', () => { |
| 1230 | + const result = markedSetNofollowLinks('https://www.apify.com', '', 'Apify Link', 'www.apify.com'); |
| 1231 | + expect(result).toBe('<a href="https://www.apify.com">Apify Link</a>'); |
| 1232 | + }); |
| 1233 | + |
| 1234 | + it('should handle a missing hostname parameter', () => { |
| 1235 | + const result = markedSetNofollowLinks('https://www.apify.com', 'Apify', 'Apify Link'); |
| 1236 | + expect(result).toBe('<a href="https://www.apify.com">Apify</a>'); |
| 1237 | + }); |
| 1238 | + |
| 1239 | + it('should treat subdomains of apify.com as Apify links', () => { |
| 1240 | + const result = markedSetNofollowLinks('https://docs.apify.com', 'Docs', 'Docs Link'); |
| 1241 | + expect(result).toBe('<a href="https://docs.apify.com">Docs</a>'); |
| 1242 | + }); |
| 1243 | + |
| 1244 | + it('should apply rel="noopener noreferrer nofollow" for links with an undefined hostname and non-Apify URLs', () => { |
| 1245 | + const result = markedSetNofollowLinks('https://example.com', 'Example', 'Example Link', undefined); |
| 1246 | + expect(result).toBe('<a rel="noopener noreferrer nofollow" target="_blank" href="https://example.com">Example</a>'); |
| 1247 | + }); |
| 1248 | + }); |
1206 | 1249 | }); |
0 commit comments