mediawiki-extensions-Revisi.../tests/qunit/RevisionSlider.SliderView.test.js

64 lines
2.1 KiB
JavaScript
Raw Normal View History

( function ( mw, $ ) {
var SliderView = mw.libs.revisionSlider.SliderView,
Slider = mw.libs.revisionSlider.Slider,
RevisionList = mw.libs.revisionSlider.RevisionList,
Revision = mw.libs.revisionSlider.Revision,
startHistoryState, startHref;
QUnit.module( 'ext.RevisionSlider.SliderView' );
QUnit.testStart( function () {
startHistoryState = history.state;
startHref = window.location.href;
} );
QUnit.testDone( function () {
history.replaceState( startHistoryState, 'QUnit', startHref );
} );
Improve SliderView rendering tests Current rendering test passes but not really because test results meet expectations but rather by accident. Test revisions lacked ids, and current way of rendering revision made all revision bars have id equal to "undefined" string. That made test pass, although it is not what is expected (we expect three revisions in tests but not that three revisions have the same id, and each of them gets a pointer assigned to - the might look interesting in the browser, though). Also the test will fail as soon as the way of rendering revisions is switched to standard use of jquery's attr() instead of handcrafting the HTML in the RevisionListView class. This patch adds missing IDs to test Revisions where needed, and also set config vars that are required to render Slider properly. This also adds tests for cases where the exception is thrown. This also makes RevisionList initialization consistent. RevisionList expect to receive an array of revision data in a format that API returns. Tests provided arrays of Revision objects instead. That also works with a difference that API-like format uses "revid" as a field containing revision ID, while Revision objects use a field named "id". The way RevisionList was used in tests actually lead to have each revision initialized twice, and on the second initialization it lost its ID (due to field name difference). This changes test to provide a API-like array instead of arrays of Revision objects to RevisionList. Change-Id: I147270f28381038d05f8bcfd2317e8c269b2e458
2016-05-31 10:00:07 +00:00
QUnit.test( 'render adds the slider view with defined revisions selected', function ( assert ) {
var $container = $( '<div>' ),
view = new SliderView( new Slider( new RevisionList( [
new Revision( { revid: 1, size: 5, comment: 'Comment1', user: 'User1' } ),
new Revision( { revid: 3, size: 21, comment: 'Comment2', user: 'User2' } ),
new Revision( { revid: 37, size: 13, comment: 'Comment3', user: 'User3' } )
Improve SliderView rendering tests Current rendering test passes but not really because test results meet expectations but rather by accident. Test revisions lacked ids, and current way of rendering revision made all revision bars have id equal to "undefined" string. That made test pass, although it is not what is expected (we expect three revisions in tests but not that three revisions have the same id, and each of them gets a pointer assigned to - the might look interesting in the browser, though). Also the test will fail as soon as the way of rendering revisions is switched to standard use of jquery's attr() instead of handcrafting the HTML in the RevisionListView class. This patch adds missing IDs to test Revisions where needed, and also set config vars that are required to render Slider properly. This also adds tests for cases where the exception is thrown. This also makes RevisionList initialization consistent. RevisionList expect to receive an array of revision data in a format that API returns. Tests provided arrays of Revision objects instead. That also works with a difference that API-like format uses "revid" as a field containing revision ID, while Revision objects use a field named "id". The way RevisionList was used in tests actually lead to have each revision initialized twice, and on the second initialization it lost its ID (due to field name difference). This changes test to provide a API-like array instead of arrays of Revision objects to RevisionList. Change-Id: I147270f28381038d05f8bcfd2317e8c269b2e458
2016-05-31 10:00:07 +00:00
] ) ) ),
$revisionOld,
$revisionNew;
mw.config.set( {
wgDiffOldId: 1,
wgDiffNewId: 37
} );
view.render( $container );
Improve SliderView rendering tests Current rendering test passes but not really because test results meet expectations but rather by accident. Test revisions lacked ids, and current way of rendering revision made all revision bars have id equal to "undefined" string. That made test pass, although it is not what is expected (we expect three revisions in tests but not that three revisions have the same id, and each of them gets a pointer assigned to - the might look interesting in the browser, though). Also the test will fail as soon as the way of rendering revisions is switched to standard use of jquery's attr() instead of handcrafting the HTML in the RevisionListView class. This patch adds missing IDs to test Revisions where needed, and also set config vars that are required to render Slider properly. This also adds tests for cases where the exception is thrown. This also makes RevisionList initialization consistent. RevisionList expect to receive an array of revision data in a format that API returns. Tests provided arrays of Revision objects instead. That also works with a difference that API-like format uses "revid" as a field containing revision ID, while Revision objects use a field named "id". The way RevisionList was used in tests actually lead to have each revision initialized twice, and on the second initialization it lost its ID (due to field name difference). This changes test to provide a API-like array instead of arrays of Revision objects to RevisionList. Change-Id: I147270f28381038d05f8bcfd2317e8c269b2e458
2016-05-31 10:00:07 +00:00
assert.ok( $container.find( '.mw-revslider-revision-slider' ).length > 0 );
$revisionOld = $container.find( '.mw-revslider-revision-old' );
$revisionNew = $container.find( '.mw-revslider-revision-new' );
Improve SliderView rendering tests Current rendering test passes but not really because test results meet expectations but rather by accident. Test revisions lacked ids, and current way of rendering revision made all revision bars have id equal to "undefined" string. That made test pass, although it is not what is expected (we expect three revisions in tests but not that three revisions have the same id, and each of them gets a pointer assigned to - the might look interesting in the browser, though). Also the test will fail as soon as the way of rendering revisions is switched to standard use of jquery's attr() instead of handcrafting the HTML in the RevisionListView class. This patch adds missing IDs to test Revisions where needed, and also set config vars that are required to render Slider properly. This also adds tests for cases where the exception is thrown. This also makes RevisionList initialization consistent. RevisionList expect to receive an array of revision data in a format that API returns. Tests provided arrays of Revision objects instead. That also works with a difference that API-like format uses "revid" as a field containing revision ID, while Revision objects use a field named "id". The way RevisionList was used in tests actually lead to have each revision initialized twice, and on the second initialization it lost its ID (due to field name difference). This changes test to provide a API-like array instead of arrays of Revision objects to RevisionList. Change-Id: I147270f28381038d05f8bcfd2317e8c269b2e458
2016-05-31 10:00:07 +00:00
assert.ok( $revisionOld.length > 0 );
assert.strictEqual( $revisionOld.attr( 'data-revid' ), '1' );
Improve SliderView rendering tests Current rendering test passes but not really because test results meet expectations but rather by accident. Test revisions lacked ids, and current way of rendering revision made all revision bars have id equal to "undefined" string. That made test pass, although it is not what is expected (we expect three revisions in tests but not that three revisions have the same id, and each of them gets a pointer assigned to - the might look interesting in the browser, though). Also the test will fail as soon as the way of rendering revisions is switched to standard use of jquery's attr() instead of handcrafting the HTML in the RevisionListView class. This patch adds missing IDs to test Revisions where needed, and also set config vars that are required to render Slider properly. This also adds tests for cases where the exception is thrown. This also makes RevisionList initialization consistent. RevisionList expect to receive an array of revision data in a format that API returns. Tests provided arrays of Revision objects instead. That also works with a difference that API-like format uses "revid" as a field containing revision ID, while Revision objects use a field named "id". The way RevisionList was used in tests actually lead to have each revision initialized twice, and on the second initialization it lost its ID (due to field name difference). This changes test to provide a API-like array instead of arrays of Revision objects to RevisionList. Change-Id: I147270f28381038d05f8bcfd2317e8c269b2e458
2016-05-31 10:00:07 +00:00
assert.ok( $revisionNew.length > 0 );
assert.strictEqual( $revisionNew.attr( 'data-revid' ), '37' );
Improve SliderView rendering tests Current rendering test passes but not really because test results meet expectations but rather by accident. Test revisions lacked ids, and current way of rendering revision made all revision bars have id equal to "undefined" string. That made test pass, although it is not what is expected (we expect three revisions in tests but not that three revisions have the same id, and each of them gets a pointer assigned to - the might look interesting in the browser, though). Also the test will fail as soon as the way of rendering revisions is switched to standard use of jquery's attr() instead of handcrafting the HTML in the RevisionListView class. This patch adds missing IDs to test Revisions where needed, and also set config vars that are required to render Slider properly. This also adds tests for cases where the exception is thrown. This also makes RevisionList initialization consistent. RevisionList expect to receive an array of revision data in a format that API returns. Tests provided arrays of Revision objects instead. That also works with a difference that API-like format uses "revid" as a field containing revision ID, while Revision objects use a field named "id". The way RevisionList was used in tests actually lead to have each revision initialized twice, and on the second initialization it lost its ID (due to field name difference). This changes test to provide a API-like array instead of arrays of Revision objects to RevisionList. Change-Id: I147270f28381038d05f8bcfd2317e8c269b2e458
2016-05-31 10:00:07 +00:00
} );
QUnit.test( 'render throws an exception when no selected revisions provided', function ( assert ) {
var $container = $( '<div>' ),
view = new SliderView( new Slider( new RevisionList( [
new Revision( { revid: 1, size: 5, comment: 'Comment1', user: 'User1' } ),
new Revision( { revid: 3, size: 21, comment: 'Comment2', user: 'User2' } ),
new Revision( { revid: 37, size: 13, comment: 'Comment3', user: 'User3' } )
Improve SliderView rendering tests Current rendering test passes but not really because test results meet expectations but rather by accident. Test revisions lacked ids, and current way of rendering revision made all revision bars have id equal to "undefined" string. That made test pass, although it is not what is expected (we expect three revisions in tests but not that three revisions have the same id, and each of them gets a pointer assigned to - the might look interesting in the browser, though). Also the test will fail as soon as the way of rendering revisions is switched to standard use of jquery's attr() instead of handcrafting the HTML in the RevisionListView class. This patch adds missing IDs to test Revisions where needed, and also set config vars that are required to render Slider properly. This also adds tests for cases where the exception is thrown. This also makes RevisionList initialization consistent. RevisionList expect to receive an array of revision data in a format that API returns. Tests provided arrays of Revision objects instead. That also works with a difference that API-like format uses "revid" as a field containing revision ID, while Revision objects use a field named "id". The way RevisionList was used in tests actually lead to have each revision initialized twice, and on the second initialization it lost its ID (due to field name difference). This changes test to provide a API-like array instead of arrays of Revision objects to RevisionList. Change-Id: I147270f28381038d05f8bcfd2317e8c269b2e458
2016-05-31 10:00:07 +00:00
] ) ) );
mw.config.set( 'wgDiffOldId', null );
mw.config.set( 'wgDiffNewId', null );
Improve SliderView rendering tests Current rendering test passes but not really because test results meet expectations but rather by accident. Test revisions lacked ids, and current way of rendering revision made all revision bars have id equal to "undefined" string. That made test pass, although it is not what is expected (we expect three revisions in tests but not that three revisions have the same id, and each of them gets a pointer assigned to - the might look interesting in the browser, though). Also the test will fail as soon as the way of rendering revisions is switched to standard use of jquery's attr() instead of handcrafting the HTML in the RevisionListView class. This patch adds missing IDs to test Revisions where needed, and also set config vars that are required to render Slider properly. This also adds tests for cases where the exception is thrown. This also makes RevisionList initialization consistent. RevisionList expect to receive an array of revision data in a format that API returns. Tests provided arrays of Revision objects instead. That also works with a difference that API-like format uses "revid" as a field containing revision ID, while Revision objects use a field named "id". The way RevisionList was used in tests actually lead to have each revision initialized twice, and on the second initialization it lost its ID (due to field name difference). This changes test to provide a API-like array instead of arrays of Revision objects to RevisionList. Change-Id: I147270f28381038d05f8bcfd2317e8c269b2e458
2016-05-31 10:00:07 +00:00
assert.throws(
Improve SliderView rendering tests Current rendering test passes but not really because test results meet expectations but rather by accident. Test revisions lacked ids, and current way of rendering revision made all revision bars have id equal to "undefined" string. That made test pass, although it is not what is expected (we expect three revisions in tests but not that three revisions have the same id, and each of them gets a pointer assigned to - the might look interesting in the browser, though). Also the test will fail as soon as the way of rendering revisions is switched to standard use of jquery's attr() instead of handcrafting the HTML in the RevisionListView class. This patch adds missing IDs to test Revisions where needed, and also set config vars that are required to render Slider properly. This also adds tests for cases where the exception is thrown. This also makes RevisionList initialization consistent. RevisionList expect to receive an array of revision data in a format that API returns. Tests provided arrays of Revision objects instead. That also works with a difference that API-like format uses "revid" as a field containing revision ID, while Revision objects use a field named "id". The way RevisionList was used in tests actually lead to have each revision initialized twice, and on the second initialization it lost its ID (due to field name difference). This changes test to provide a API-like array instead of arrays of Revision objects to RevisionList. Change-Id: I147270f28381038d05f8bcfd2317e8c269b2e458
2016-05-31 10:00:07 +00:00
function () {
view.render( $container );
}
);
} );
}( mediaWiki, jQuery ) );