File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,21 @@ describe(`Script Link`, () => {
6868 } ) ;
6969 } ) ;
7070
71+ it ( 'should set the correct alternate variant when URL has query parameters' , ( ) => {
72+ const { container } = render ( < ScriptLink /> , {
73+ toggles : enabledToggleState ,
74+ service : 'serbian' ,
75+ variant : 'lat' ,
76+ pathname : '/serbian/articles/c805k05kr73o/lat?foo=bar&baz=qux' ,
77+ } ) ;
78+
79+ const scriptLink = container . querySelector ( `a[data-variant]` ) ;
80+
81+ expect ( scriptLink ?. getAttribute ( 'href' ) ) . toBe (
82+ '/serbian/articles/c805k05kr73o/cyr' ,
83+ ) ;
84+ } ) ;
85+
7186 it ( 'should not render when scriptLink toggle is off' , ( ) => {
7287 const disabledToggleState = {
7388 scriptLink : {
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ const ScriptLink = () => {
1717
1818 const pathPartsWithoutExtension = pathname
1919 . replace ( / \. [ ^ / . ] + $ / , '' ) // remove any extensions, we don't want to link to AMP pages directly
20- . split ( '/' ) ;
20+ . split ( '?' ) ?. [ 0 ] // remove any query parameters
21+ . split ( '/' ) ; // split path into parts
2122
2223 const currentVariantIndex = pathPartsWithoutExtension . indexOf (
2324 currentVariant as string ,
You can’t perform that action at this time.
0 commit comments