1 const assert
= require( 'assert' ),
2 Api
= require( 'wdio-mediawiki/Api' ),
3 DeletePage
= require( '../pageobjects/delete.page' ),
4 RestorePage
= require( '../pageobjects/restore.page' ),
5 EditPage
= require( '../pageobjects/edit.page' ),
6 HistoryPage
= require( '../pageobjects/history.page' ),
7 UndoPage
= require( '../pageobjects/undo.page' ),
8 UserLoginPage
= require( 'wdio-mediawiki/LoginPage' ),
9 Util
= require( 'wdio-mediawiki/Util' );
11 describe( 'Page', function () {
16 // disable VisualEditor welcome dialog
18 browser
.localStorage( 'POST', { key
: 've-beta-welcome-dialog', value
: '1' } );
21 beforeEach( function () {
22 browser
.deleteCookie();
23 content
= Util
.getTestString( 'beforeEach-content-' );
24 name
= Util
.getTestString( 'BeforeEach-name-' );
27 it( 'should be previewable', function () {
28 EditPage
.preview( name
, content
);
30 assert
.strictEqual( EditPage
.heading
.getText(), 'Creating ' + name
);
31 assert
.strictEqual( EditPage
.displayedContent
.getText(), content
);
32 assert( EditPage
.content
.isVisible(), 'editor is still present' );
33 assert( !EditPage
.conflictingContent
.isVisible(), 'no edit conflict happened' );
34 // provoke and dismiss reload warning due to unsaved content
35 browser
.url( 'data:text/html,Done' );
37 browser
.alertAccept();
41 it( 'should be creatable', function () {
43 EditPage
.edit( name
, content
);
46 assert
.strictEqual( EditPage
.heading
.getText(), name
);
47 assert
.strictEqual( EditPage
.displayedContent
.getText(), content
);
50 it( 'should be re-creatable', function () {
51 const initialContent
= Util
.getTestString( 'initialContent-' );
54 browser
.call( function () {
55 return Api
.edit( name
, initialContent
);
59 browser
.call( function () {
60 return Api
.delete( name
, 'delete prior to recreate' );
64 EditPage
.edit( name
, content
);
67 assert
.strictEqual( EditPage
.heading
.getText(), name
);
68 assert
.strictEqual( EditPage
.displayedContent
.getText(), content
);
71 it( 'should be editable @daily', function () {
73 browser
.call( function () {
74 return Api
.edit( name
, content
);
78 const editContent
= Util
.getTestString( 'editContent-' );
79 EditPage
.edit( name
, editContent
);
82 assert
.strictEqual( EditPage
.heading
.getText(), name
);
83 // eslint-disable-next-line no-restricted-syntax
84 assert( EditPage
.displayedContent
.getText().includes( editContent
) );
87 it( 'should have history @daily', function () {
89 browser
.call( function () {
90 return Api
.edit( name
, content
);
94 HistoryPage
.open( name
);
95 assert
.strictEqual( HistoryPage
.comment
.getText(), `Created or updated page with "${content}"` );
98 it( 'should be deletable', function () {
100 UserLoginPage
.loginAdmin();
103 browser
.call( function () {
104 return Api
.edit( name
, content
);
108 DeletePage
.delete( name
, content
+ '-deletereason' );
112 DeletePage
.displayedContent
.getText(),
113 '"' + name
+ '" has been deleted. See deletion log for a record of recent deletions.\nReturn to Main Page.'
117 it( 'should be restorable', function () {
119 UserLoginPage
.loginAdmin();
122 browser
.call( function () {
123 return Api
.edit( name
, content
);
127 browser
.call( function () {
128 return Api
.delete( name
, content
+ '-deletereason' );
132 RestorePage
.restore( name
, content
+ '-restorereason' );
135 assert
.strictEqual( RestorePage
.displayedContent
.getText(), name
+ ' has been restored\nConsult the deletion log for a record of recent deletions and restorations.' );
138 it( 'should be undoable', function () {
140 browser
.call( function () {
141 return Api
.edit( name
, content
);
145 let previousRev
, undoRev
;
146 browser
.call( function () {
147 return Api
.edit( name
, Util
.getTestString( 'editContent-' ) )
148 .then( ( response
) => {
149 previousRev
= response
.edit
.oldrevid
;
150 undoRev
= response
.edit
.newrevid
;
154 UndoPage
.undo( name
, previousRev
, undoRev
);
156 assert
.strictEqual( EditPage
.displayedContent
.getText(), content
);