2020-05-14 21:14:42 +00:00
'use strict' ;
2019-10-01 01:36:15 +00:00
const assert = require ( 'assert' ) ;
const Api = require ( 'wdio-mediawiki/Api' ) ;
const DeletePage = require ( '../pageobjects/delete.page' ) ;
const RestorePage = require ( '../pageobjects/restore.page' ) ;
const EditPage = require ( '../pageobjects/edit.page' ) ;
const HistoryPage = require ( '../pageobjects/history.page' ) ;
const UndoPage = require ( '../pageobjects/undo.page' ) ;
2021-06-07 17:57:28 +00:00
const ProtectPage = require ( '../pageobjects/protect.page' ) ;
2019-10-01 01:36:15 +00:00
const UserLoginPage = require ( 'wdio-mediawiki/LoginPage' ) ;
const Util = require ( 'wdio-mediawiki/Util' ) ;
2016-12-19 16:39:29 +00:00
describe ( 'Page' , function ( ) {
2019-10-01 01:36:15 +00:00
let content , name , bot ;
2016-12-19 16:39:29 +00:00
selenium: Fix more inefficient MWBot use and simplify wdio-mediawiki Api
This does the same for the other specs, as previously done to the
page.js spec in 058d5b7cd857af.
* rollkback: From 6 api logins to 4 api logins.
Before (2x3): admin for edit, admin for createaccount, vandal for edit.
After (2x2): admin for edit + createaccount, vandal for edit.
* recentchanges spec: No difference, but updated pattern for consistency
so that if it is extended in the future, it will be natural to re-use
the bot object instead of creating a new one.
* watchlist spec: From 3 api logins to 1 api login.
Before: admin for createaccount, admin for edit, admin for edit.
After: admin (re-used)
* user spec: From 2 to 1 api login.
Also:
* Remove the now-unused Api.edit() and Api.delete() anti-pattern
methods, as these are nothing but one-line shortcuts to the
already one-line invocation of bot.edit() and bot.delete(),
except that they bypassed the current bot object, causing
inefficient repeat logins in way that was non-obvious.
Migration is simple and won't be required until other repos
upgrade to the next wdio-mediawiki version (not yet released).
* Make 'bot' a mandatory parameter for the createAccount, block,
and unblock convenience wrapper methods.
* Move the vandalizePage() method from HistoryPage to rollback spec,
as it had no connection with that page object or the action=history
interface, and document why it can't (yet) re-use its bot object.
Bug: T234002
Change-Id: Id6e995916566f7dd7b618892295198b897fbee2e
2019-10-01 02:10:05 +00:00
before ( async ( ) => {
2019-09-29 03:24:47 +00:00
bot = await Api . bot ( ) ;
2017-07-05 11:52:47 +00:00
} ) ;
2016-12-19 16:39:29 +00:00
beforeEach ( function ( ) {
2019-09-27 03:08:00 +00:00
browser . deleteAllCookies ( ) ;
2018-06-20 11:06:45 +00:00
content = Util . getTestString ( 'beforeEach-content-' ) ;
name = Util . getTestString ( 'BeforeEach-name-' ) ;
2016-12-19 16:39:29 +00:00
} ) ;
2018-11-29 18:04:31 +00:00
it ( 'should be previewable' , function ( ) {
EditPage . preview ( name , content ) ;
assert . strictEqual ( EditPage . heading . getText ( ) , 'Creating ' + name ) ;
assert . strictEqual ( EditPage . displayedContent . getText ( ) , content ) ;
2019-09-27 03:08:00 +00:00
assert ( EditPage . content . isDisplayed ( ) , 'editor is still present' ) ;
assert ( ! EditPage . conflictingContent . isDisplayed ( ) , 'no edit conflict happened' ) ;
2021-02-25 15:58:25 +00:00
// T269566: Popup with text
// 'Leave site? Changes that you made may not be saved. Cancel/Leave'
// appears after the browser tries to leave the page with the preview.
browser . reloadSession ( ) ;
2018-11-29 18:04:31 +00:00
} ) ;
2016-12-19 16:39:29 +00:00
it ( 'should be creatable' , function ( ) {
// create
EditPage . edit ( name , content ) ;
// check
2018-06-06 10:49:33 +00:00
assert . strictEqual ( EditPage . heading . getText ( ) , name ) ;
assert . strictEqual ( EditPage . displayedContent . getText ( ) , content ) ;
2016-12-19 16:39:29 +00:00
} ) ;
2018-01-13 14:06:39 +00:00
it ( 'should be re-creatable' , function ( ) {
2019-07-05 19:38:29 +00:00
const initialContent = Util . getTestString ( 'initialContent-' ) ;
2018-01-13 14:06:39 +00:00
2019-09-29 03:24:47 +00:00
// create and delete
browser . call ( async ( ) => {
await bot . edit ( name , initialContent , 'create for delete' ) ;
await bot . delete ( name , 'delete prior to recreate' ) ;
2018-01-13 14:06:39 +00:00
} ) ;
2019-09-29 03:24:47 +00:00
// re-create
2018-01-13 14:06:39 +00:00
EditPage . edit ( name , content ) ;
// check
2018-06-06 10:49:33 +00:00
assert . strictEqual ( EditPage . heading . getText ( ) , name ) ;
assert . strictEqual ( EditPage . displayedContent . getText ( ) , content ) ;
2018-01-13 14:06:39 +00:00
} ) ;
2018-09-04 09:27:01 +00:00
it ( 'should be editable @daily' , function ( ) {
2016-12-19 16:39:29 +00:00
// create
2019-09-29 03:24:47 +00:00
browser . call ( async ( ) => {
await bot . edit ( name , content , 'create for edit' ) ;
2017-05-08 10:10:18 +00:00
} ) ;
2016-12-19 16:39:29 +00:00
// edit
2019-07-05 19:38:29 +00:00
const editContent = Util . getTestString ( 'editContent-' ) ;
2018-06-08 12:11:38 +00:00
EditPage . edit ( name , editContent ) ;
2016-12-19 16:39:29 +00:00
2017-05-08 10:10:18 +00:00
// check
2018-06-06 10:49:33 +00:00
assert . strictEqual ( EditPage . heading . getText ( ) , name ) ;
2019-04-12 09:57:46 +00:00
assert ( EditPage . displayedContent . getText ( ) . includes ( editContent ) ) ;
2016-12-19 16:39:29 +00:00
} ) ;
2018-09-04 09:27:01 +00:00
it ( 'should have history @daily' , function ( ) {
2016-12-19 16:39:29 +00:00
// create
2019-09-29 03:24:47 +00:00
browser . call ( async ( ) => {
await bot . edit ( name , content , ` created with " ${ content } " ` ) ;
2017-05-08 10:10:18 +00:00
} ) ;
2016-12-19 16:39:29 +00:00
// check
HistoryPage . open ( name ) ;
2019-09-29 03:24:47 +00:00
assert . strictEqual ( HistoryPage . comment . getText ( ) , ` created with " ${ content } " ` ) ;
2016-12-19 16:39:29 +00:00
} ) ;
2018-01-13 12:56:46 +00:00
it ( 'should be deletable' , function ( ) {
// create
2019-09-29 03:24:47 +00:00
browser . call ( async ( ) => {
await bot . edit ( name , content , 'create for delete' ) ;
2018-01-13 12:56:46 +00:00
} ) ;
2019-09-29 03:24:47 +00:00
// login
UserLoginPage . loginAdmin ( ) ;
2018-01-13 12:56:46 +00:00
// delete
2019-09-29 03:24:47 +00:00
DeletePage . delete ( name , 'delete reason' ) ;
2018-01-13 12:56:46 +00:00
// check
2018-06-06 10:49:33 +00:00
assert . strictEqual (
2018-01-13 12:56:46 +00:00
DeletePage . displayedContent . getText ( ) ,
2021-02-25 15:58:25 +00:00
'"' + name + '" has been deleted. See deletion log for a record of recent deletions.\n\nReturn to Main Page.'
2018-01-13 12:56:46 +00:00
) ;
} ) ;
2018-01-13 13:52:35 +00:00
it ( 'should be restorable' , function ( ) {
2019-09-29 03:24:47 +00:00
// create and delete
browser . call ( async ( ) => {
await bot . edit ( name , content , 'create for delete' ) ;
await bot . delete ( name , 'delete for restore' ) ;
2018-01-13 13:52:35 +00:00
} ) ;
2019-09-29 03:24:47 +00:00
// login
UserLoginPage . loginAdmin ( ) ;
2018-01-13 13:52:35 +00:00
// restore
2019-09-29 03:24:47 +00:00
RestorePage . restore ( name , 'restore reason' ) ;
2018-01-13 13:52:35 +00:00
// check
2021-02-25 15:58:25 +00:00
assert . strictEqual ( RestorePage . displayedContent . getText ( ) , name + ' has been restored\n\nConsult the deletion log for a record of recent deletions and restorations.' ) ;
2018-01-13 13:52:35 +00:00
} ) ;
2018-08-14 14:27:31 +00:00
2021-06-07 17:57:28 +00:00
it ( 'should be protectable' , function ( ) {
browser . call ( async ( ) => {
await bot . edit ( name , content , 'create for protect' ) ;
} ) ;
// login
UserLoginPage . loginAdmin ( ) ;
ProtectPage . protect (
name ,
'protect reason' ,
'Allow only administrators'
) ;
// Logout
browser . deleteAllCookies ( ) ;
// Check that we can't edit the page anymore
EditPage . openForEditing ( name ) ;
assert . strictEqual ( EditPage . save . isExisting ( ) , false ) ;
assert . strictEqual ( EditPage . heading . getText ( ) , 'View source for ' + name ) ;
} ) ;
2021-03-11 10:55:07 +00:00
it . skip ( 'should be undoable' , function ( ) {
2018-08-14 14:27:31 +00:00
let previousRev , undoRev ;
2019-09-29 03:24:47 +00:00
browser . call ( async ( ) => {
// create
await bot . edit ( name , content , 'create to edit and undo' ) ;
// edit
const response = await bot . edit ( name , Util . getTestString ( 'editContent-' ) ) ;
previousRev = response . edit . oldrevid ;
undoRev = response . edit . newrevid ;
2018-08-14 14:27:31 +00:00
} ) ;
UndoPage . undo ( name , previousRev , undoRev ) ;
assert . strictEqual ( EditPage . displayedContent . getText ( ) , content ) ;
} ) ;
2016-12-19 16:39:29 +00:00
} ) ;