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 {
|
2023-11-24 09:14:15 +00:00
|
|
|
get rsMain() {
|
|
|
|
return $( '.mw-revslider-revision-slider' );
|
|
|
|
}
|
|
|
|
|
|
|
|
get rsToggleButton() {
|
|
|
|
return $( '.mw-revslider-toggle-button' );
|
|
|
|
}
|
|
|
|
|
|
|
|
get rsAutoExpandButton() {
|
|
|
|
return $( '.mw-revslider-auto-expand-button' );
|
|
|
|
}
|
|
|
|
|
|
|
|
get rsLoading() {
|
|
|
|
return $( '.mw-revslider-diff-loading' );
|
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async waitUntilLoaded() {
|
|
|
|
await this.rsLoading.waitForDisplayed( { reverse: true } );
|
2020-11-06 11:03:23 +00:00
|
|
|
}
|
2020-11-05 17:07:21 +00:00
|
|
|
|
2023-11-24 09:14:15 +00:00
|
|
|
get rsEditOlderButton() {
|
|
|
|
return $( '#differences-prevlink' );
|
|
|
|
}
|
|
|
|
|
|
|
|
get rsEditNewerButton() {
|
|
|
|
return $( '#differences-nextlink' );
|
|
|
|
}
|
|
|
|
|
|
|
|
get rsPointerOlder() {
|
|
|
|
return $( '.mw-revslider-pointer-older' );
|
|
|
|
}
|
|
|
|
|
|
|
|
get rsPointerNewer() {
|
|
|
|
return $( '.mw-revslider-pointer-newer' );
|
|
|
|
}
|
2020-11-05 17:34:38 +00:00
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async isOlderPointerOn( num ) {
|
|
|
|
return await this.rsPointerOlder.getAttribute( 'data-pos' ) === num.toString();
|
2020-11-05 17:07:21 +00:00
|
|
|
}
|
2023-11-24 09:14:15 +00:00
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async isNewerPointerOn( num ) {
|
|
|
|
return await this.rsPointerNewer.getAttribute( 'data-pos' ) === num.toString();
|
2020-11-05 17:07:21 +00:00
|
|
|
}
|
|
|
|
|
2023-11-24 09:14:15 +00:00
|
|
|
get rsSummaryOlder() {
|
|
|
|
return $( '#mw-diff-otitle3' );
|
|
|
|
}
|
|
|
|
|
|
|
|
get rsSummaryNewer() {
|
|
|
|
return $( '#mw-diff-ntitle3' );
|
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async showsOlderSummary( num ) {
|
|
|
|
const summary = await this.rsSummaryOlder.getText();
|
|
|
|
return await summary.includes( 'Summary ' + num );
|
2020-11-05 17:07:21 +00:00
|
|
|
}
|
2023-11-24 09:14:15 +00:00
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async showsNewerSummary( num ) {
|
|
|
|
const summary = await this.rsSummaryNewer.getText();
|
|
|
|
return await summary.includes( 'Summary ' + num );
|
2020-11-05 17:07:21 +00:00
|
|
|
}
|
2019-03-27 18:09:56 +00:00
|
|
|
|
2023-11-24 09:14:15 +00:00
|
|
|
get rsUserFilterBubble() {
|
|
|
|
return $( USER_BUBBLE_SELECTOR );
|
|
|
|
}
|
|
|
|
|
|
|
|
get rsTagFilterBubble() {
|
|
|
|
return $( TAG_BUBBLE_SELECTOR );
|
|
|
|
}
|
|
|
|
|
|
|
|
getRevision( num ) {
|
|
|
|
return $( '.mw-revslider-revision[data-pos="' + num + '"]' );
|
|
|
|
}
|
2019-03-27 18:09:56 +00:00
|
|
|
|
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")]'
|
|
|
|
);
|
|
|
|
}
|
2023-11-24 09:14:15 +00:00
|
|
|
|
2020-11-05 17:07:21 +00:00
|
|
|
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-11 15:20:52 +00:00
|
|
|
getTooltip( num ) {
|
|
|
|
return $( '.mw-revslider-revision-tooltip-' + num );
|
|
|
|
}
|
|
|
|
|
2023-11-24 09:14:15 +00:00
|
|
|
get backwardsArrow() {
|
|
|
|
return $( '.mw-revslider-arrow-backwards' );
|
|
|
|
}
|
|
|
|
|
|
|
|
get forwardsArrow() {
|
|
|
|
return $( '.mw-revslider-arrow-forwards' );
|
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async isBackwardsArrowDisabled() {
|
|
|
|
return await this.backwardsArrow.getAttribute( 'aria-disabled' ) === 'true';
|
2020-11-06 11:49:07 +00:00
|
|
|
}
|
2023-11-24 09:14:15 +00:00
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async isForwardsArrowDisabled() {
|
|
|
|
return await this.forwardsArrow.getAttribute( 'aria-disabled' ) === 'true';
|
2020-11-06 11:49:07 +00:00
|
|
|
}
|
2023-11-24 09:14:15 +00:00
|
|
|
|
2020-11-09 11:16:10 +00:00
|
|
|
waitForSliding() {
|
|
|
|
this.waitForAnimation( $( '.mw-revslider-revisions-container' ) );
|
|
|
|
}
|
2020-11-06 11:49:07 +00:00
|
|
|
|
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.
|
2020-11-17 09:53:46 +00:00
|
|
|
* @param {boolean} [showHelp] Display help dialog. Defaults to false.
|
2020-11-05 17:07:21 +00:00
|
|
|
*/
|
2023-03-29 20:23:48 +00:00
|
|
|
async prepareSimpleTests( num, showHelp = false ) {
|
2020-11-04 15:40:17 +00:00
|
|
|
const title = Util.getTestString( 'revisionslider-test-' );
|
2023-03-29 20:23:48 +00:00
|
|
|
await BlankPage.open();
|
|
|
|
await this.toggleHelpDialog( showHelp );
|
|
|
|
await this.addUserEditsToPage( title, num );
|
2020-11-04 15:40:17 +00:00
|
|
|
this.open( title );
|
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async prepareFilterTests() {
|
|
|
|
const title = await Util.getTestString( 'revisionslider-test-' );
|
|
|
|
await BlankPage.open();
|
|
|
|
await this.toggleHelpDialog( false );
|
|
|
|
await this.hasPageWithDifferentEdits( title );
|
|
|
|
await this.open( title );
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async openSlider() {
|
|
|
|
await this.rsToggleButton.click();
|
2021-06-13 18:50:36 +00:00
|
|
|
try {
|
2023-03-29 20:23:48 +00:00
|
|
|
await this.rsMain.waitForDisplayed( { timeout: 2500 } );
|
2021-06-13 18:50:36 +00:00
|
|
|
} catch ( e ) {
|
2023-03-29 20:23:48 +00:00
|
|
|
await this.rsToggleButton.click();
|
|
|
|
await this.rsMain.waitForDisplayed();
|
2021-06-13 18:50:36 +00:00
|
|
|
}
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
open( title ) {
|
|
|
|
super.openTitle( title, { type: 'revision', diff: '' } );
|
|
|
|
}
|
|
|
|
|
2023-11-24 09:14:15 +00:00
|
|
|
get helpDialog() {
|
|
|
|
return $( '.mw-revslider-help-dialog' );
|
|
|
|
}
|
|
|
|
|
|
|
|
get nextHelpButton() {
|
|
|
|
return $( '.mw-revslider-help-next' );
|
|
|
|
}
|
2020-11-17 09:53:46 +00:00
|
|
|
|
2019-03-27 18:09:56 +00:00
|
|
|
/**
|
|
|
|
* @param {boolean} [show] Defaults to true.
|
|
|
|
*/
|
2023-03-29 20:23:48 +00:00
|
|
|
async toggleHelpDialog( show ) {
|
2020-06-16 14:13:36 +00:00
|
|
|
const hide = ( show === false ) ? '1' : '0';
|
2023-03-29 20:23:48 +00:00
|
|
|
await browser.execute( async function ( h ) {
|
|
|
|
await 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
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async resetAutoExpand() {
|
|
|
|
await browser.execute( async function () {
|
|
|
|
await this.localStorage.setItem( 'mw-revslider-autoexpand', '0' );
|
2020-11-04 15:40:17 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2023-03-29 20:23:48 +00:00
|
|
|
async hasPageWithDifferentEdits( title ) {
|
|
|
|
await this.addUserEditsToPage( title, 2 );
|
|
|
|
await this.addTaggedOtherUserEditToPage( title );
|
|
|
|
await this.addTaggedEditToPage( title );
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
*/
|
2023-03-29 20:23:48 +00:00
|
|
|
async addUserEditsToPage( title, num ) {
|
|
|
|
await browser.call( async () => {
|
2020-11-09 10:44:12 +00:00
|
|
|
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.
|
|
|
|
*/
|
2023-03-29 20:23:48 +00:00
|
|
|
async addTaggedOtherUserEditToPage( title ) {
|
|
|
|
const otherUser = await Util.getTestString( 'User-' );
|
|
|
|
const otherUserPassword = await Util.getTestString();
|
|
|
|
await browser.call( async () => {
|
2020-05-23 19:41:28 +00:00
|
|
|
const bot = await Api.bot();
|
|
|
|
return await Api.createAccount( bot, otherUser, otherUserPassword );
|
2019-03-27 18:09:56 +00:00
|
|
|
} );
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
await browser.call( async () => {
|
2020-05-23 19:41:28 +00:00
|
|
|
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
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async dwellRevision( num ) {
|
|
|
|
await this.getRevision( num ).moveTo();
|
|
|
|
await this.getTooltip( num ).waitForDisplayed();
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async dwellTagFilterBubble() {
|
|
|
|
await $( TAG_BUBBLE_SELECTOR ).moveTo();
|
2019-03-29 18:00:27 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async abondonBubbleDwell() {
|
2019-03-27 18:09:56 +00:00
|
|
|
// make sure we do not dwell the line/bubble after clicking
|
2023-03-29 20:23:48 +00:00
|
|
|
await $( '.mw-revslider-revision-tooltip p:first-of-type' ).moveTo();
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async clickUserFilterBubble() {
|
|
|
|
await this.rsUserFilterBubble.click();
|
|
|
|
await this.abondonBubbleDwell();
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async clickTagFilterBubble() {
|
|
|
|
await this.rsTagFilterBubble.click();
|
|
|
|
await this.abondonBubbleDwell();
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async highlightsRevision( num ) {
|
|
|
|
const attr = await this.getRevision( num ).$( '..' ).getAttribute( 'class' );
|
2023-09-01 07:44:40 +00:00
|
|
|
return await attr.includes( 'mw-revslider-revision-filter-highlight' );
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async highlightsBubble( el ) {
|
|
|
|
const element = await el.getAttribute( 'class' );
|
2023-09-01 07:44:40 +00:00
|
|
|
return await element.includes( 'mw-revslider-filter-highlight-bubble' );
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
2020-11-06 11:03:23 +00:00
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async dragOlderPointerTo( num ) {
|
|
|
|
await this.rsPointerOlder.dragAndDrop( await this.getRevision( num ) );
|
2020-11-06 11:03:23 +00:00
|
|
|
}
|
2023-11-24 09:14:15 +00:00
|
|
|
|
2023-03-29 20:23:48 +00:00
|
|
|
async dragNewerPointerTo( num ) {
|
|
|
|
await this.rsPointerNewer.dragAndDrop( await this.getRevision( num ) );
|
2020-11-06 11:03:23 +00:00
|
|
|
}
|
2020-11-09 11:16:10 +00:00
|
|
|
|
|
|
|
waitForAnimation( el ) {
|
|
|
|
browser.execute( ( elem ) => {
|
|
|
|
setInterval( function () {
|
|
|
|
if ( $( elem ).filter( ':not(animated)' ) ) {
|
|
|
|
clearInterval();
|
|
|
|
}
|
|
|
|
}, 500 );
|
|
|
|
}, el );
|
2020-11-06 11:49:07 +00:00
|
|
|
}
|
2019-03-27 18:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = new DiffPage();
|