2020-06-16 14:13:36 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-03-27 18:09:56 +00:00
|
|
|
const Page = require( 'wdio-mediawiki/Page' ),
|
|
|
|
Api = require( 'wdio-mediawiki/Api' ),
|
|
|
|
BlankPage = require( 'wdio-mediawiki/BlankPage' ),
|
|
|
|
Util = require( 'wdio-mediawiki/Util' ),
|
2019-03-29 18:00:27 +00:00
|
|
|
USER_BUBBLE_SELECTOR = '.mw-revslider-username-row .mw-revslider-bubble',
|
|
|
|
TAG_BUBBLE_SELECTOR = '.mw-revslider-tag-row:last-of-type .mw-revslider-bubble';
|
2019-03-27 18:09:56 +00:00
|
|
|
|
|
|
|
class DiffPage extends Page {
|
2020-05-23 19:41:28 +00:00
|
|
|
get rsMain() { return $( '.mw-revslider-revision-slider' ); }
|
|
|
|
get rsToggleButton() { return $( '.mw-revslider-toggle-button' ); }
|
2020-11-04 15:40:17 +00:00
|
|
|
get rsAutoExpandButton() { return $( '.mw-revslider-auto-expand-button' ); }
|
2020-11-05 17:07:21 +00:00
|
|
|
get rsLoading() { return $( '.mw-revslider-diff-loading' ); }
|
2020-11-06 11:03:23 +00:00
|
|
|
waitUntilLoaded() {
|
|
|
|
this.rsLoading.waitForDisplayed( { reverse: true } );
|
|
|
|
}
|
2020-11-05 17:07:21 +00:00
|
|
|
|
2020-11-05 17:34:38 +00:00
|
|
|
get rsEditOlderButton() { return $( '#differences-prevlink' ); }
|
|
|
|
get rsEditNewerButton() { return $( '#differences-nextlink' ); }
|
|
|
|
|
2020-11-05 17:07:21 +00:00
|
|
|
get rsPointerOlder() { return $( '.mw-revslider-pointer-older' ); }
|
|
|
|
get rsPointerNewer() { return $( '.mw-revslider-pointer-newer' ); }
|
|
|
|
isOlderPointerOn( num ) {
|
|
|
|
return this.rsPointerOlder.getAttribute( 'data-pos' ) === num.toString();
|
|
|
|
}
|
|
|
|
isNewerPointerOn( num ) {
|
|
|
|
return this.rsPointerNewer.getAttribute( 'data-pos' ) === num.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
get rsSummaryOlder() { return $( '#mw-diff-otitle3' ); }
|
|
|
|
get rsSummaryNewer() { return $( '#mw-diff-ntitle3' ); }
|
|
|
|
showsOlderSummary( num ) {
|
|
|
|
return this.rsSummaryOlder.getText().indexOf( 'Summary ' + num ) !== -1;
|
|
|
|
}
|
|
|
|
showsNewerSummary( num ) {
|
|
|
|
return this.rsSummaryNewer.getText().indexOf( 'Summary ' + num ) !== -1;
|
|
|
|
}
|
2019-03-27 18:09:56 +00:00
|
|
|
|
2020-05-23 19:41:28 +00:00
|
|
|
get rsUserFilterBubble() { return $( USER_BUBBLE_SELECTOR ); }
|
|
|
|
get rsTagFilterBubble() { return $( TAG_BUBBLE_SELECTOR ); }
|
2019-03-27 18:09:56 +00:00
|
|
|
|
2020-05-23 19:41:28 +00:00
|
|
|
getRevision( num ) { return $( '.mw-revslider-revision[data-pos="' + num + '"]' ); }
|
2020-11-05 17:07:21 +00:00
|
|
|
getRevisionUp( num ) {
|
|
|
|
return $(
|
|
|
|
'//div[contains(@class,"mw-revslider-revision")][@data-pos="' + num + '"]' +
|
|
|
|
'/following-sibling::div[contains(@class,"revision-wrapper-up")]'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
getRevisionDown( num ) {
|
|
|
|
return $(
|
|
|
|
'//div[contains(@class,"mw-revslider-revision")][@data-pos="' + num + '"]' +
|
|
|
|
'/following-sibling::div[contains(@class,"revision-wrapper-down")]'
|
|
|
|
);
|
|
|
|
}
|
2019-03-27 18:09:56 +00:00
|
|
|
|
2020-11-06 11:49:07 +00:00
|
|
|
get backwardsArrow() { return $( '.mw-revslider-arrow-backwards' ); }
|
|
|
|
get forwardsArrow() { return $( '.mw-revslider-arrow-forwards' ); }
|
|
|
|
isBackwardsArrowDisabled() {
|
|
|
|
return this.backwardsArrow.getAttribute( 'aria-disabled' ) === 'true';
|
|
|
|
}
|
|
|
|
isForwardsArrowDisabled() {
|
|
|
|
return this.forwardsArrow.getAttribute( 'aria-disabled' ) === 'true';
|
|
|
|
}
|
|
|
|
|
2019-03-27 18:09:56 +00:00
|
|
|
ready() {
|
2019-10-23 15:50:21 +00:00
|
|
|
Util.waitForModuleState( 'ext.RevisionSlider.lazyJs' );
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 17:07:21 +00:00
|
|
|
/**
|
|
|
|
* @param {number} num Number of different edits.
|
|
|
|
*/
|
|
|
|
prepareSimpleTests( num ) {
|
2020-11-04 15:40:17 +00:00
|
|
|
const title = Util.getTestString( 'revisionslider-test-' );
|
|
|
|
BlankPage.open();
|
|
|
|
this.toggleHelpDialog( false );
|
2020-11-05 17:07:21 +00:00
|
|
|
this.addUserEditsToPage( title, num );
|
2020-11-04 15:40:17 +00:00
|
|
|
this.open( title );
|
|
|
|
}
|
|
|
|
|
2019-03-27 18:09:56 +00:00
|
|
|
prepareFilterTests() {
|
2019-10-23 15:46:39 +00:00
|
|
|
const title = Util.getTestString( 'revisionslider-test-' );
|
2019-03-27 18:09:56 +00:00
|
|
|
BlankPage.open();
|
|
|
|
this.toggleHelpDialog( false );
|
|
|
|
this.hasPageWithDifferentEdits( title );
|
|
|
|
this.open( title );
|
|
|
|
}
|
|
|
|
|
|
|
|
openSlider() {
|
|
|
|
this.rsToggleButton.click();
|
2020-05-23 19:41:28 +00:00
|
|
|
this.rsMain.waitForDisplayed( { timeout: 10000 } );
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
open( title ) {
|
|
|
|
super.openTitle( title, { type: 'revision', diff: '' } );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {boolean} [show] Defaults to true.
|
|
|
|
*/
|
|
|
|
toggleHelpDialog( show ) {
|
2020-06-16 14:13:36 +00:00
|
|
|
const hide = ( show === false ) ? '1' : '0';
|
2020-09-11 15:28:52 +00:00
|
|
|
browser.execute( function ( h ) {
|
|
|
|
this.localStorage.setItem( 'mw-revslider-hide-help-dialogue', h );
|
2020-05-23 19:41:28 +00:00
|
|
|
}, hide );
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 15:40:17 +00:00
|
|
|
resetAutoExpand() {
|
|
|
|
browser.execute( function () {
|
|
|
|
this.localStorage.setItem( 'mw-revslider-autoexpand', '0' );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2019-03-27 18:09:56 +00:00
|
|
|
/**
|
|
|
|
* Will setup a test page with two user edits, one anonymous edit
|
|
|
|
* and a tagged.
|
|
|
|
*
|
|
|
|
* @param {string} title Article to edit.
|
|
|
|
*/
|
|
|
|
hasPageWithDifferentEdits( title ) {
|
2020-11-04 12:49:30 +00:00
|
|
|
this.addUserEditsToPage( title, 2 );
|
2019-03-27 18:09:56 +00:00
|
|
|
this.addTaggedOtherUserEditToPage( title );
|
|
|
|
this.addTaggedEditToPage( title );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} title Article to edit.
|
2020-11-04 12:49:30 +00:00
|
|
|
* @param {number} num Number of different edits to add.
|
2019-03-27 18:09:56 +00:00
|
|
|
*/
|
2020-11-04 12:49:30 +00:00
|
|
|
addUserEditsToPage( title, num ) {
|
2020-11-09 10:44:12 +00:00
|
|
|
browser.call( async () => {
|
|
|
|
const bot = await Api.bot();
|
|
|
|
for ( let i = 1; i <= num; i++ ) {
|
|
|
|
await bot.edit(
|
2020-11-04 12:49:30 +00:00
|
|
|
title,
|
2020-11-05 17:07:21 +00:00
|
|
|
'RevisionSlider-Test-Text ' + i,
|
|
|
|
'RevisionSlider-Test-Summary ' + i
|
2020-11-04 12:49:30 +00:00
|
|
|
);
|
2020-11-09 10:44:12 +00:00
|
|
|
}
|
|
|
|
} );
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} title Article to edit.
|
|
|
|
*/
|
|
|
|
addTaggedEditToPage( title ) {
|
2020-06-16 14:13:36 +00:00
|
|
|
browser.call( async () => {
|
|
|
|
const bot = await Api.bot();
|
2020-11-04 12:39:58 +00:00
|
|
|
return bot.edit(
|
2020-05-23 19:41:28 +00:00
|
|
|
title,
|
|
|
|
'',
|
|
|
|
'RevisionSlider-Test-Tagged',
|
|
|
|
{ tags: 'mw-blank' }
|
|
|
|
);
|
2019-03-27 18:09:56 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} title Article to edit.
|
|
|
|
*/
|
|
|
|
addTaggedOtherUserEditToPage( title ) {
|
2019-10-23 15:46:39 +00:00
|
|
|
const otherUser = Util.getTestString( 'User-' );
|
|
|
|
const otherUserPassword = Util.getTestString();
|
2020-05-23 19:41:28 +00:00
|
|
|
browser.call( async () => {
|
|
|
|
const bot = await Api.bot();
|
|
|
|
return await Api.createAccount( bot, otherUser, otherUserPassword );
|
2019-03-27 18:09:56 +00:00
|
|
|
} );
|
|
|
|
|
2020-05-23 19:41:28 +00:00
|
|
|
browser.call( async () => {
|
|
|
|
const bot = await Api.bot( otherUser, otherUserPassword );
|
2020-11-04 12:39:58 +00:00
|
|
|
return bot.edit(
|
2020-05-23 19:41:28 +00:00
|
|
|
title,
|
|
|
|
'RevisionSlider-Test-Other-Text with tag',
|
|
|
|
'RevisionSlider-Test-Other-Tagged',
|
|
|
|
{ tags: 'mw-replace' }
|
|
|
|
);
|
|
|
|
|
2019-03-27 18:09:56 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
dwellRevision( num ) {
|
2020-05-23 19:41:28 +00:00
|
|
|
$( '.mw-revslider-revision[data-pos="' + num + '"]' ).moveTo();
|
|
|
|
$( '.mw-revslider-revision-tooltip-' + num ).waitForDisplayed();
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 18:00:27 +00:00
|
|
|
dwellTagFilterBubble() {
|
2020-05-23 19:41:28 +00:00
|
|
|
$( TAG_BUBBLE_SELECTOR ).moveTo();
|
2019-03-29 18:00:27 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 18:09:56 +00:00
|
|
|
abondonBubbleDwell() {
|
|
|
|
// make sure we do not dwell the line/bubble after clicking
|
2020-05-23 19:41:28 +00:00
|
|
|
$( '.mw-revslider-revision-tooltip p:first-of-type' ).moveTo();
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clickUserFilterBubble() {
|
|
|
|
this.rsUserFilterBubble.click();
|
|
|
|
this.abondonBubbleDwell();
|
|
|
|
}
|
|
|
|
|
|
|
|
clickTagFilterBubble() {
|
|
|
|
this.rsTagFilterBubble.click();
|
|
|
|
this.abondonBubbleDwell();
|
|
|
|
}
|
|
|
|
|
|
|
|
highlightsRevision( num ) {
|
|
|
|
return this.getRevision( num ).$( '..' )
|
|
|
|
.getAttribute( 'class' ).indexOf( 'mw-revslider-revision-highlight' ) !== -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
highlightsBubble( el ) {
|
|
|
|
return el.getAttribute( 'class' ).indexOf( 'mw-revslider-highlite-bubble' ) !== -1;
|
|
|
|
}
|
2020-11-06 11:03:23 +00:00
|
|
|
|
|
|
|
dragOlderPointerTo( num ) {
|
|
|
|
$( '.mw-revslider-pointer-older' )
|
|
|
|
.dragAndDrop( this.getRevision( num ) );
|
|
|
|
}
|
|
|
|
dragNewerPointerTo( num ) {
|
|
|
|
$( '.mw-revslider-pointer-newer' )
|
|
|
|
.dragAndDrop( this.getRevision( num ) );
|
|
|
|
}
|
2020-11-06 11:49:07 +00:00
|
|
|
waitForSliding() {
|
|
|
|
// Roundabout way of detecting when the animation has stopped, by checking for a
|
|
|
|
// side-effect performed at the end of animation. See ext.RevisionSlider.SliderView .
|
|
|
|
browser.waitUntil(
|
|
|
|
() => !$( '.mw-revslider-pointer-newer.ui-draggable-disabled' ).isDisplayed()
|
|
|
|
);
|
|
|
|
// Hopefully avoid a race condition while the animation completion callback finishes.
|
|
|
|
browser.pause( 100 );
|
|
|
|
}
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = new DiffPage();
|