mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

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

at profile-init 134 lines 4.4 kB view raw
1import { 2 linkRequiresWarning, 3 isPossiblyAUrl, 4 splitApexDomain, 5} from '../../../src/lib/strings/url-helpers' 6 7describe('linkRequiresWarning', () => { 8 type Case = [string, string, boolean] 9 const cases: Case[] = [ 10 ['http://example.com', 'http://example.com', false], 11 ['http://example.com', 'example.com', false], 12 ['http://example.com', 'example.com/page', false], 13 ['http://example.com', '', true], 14 ['http://example.com', 'other.com', true], 15 ['http://example.com', 'http://other.com', true], 16 ['http://example.com', 'some label', true], 17 ['http://example.com', 'example.com more', true], 18 ['http://example.com', 'http://example.co', true], 19 ['http://example.co', 'http://example.com', true], 20 ['http://example.com', 'example.co', true], 21 ['http://example.co', 'example.com', true], 22 ['http://site.pages.dev', 'http://site.page', true], 23 ['http://site.page', 'http://site.pages.dev', true], 24 ['http://site.pages.dev', 'site.page', true], 25 ['http://site.page', 'site.pages.dev', true], 26 ['http://site.pages.dev', 'http://site.pages', true], 27 ['http://site.pages', 'http://site.pages.dev', true], 28 ['http://site.pages.dev', 'site.pages', true], 29 ['http://site.pages', 'site.pages.dev', true], 30 ['http://bsky.app/profile/bob.test/post/3kbeuduu7m22v', 'my post', false], 31 ['https://bsky.app/profile/bob.test/post/3kbeuduu7m22v', 'my post', false], 32 ['http://bsky.app/', 'bluesky', false], 33 ['https://bsky.app/', 'bluesky', false], 34 [ 35 'http://bsky.app/profile/bob.test/post/3kbeuduu7m22v', 36 'http://bsky.app/profile/bob.test/post/3kbeuduu7m22v', 37 false, 38 ], 39 [ 40 'https://bsky.app/profile/bob.test/post/3kbeuduu7m22v', 41 'http://bsky.app/profile/bob.test/post/3kbeuduu7m22v', 42 false, 43 ], 44 [ 45 'http://bsky.app/', 46 'http://bsky.app/profile/bob.test/post/3kbeuduu7m22v', 47 false, 48 ], 49 [ 50 'https://bsky.app/', 51 'http://bsky.app/profile/bob.test/post/3kbeuduu7m22v', 52 false, 53 ], 54 [ 55 'http://bsky.app/profile/bob.test/post/3kbeuduu7m22v', 56 'https://google.com', 57 true, 58 ], 59 [ 60 'https://bsky.app/profile/bob.test/post/3kbeuduu7m22v', 61 'https://google.com', 62 true, 63 ], 64 ['http://bsky.app/', 'https://google.com', true], 65 ['https://bsky.app/', 'https://google.com', true], 66 67 // bad uri inputs, default to true 68 ['', '', true], 69 ['example.com', 'example.com', true], 70 ] 71 72 it.each(cases)( 73 'given input uri %p and text %p, returns %p', 74 (uri, text, expected) => { 75 const output = linkRequiresWarning(uri, text) 76 expect(output).toEqual(expected) 77 }, 78 ) 79}) 80 81describe('isPossiblyAUrl', () => { 82 type Case = [string, boolean] 83 const cases: Case[] = [ 84 ['', false], 85 ['text', false], 86 ['some text', false], 87 ['some text', false], 88 ['some domain.com', false], 89 ['domain.com', true], 90 [' domain.com', true], 91 ['domain.com ', true], 92 [' domain.com ', true], 93 ['http://domain.com', true], 94 [' http://domain.com', true], 95 ['http://domain.com ', true], 96 [' http://domain.com ', true], 97 ['https://domain.com', true], 98 [' https://domain.com', true], 99 ['https://domain.com ', true], 100 [' https://domain.com ', true], 101 ['http://domain.com/foo', true], 102 ['http://domain.com stuff', true], 103 ] 104 105 it.each(cases)('given input uri %p, returns %p', (str, expected) => { 106 const output = isPossiblyAUrl(str) 107 expect(output).toEqual(expected) 108 }) 109}) 110 111describe('splitApexDomain', () => { 112 type Case = [string, string, string] 113 const cases: Case[] = [ 114 ['', '', ''], 115 ['example.com', '', 'example.com'], 116 ['foo.example.com', 'foo.', 'example.com'], 117 ['foo.bar.example.com', 'foo.bar.', 'example.com'], 118 ['example.co.uk', '', 'example.co.uk'], 119 ['foo.example.co.uk', 'foo.', 'example.co.uk'], 120 ['example.nonsense', '', 'example.nonsense'], 121 ['foo.example.nonsense', '', 'foo.example.nonsense'], 122 ['foo.bar.example.nonsense', '', 'foo.bar.example.nonsense'], 123 ['example.com.example.com', 'example.com.', 'example.com'], 124 ] 125 126 it.each(cases)( 127 'given input uri %p, returns %p,%p', 128 (str, expected1, expected2) => { 129 const output = splitApexDomain(str) 130 expect(output[0]).toEqual(expected1) 131 expect(output[1]).toEqual(expected2) 132 }, 133 ) 134})