11import { describe , expect , it } from 'vitest' ;
22import { createDefaultScheme } from '../../../src/domain/scheme/scheme-defaults' ;
33import {
4+ buildFacebookShareHref ,
5+ buildLinkedInShareHref ,
46 buildShareUrl ,
57 buildTwitterShareHref ,
68 defaultShareBaseUrl ,
@@ -23,7 +25,7 @@ describe('share-urls', () => {
2325 ) ;
2426 } ) ;
2527
26- it ( 'builds a twitter intent link with the share text and encoded URL' , ( ) => {
28+ it ( 'builds a twitter intent link with the encoded URL' , ( ) => {
2729 const scheme = createDefaultScheme ( ) ;
2830 scheme . dyeScope = 'all' ;
2931
@@ -35,10 +37,48 @@ describe('share-urls', () => {
3537
3638 expect ( `${ url . origin } ${ url . pathname } ` ) . toBe ( 'https://twitter.com/intent/tweet' ) ;
3739 expect ( url . searchParams . get ( 'text' ) ) . toBe ( SHARE_TEXT ) ;
40+ expect ( url . searchParams . get ( 'url' ) ) . toBe ( 'https://ciembor.github.io/4bit/?dyeScope=all' ) ;
3841 expect ( url . searchParams . get ( 'via' ) ) . toBe ( 'ciembor' ) ;
42+ } ) ;
43+
44+ it ( 'falls back to the public share URL when current location is local' , ( ) => {
45+ const scheme = createDefaultScheme ( ) ;
46+ scheme . dyeScope = 'all' ;
47+
48+ expect ( buildShareUrl ( scheme , {
49+ origin : 'http://localhost:5173' ,
50+ pathname : '/' ,
51+ } ) ) . toBe ( 'https://ciembor.github.io/4bit/?dyeScope=all' ) ;
52+ } ) ;
53+
54+ it ( 'builds a linkedin share link with the encoded URL' , ( ) => {
55+ const scheme = createDefaultScheme ( ) ;
56+ scheme . dyeScope = 'all' ;
57+
58+ const href = buildLinkedInShareHref ( scheme , {
59+ origin : 'https://ciembor.github.io' ,
60+ pathname : '/4bit/' ,
61+ } ) ;
62+ const url = new URL ( href ) ;
63+
64+ expect ( `${ url . origin } ${ url . pathname } ` ) . toBe ( 'https://www.linkedin.com/sharing/share-offsite/' ) ;
3965 expect ( url . searchParams . get ( 'url' ) ) . toBe ( 'https://ciembor.github.io/4bit/?dyeScope=all' ) ;
4066 } ) ;
4167
68+ it ( 'builds a facebook share link with the encoded URL' , ( ) => {
69+ const scheme = createDefaultScheme ( ) ;
70+ scheme . dyeScope = 'all' ;
71+
72+ const href = buildFacebookShareHref ( scheme , {
73+ origin : 'https://ciembor.github.io' ,
74+ pathname : '/4bit/' ,
75+ } ) ;
76+ const url = new URL ( href ) ;
77+
78+ expect ( `${ url . origin } ${ url . pathname } ` ) . toBe ( 'https://www.facebook.com/sharer/sharer.php' ) ;
79+ expect ( url . searchParams . get ( 'u' ) ) . toBe ( 'https://ciembor.github.io/4bit/?dyeScope=all' ) ;
80+ } ) ;
81+
4282 it ( 'uses the production share URL defaults when location is unavailable' , ( ) => {
4383 expect ( buildShareUrl ( createDefaultScheme ( ) ) ) . toBe ( 'https://ciembor.github.io/4bit/' ) ;
4484 expect ( defaultShareBaseUrl ( ) ) . toBe ( 'https://ciembor.github.io/4bit/' ) ;
0 commit comments