@@ -24,6 +24,7 @@ describe('ShareModal', () => {
2424 vi . clearAllMocks ( ) ;
2525 document . title = '' ;
2626 document . head . innerHTML = '' ;
27+ window . history . pushState ( { } , '' , '/post/test/share/?ref=mail' ) ;
2728 } ) ;
2829
2930 afterEach ( ( ) => {
@@ -190,8 +191,9 @@ describe('ShareModal', () => {
190191
191192 const linkedInLink = getByRole ( 'link' , { name : 'LinkedIn' } ) ;
192193 const linkedInUrl = new URL ( linkedInLink . getAttribute ( 'href' ) ) ;
194+ const expectedShareUrl = `${ window . location . origin } /post/test/?ref=mail` ;
193195
194- expect ( linkedInUrl . searchParams . get ( 'url' ) ) . toBe ( window . location . href ) ;
196+ expect ( linkedInUrl . searchParams . get ( 'url' ) ) . toBe ( expectedShareUrl ) ;
195197
196198 const twitterLink = getByRole ( 'link' , { name : 'X (Twitter)' } ) ;
197199 const twitterUrl = new URL ( twitterLink . getAttribute ( 'href' ) ) ;
@@ -245,7 +247,7 @@ describe('ShareModal', () => {
245247 fireEvent . click ( copyButton ) ;
246248
247249 await waitFor ( ( ) => {
248- expect ( copyTextToClipboard ) . toHaveBeenCalledWith ( window . location . href ) ;
250+ expect ( copyTextToClipboard ) . toHaveBeenCalledWith ( ` ${ window . location . origin } /post/test/?ref=mail` ) ;
249251 expect ( getByRole ( 'button' , { name : 'Copied' } ) ) . toBeInTheDocument ( ) ;
250252 } ) ;
251253
@@ -255,4 +257,20 @@ describe('ShareModal', () => {
255257 expect ( getByRole ( 'button' , { name : 'Copy link' } ) ) . toBeInTheDocument ( ) ;
256258 } ) ;
257259 } ) ;
260+
261+ test ( 'normalizes canonical share URL by removing /share suffix' , ( ) => {
262+ addHeadTag ( {
263+ tagName : 'link' ,
264+ attrs : {
265+ rel : 'canonical' ,
266+ href : 'https://example.com/post/share/?ref=test'
267+ }
268+ } ) ;
269+
270+ const { getByRole} = setup ( ) ;
271+ const twitterLink = getByRole ( 'link' , { name : 'X (Twitter)' } ) ;
272+ const twitterUrl = new URL ( twitterLink . getAttribute ( 'href' ) ) ;
273+
274+ expect ( twitterUrl . searchParams . get ( 'url' ) ) . toBe ( 'https://example.com/post/?ref=test' ) ;
275+ } ) ;
258276} ) ;
0 commit comments