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 let 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 let editContent
= Util
.getTestString( 'editContent-' );
79 EditPage
.edit( name
, editContent
);
82 assert
.strictEqual( EditPage
.heading
.getText(), name
);
83 assert
.strictEqual( EditPage
.displayedContent
.getText(), editContent
);
86 it( 'should have history @daily', function () {
88 browser
.call( function () {
89 return Api
.edit( name
, content
);
93 HistoryPage
.open( name
);
94 assert
.strictEqual( HistoryPage
.comment
.getText(), `(Created or updated page with "${content}")` );
97 it( 'should be deletable', function () {
99 UserLoginPage
.loginAdmin();
102 browser
.call( function () {
103 return Api
.edit( name
, content
);
107 DeletePage
.delete( name
, content
+ '-deletereason' );
111 DeletePage
.displayedContent
.getText(),
112 '"' + name
+ '" has been deleted. See deletion log for a record of recent deletions.\nReturn to Main Page.'
116 it( 'should be restorable', function () {
118 UserLoginPage
.loginAdmin();
121 browser
.call( function () {
122 return Api
.edit( name
, content
);
126 browser
.call( function () {
127 return Api
.delete( name
, content
+ '-deletereason' );
131 RestorePage
.restore( name
, content
+ '-restorereason' );
134 assert
.strictEqual( RestorePage
.displayedContent
.getText(), name
+ ' has been restored\nConsult the deletion log for a record of recent deletions and restorations.' );
137 it( 'should be undoable', function () {
139 browser
.call( function () {
140 return Api
.edit( name
, content
);
144 let previousRev
, undoRev
;
145 browser
.call( function () {
146 return Api
.edit( name
, Util
.getTestString( 'editContent-' ) )
147 .then( ( response
) => {
148 previousRev
= response
.edit
.oldrevid
;
149 undoRev
= response
.edit
.newrevid
;
153 UndoPage
.undo( name
, previousRev
, undoRev
);
155 assert
.strictEqual( EditPage
.displayedContent
.getText(), content
);