diff --git a/extension.json b/extension.json index 19dd2a8b0..fe89a4019 100644 --- a/extension.json +++ b/extension.json @@ -280,9 +280,11 @@ "tests/qunit/ve-cite/ve.ui.MWWikitextStringTransferHandler.test.js", "tests/qunit/ext.cite.referencePreviews/createReferenceGateway.test.js", "tests/qunit/ext.cite.referencePreviews/isReferencePreviewsEnabled.test.js", - "tests/qunit/ext.cite.referencePreviews/renderer.test.js" + "tests/qunit/ext.cite.referencePreviews/renderer.test.js", + "tests/qunit/ext.cite.highlighting.test.js" ], "dependencies": [ + "ext.cite.ux-enhancements", "ext.cite.visualEditor", "test.VisualEditor" ], diff --git a/tests/qunit/ext.cite.highlighting.test.js b/tests/qunit/ext.cite.highlighting.test.js new file mode 100644 index 000000000..724c01e3a --- /dev/null +++ b/tests/qunit/ext.cite.highlighting.test.js @@ -0,0 +1,67 @@ +'use strict'; + +/* eslint-disable no-jquery/no-global-selector */ +( function () { + QUnit.module( 'ext.cite.highlighting (Cite)', { + beforeEach: function () { + const $content = $( ` +
+ + [2] + + + [2] + + +
    +
  1. ^ + a + b + Named and reused +
  2. +
+
+ ` ); + $( '#qunit-fixture' ).html( $content ); + mw.hook( 'wikipage.content' ).fire( $( '#qunit-fixture' ) ); + } + } ); + + QUnit.test( 'highlights backlink in the reference list for the clicked reference', ( assert ) => { + const $content = $( '#qunit-fixture' ); + const $footnoteMarkerLink = $content.find( '#cite_ref-foo1_2-1 a' ); + const $backlink = $content.find( '#cite_note-foo1-2 sup:nth-child(2) a' ); + + $footnoteMarkerLink.trigger( 'click' ); + assert.true( $backlink.hasClass( 'mw-cite-targeted-backlink' ) ); + } ); + + QUnit.test( 'hides clickable up-arrow when jumping back from multiple used references ', ( assert ) => { + const $content = $( '#qunit-fixture' ); + const $footnoteMarkerLink = $content.find( '#cite_ref-foo1_2-1 a' ); + $footnoteMarkerLink.trigger( 'click' ); + + const $backlink = $content.find( '#cite_note-foo1-2 sup:nth-child(2) a' ); + $backlink.trigger( 'click' ); + // eslint-disable-next-line no-jquery/no-sizzle + assert.false( $backlink.is( ':visible' ) ); + } ); + + QUnit.test( 'uses the last clicked target for the clickable up arrow on multiple used references', ( assert ) => { + const $content = $( '#qunit-fixture' ); + + const $footnoteMarkerLink2 = $content.find( '#cite_ref-foo1_2-1 a' ); + const $footnoteMarkerLink1 = $content.find( '#cite_ref-foo1_2-0 a' ); + $footnoteMarkerLink2.trigger( 'click' ); + $footnoteMarkerLink1.trigger( 'click' ); + + const $backlinkToFirstMarker = $content.find( 'li#cite_note-foo1-2 a.mw-cite-up-arrow-backlink' ); + assert.strictEqual( $backlinkToFirstMarker.length, 1 ); + + // The backlink href points to the id of the last clicked ref marker + assert.strictEqual( + $backlinkToFirstMarker.attr( 'href' ), + '#cite_ref-foo1_2-0' + ); + } ); +}() );