mediawiki-extensions-Revisi.../tests/qunit/RevisionSlider.DiffPage.test.js
WMDE-Fisch 37dc0b5adb [QUnit] Avoid manipulating the global history
Also introducing sinon to mock some parts.

Bug: T370573
Change-Id: I5a7573bcac9501a7b37a12b86bb0d4f46055f70e
2024-07-23 22:19:58 +02:00

34 lines
946 B
JavaScript

QUnit.module( 'ext.RevisionSlider.DiffPage' );
QUnit.test( 'Push state', () => {
const SliderModule = require( 'ext.RevisionSlider.Slider' ),
DiffPage = SliderModule.DiffPage;
const historyStub = { pushState: sinon.spy() };
const sliderStub = { getOldestVisibleRevisionIndex: sinon.stub().returns( 42 ) };
const pointerStub = { getPosition: sinon.stub().returns( 5 ) };
const sliderViewStub = {
pointerOlder: pointerStub,
pointerNewer: pointerStub,
slider: sliderStub
};
const diffPage = new DiffPage( historyStub );
mw.config.set( {
wgDiffOldId: 1,
wgDiffNewId: 37
} );
diffPage.pushState( 3, 37, sliderViewStub );
sinon.assert.calledWith(
historyStub.pushState,
{ diff: 3, oldid: 37, pointerNewerPos: 5, pointerOlderPos: 5, sliderPos: 42 },
sinon.match.any,
sinon.match.any
);
sinon.assert.calledOnce( sliderStub.getOldestVisibleRevisionIndex );
sinon.assert.calledTwice( pointerStub.getPosition );
} );