mediawiki-skins-MinervaNeue/tests/selenium/features/step_definitions/create_page_api_steps.js

129 lines
3.6 KiB
JavaScript
Raw Normal View History

'use strict';
const { ArticlePage } = require( '../support/world' ),
RunJobs = require( 'wdio-mediawiki/RunJobs' ),
Api = require( 'wdio-mediawiki/Api' ),
Page = require( 'wdio-mediawiki/Page' ),
MWBot = require( 'mwbot' ),
{
iAmOnPage,
waitForPropagation,
createPages,
createPage
} = require( './common_steps' );
const iAmInAWikiThatHasCategories = ( title ) => {
const msg = 'This page is used by Selenium to test category related features.',
wikitext = `
${msg}
[[Category:Test category]]
[[Category:Selenium artifacts]]
[[Category:Selenium hidden category]]
`;
createPages( [
[ 'create', 'Category:Selenium artifacts', msg ],
[ 'create', 'Category:Test category', msg ],
[ 'create', 'Category:Selenium hidden category', '__HIDDENCAT__' ]
] );
// A pause is necessary to let the categories register with database before trying to use
// them in an article
waitForPropagation( 5000 );
browser.call( async () => {
const bot = await Api.bot();
await bot.edit( title, wikitext );
} );
browser.call( () => {
// The category overlay uses the category API
// which will only return results if the job queue has completed.
// Run before continuing!
return RunJobs.run();
} );
};
const iAmOnAPageThatHasTheFollowingEdits = function ( table ) {
const randomString = Math.random().toString( 36 ).slice( 7 ),
pageTitle = `Selenium_diff_test_${randomString}`,
edits = table.rawTable.map( ( row, i ) =>
[ i === 0 ? 'create' : 'edit', pageTitle, row[ 0 ] ] );
browser.call( () => {
const bot = new MWBot();
return bot.loginGetEditToken( {
username: browser.options.username,
password: browser.options.password,
apiUrl: `${browser.options.baseUrl}/api.php`
} )
.then( () => bot.batch( edits ) )
.catch( ( err ) => { throw err; } );
} );
browser.call( () => RunJobs.run() );
ArticlePage.open( pageTitle );
};
const iGoToAPageThatHasLanguages = () => {
const wikitext = `This page is used by Selenium to test language related features.
[[es:Selenium language test page]]
`;
browser.call( () => {
createPage( 'Selenium language test page', wikitext );
} );
browser.call( () => {
iAmOnPage( 'Selenium language test page' );
} );
};
const watch = ( title ) => {
// Ideally this would use the API but mwbot / Selenium's API can't do this right now
// So we run the non-js workflow.
const page = new Page();
page.openTitle( title, { action: 'watch' } );
$( '#mw-content-text button[type="submit"]' ).waitForDisplayed();
$( '#mw-content-text button[type="submit"]' ).click();
waitForPropagation( 10000 );
page.openTitle( title );
};
const iAmViewingAWatchedPage = () => {
const title = `I am on the "Selenium mobile watched page test ${Date.now()}`;
browser.call( () => {
return createPage( title, 'watch test' );
} );
watch( title );
// navigate away from page
iAmOnPage( 'Main Page' );
waitForPropagation( 5000 );
// and back to page
iAmOnPage( title );
waitForPropagation( 5000 );
};
const iAmViewingAnUnwatchedPage = async () => {
// new pages are watchable but unwatched by default
const title = 'I am on the "Selenium mobile unwatched test ' + new Date();
await iAmOnPage( title );
};
Render talk page as a tab instead of an overlay Following up on Jon's POC, this will get rid of the talk board component in favor of linking to the server rendered talk page. Additional Changes: * Cleaned up talk selenium tests. Removed talk_steps.rb which doesn't appear to be used anymore. * Changed talk add button classes to a single class * Moved "Add discussion" button to postheadinghtml per design mock * Added "...talk-explained", "...talk-explained-empty" messages to postheadinghtml per design mock * Due to undesirable jumps in window scroll caused by the section anchor & Toggler.js code when opening the TalkSectionOverlay (read fixme in code), a Promise is always returned from OverlayManager route to reset the scroll position to the top when the section overlay is opened. * Moved "mobile-frontend-talk-fullpage", "mobile-frontend-talk-reply-success", "mobile-frontend-talk-topic-feedback", "mobile-frontend-talk-explained" "mobile-frontend-talk-explained-empty" messages to minerva as minerva is the one who initiates those messages now. * Limited $talk selector to only `.talk` elements since amc talk tab does not need to be targeted * After saving a reply from TalkSectionOverlay, the DOM that is not part of the overlay becomes out of sync since a new reply was created. To get around this, an `onSaveComplete` callback was passed (similar to the TalkSectionAddOverlay) to execute a full page refresh. Although this is clunky, it is the easiest way to resync. Bug: T230695 Depends-On: I80201394fd7015db6700446142b0b4b20829f12e Change-Id: I243f1193bce0da9fa710fc3b5379f90b2d079680
2019-10-17 22:46:07 +00:00
const iAmOnATalkPageWithNoTalkTopics = () => {
const title = `Selenium talk test ${new Date()}`;
createPage( title, 'Selenium' );
Render talk page as a tab instead of an overlay Following up on Jon's POC, this will get rid of the talk board component in favor of linking to the server rendered talk page. Additional Changes: * Cleaned up talk selenium tests. Removed talk_steps.rb which doesn't appear to be used anymore. * Changed talk add button classes to a single class * Moved "Add discussion" button to postheadinghtml per design mock * Added "...talk-explained", "...talk-explained-empty" messages to postheadinghtml per design mock * Due to undesirable jumps in window scroll caused by the section anchor & Toggler.js code when opening the TalkSectionOverlay (read fixme in code), a Promise is always returned from OverlayManager route to reset the scroll position to the top when the section overlay is opened. * Moved "mobile-frontend-talk-fullpage", "mobile-frontend-talk-reply-success", "mobile-frontend-talk-topic-feedback", "mobile-frontend-talk-explained" "mobile-frontend-talk-explained-empty" messages to minerva as minerva is the one who initiates those messages now. * Limited $talk selector to only `.talk` elements since amc talk tab does not need to be targeted * After saving a reply from TalkSectionOverlay, the DOM that is not part of the overlay becomes out of sync since a new reply was created. To get around this, an `onSaveComplete` callback was passed (similar to the TalkSectionAddOverlay) to execute a full page refresh. Although this is clunky, it is the easiest way to resync. Bug: T230695 Depends-On: I80201394fd7015db6700446142b0b4b20829f12e Change-Id: I243f1193bce0da9fa710fc3b5379f90b2d079680
2019-10-17 22:46:07 +00:00
iAmOnPage( `Talk:${title}` );
};
module.exports = {
waitForPropagation,
iAmOnAPageThatHasTheFollowingEdits,
Render talk page as a tab instead of an overlay Following up on Jon's POC, this will get rid of the talk board component in favor of linking to the server rendered talk page. Additional Changes: * Cleaned up talk selenium tests. Removed talk_steps.rb which doesn't appear to be used anymore. * Changed talk add button classes to a single class * Moved "Add discussion" button to postheadinghtml per design mock * Added "...talk-explained", "...talk-explained-empty" messages to postheadinghtml per design mock * Due to undesirable jumps in window scroll caused by the section anchor & Toggler.js code when opening the TalkSectionOverlay (read fixme in code), a Promise is always returned from OverlayManager route to reset the scroll position to the top when the section overlay is opened. * Moved "mobile-frontend-talk-fullpage", "mobile-frontend-talk-reply-success", "mobile-frontend-talk-topic-feedback", "mobile-frontend-talk-explained" "mobile-frontend-talk-explained-empty" messages to minerva as minerva is the one who initiates those messages now. * Limited $talk selector to only `.talk` elements since amc talk tab does not need to be targeted * After saving a reply from TalkSectionOverlay, the DOM that is not part of the overlay becomes out of sync since a new reply was created. To get around this, an `onSaveComplete` callback was passed (similar to the TalkSectionAddOverlay) to execute a full page refresh. Although this is clunky, it is the easiest way to resync. Bug: T230695 Depends-On: I80201394fd7015db6700446142b0b4b20829f12e Change-Id: I243f1193bce0da9fa710fc3b5379f90b2d079680
2019-10-17 22:46:07 +00:00
iAmOnATalkPageWithNoTalkTopics,
iAmViewingAWatchedPage,
iAmViewingAnUnwatchedPage,
iAmInAWikiThatHasCategories,
iGoToAPageThatHasLanguages
};