@@ -947,6 +947,94 @@ describe("pat-inject", function () {
947947
948948 expect ( $div . contents ( ) . last ( ) . text ( ) ) . toBe ( "repl" ) ;
949949 } ) ;
950+
951+ it ( "9.1.13 - injects and scrolls to scroll target, if set." , async function ( ) {
952+ const scroll_spy = jest
953+ . spyOn ( window , "scrollTo" )
954+ . mockImplementation ( ( ) => null ) ;
955+
956+
957+ answer ( `
958+ <html>
959+ <body>
960+ <div id="source">
961+ </div>
962+ </body>
963+ </html>
964+ ` ) ;
965+
966+ document . body . innerHTML = `
967+ <html>
968+ <body>
969+ <a class="pat-inject"
970+ href="test.html"
971+ data-pat-inject="
972+ source: #source::element;
973+ target: self::element;
974+ scroll: #source;
975+ "
976+ >inject this</a>
977+ </body>
978+ </html>
979+ ` ;
980+
981+ const trigger = document . querySelector ( ".pat-inject" ) ;
982+
983+ pattern . init ( $ ( trigger ) ) ;
984+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
985+
986+ trigger . click ( ) ;
987+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
988+
989+ expect ( scroll_spy ) . toHaveBeenCalledTimes ( 1 ) ;
990+ } ) ;
991+
992+ it ( "9.1.14 - injects and scrolls to scroll target with injection results as a list of jQuery nodes." , async function ( ) {
993+ const scroll_spy = jest
994+ . spyOn ( window , "scrollTo" )
995+ . mockImplementation ( ( ) => null ) ;
996+
997+
998+ answer ( `
999+ <html>
1000+ <body>
1001+ <article id="source">
1002+ <section class="paragraph-1"></section>
1003+ <section class="paragraph-2"></section>
1004+ <section class="paragraph-3"></section>
1005+ </article>
1006+ </body>
1007+ </html>
1008+ ` ) ;
1009+
1010+ document . body . innerHTML = `
1011+ <html>
1012+ <body>
1013+ <a class="pat-inject"
1014+ href="test.html"
1015+ data-pat-inject="
1016+ source: #source;
1017+ target: self::element;
1018+ scroll: .paragraph-2;
1019+ "
1020+ >inject this</a>
1021+ </body>
1022+ </html>
1023+ ` ;
1024+
1025+ const trigger = document . querySelector ( ".pat-inject" ) ;
1026+
1027+ pattern . init ( $ ( trigger ) ) ;
1028+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1029+
1030+ trigger . click ( ) ;
1031+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
1032+
1033+ console . log ( document . body . outerHTML )
1034+
1035+ expect ( scroll_spy ) . toHaveBeenCalledTimes ( 1 ) ;
1036+ } ) ;
1037+
9501038 } ) ;
9511039
9521040 describe ( "9.2 - inject on forms" , function ( ) {
0 commit comments