Emoji favicons for the web
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: adds tests for favicon_selector

+92 -2
-1
import_map.json
··· 6 6 "preact/hooks": "https://esm.sh/preact/hooks?dev", 7 7 8 8 "deno-dom": "https://deno.land/x/deno_dom@v0.1.32-alpha/deno-dom-wasm.ts", 9 - "react-test-renderer": "https://esm.sh/react-test-renderer", 10 9 "std/asserts": "https://deno.land/std@0.138.0/testing/asserts.ts", 11 10 "std/bdd": "https://deno.land/std@0.138.0/testing/bdd.ts", 12 11 "std/mock": "https://deno.land/std@0.138.0/testing/mock.ts",
+89
source/utilities/__tests__/favicon_selector.test.ts
··· 1 + import type { Settings } from '../../models/settings.ts'; 2 + 3 + import { assertStrictEquals } from 'std/asserts'; 4 + import { describe, it } from 'std/bdd'; 5 + 6 + import { DEFAULT_SETTINGS } from '../../models/settings.ts'; 7 + import Autoselector, { AUTOSELECTOR_VERSION } from '../favicon_autoselector.ts'; 8 + import selectFavicon from '../favicon_selector.ts'; 9 + 10 + const url = 'https://fAvIolI.cOm'; 11 + const emojiId = 'tractor'; 12 + 13 + describe('matchers', () => { 14 + const settings: Settings = { ...DEFAULT_SETTINGS }; 15 + 16 + it('Should match strings, ignoring case', () => { 17 + settings.siteList = [{ matcher: 'fAvIolI.cOm', emojiId }]; 18 + const [favicon, shouldOverride] = selectFavicon(url, settings); 19 + assertStrictEquals(shouldOverride, true); 20 + assertStrictEquals(favicon?.emojiId, 'tractor'); 21 + assertStrictEquals(favicon?.matcher, 'fAvIolI.cOm'); 22 + }); 23 + 24 + it('Should match regex', () => { 25 + settings.siteList = [{ matcher: '/favi/i', emojiId }]; 26 + const matchedFavicon = selectFavicon(url, settings)[0]; 27 + 28 + settings.siteList = [{ matcher: '/favi/', emojiId }]; 29 + const noMatchFavicon = selectFavicon(url, settings)[0]; 30 + 31 + assertStrictEquals(matchedFavicon?.emojiId, 'tractor'); 32 + assertStrictEquals(matchedFavicon?.matcher, '/favi/i'); 33 + assertStrictEquals(noMatchFavicon, undefined); 34 + }); 35 + 36 + it('Should return [undefined, false] if no matches', () => { 37 + settings.siteList = []; 38 + const [favicon, shouldOverride] = selectFavicon(url, settings); 39 + 40 + assertStrictEquals(favicon, undefined); 41 + assertStrictEquals(shouldOverride, false); 42 + }); 43 + 44 + it('Should return [undefined, false] if site is ignored', () => { 45 + const favicon = { matcher: 'fAvIolI.cOm', emojiId }; 46 + settings.siteList = [favicon]; 47 + settings.ignoreList = [favicon]; 48 + settings.features.enableSiteIgnore = false; 49 + const matchedFavicon = selectFavicon(url, settings)[0]; 50 + 51 + settings.features.enableSiteIgnore = true; 52 + const noMatchFavicon = selectFavicon(url, settings)[0]; 53 + 54 + assertStrictEquals(matchedFavicon, favicon); 55 + assertStrictEquals(noMatchFavicon, undefined); 56 + }); 57 + }); 58 + 59 + describe('autoselect', () => { 60 + const autoselect = new Autoselector(AUTOSELECTOR_VERSION.UNICODE_11); 61 + const settings: Settings = { ...DEFAULT_SETTINGS }; 62 + 63 + it('Should not autoselect if no autoselect enabled', () => { 64 + settings.features.enableFaviconAutofill = false; 65 + const [favicon, shouldOverride] = selectFavicon(url, settings, autoselect); 66 + 67 + assertStrictEquals(favicon, undefined); 68 + assertStrictEquals(shouldOverride, false); 69 + }); 70 + 71 + it('Should autoselect if autoselect is enabled', () => { 72 + settings.features.enableFaviconAutofill = true; 73 + const [favicon, shouldOverride] = selectFavicon(url, settings, autoselect); 74 + 75 + assertStrictEquals(favicon?.emojiId, 'mouth'); 76 + assertStrictEquals(favicon?.matcher, 'https://fAvIolI.cOm'); 77 + assertStrictEquals(shouldOverride, false); 78 + }); 79 + 80 + it('Should override if overrideAll is enabled', () => { 81 + settings.features.enableFaviconAutofill = true; 82 + settings.features.enableOverrideAll = true; 83 + const [favicon, shouldOverride] = selectFavicon(url, settings, autoselect); 84 + 85 + assertStrictEquals(favicon?.emojiId, 'mouth'); 86 + assertStrictEquals(favicon?.matcher, 'https://fAvIolI.cOm'); 87 + assertStrictEquals(shouldOverride, true); 88 + }); 89 + });
+3 -1
source/utilities/favicon_selector.ts
··· 38 38 return regex.test(url); 39 39 } 40 40 41 - return url.toLocaleLowerCase().includes(favicon.matcher.toLocaleLowerCase()); 41 + return url.toLocaleLowerCase().includes( 42 + favicon.matcher.toLocaleLowerCase(), 43 + ); 42 44 }; 43 45 }