1 const assert
= require( 'assert' ),
2 BlankPage
= require( 'wdio-mediawiki/BlankPage' ),
3 HistoryPage
= require( '../pageobjects/history.page' ),
4 UserLoginPage
= require( 'wdio-mediawiki/LoginPage' ),
5 Util
= require( 'wdio-mediawiki/Util' );
7 describe( 'Rollback with confirmation', function () {
12 // disable VisualEditor welcome dialog
13 browser
.deleteCookie();
15 browser
.localStorage( 'POST', { key
: 've-beta-welcome-dialog', value
: '1' } );
17 // Enable rollback confirmation for admin user
18 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
19 UserLoginPage
.loginAdmin();
20 HistoryPage
.toggleRollbackConfirmationSetting( true );
23 beforeEach( function () {
24 browser
.deleteCookie();
26 content
= Util
.getTestString( 'beforeEach-content-' );
27 name
= Util
.getTestString( 'BeforeEach-name-' );
29 HistoryPage
.vandalizePage( name
, content
);
31 UserLoginPage
.loginAdmin();
32 HistoryPage
.open( name
);
35 it( 'should offer rollback options for admin users', function () {
36 assert
.strictEqual( HistoryPage
.rollback
.getText(), 'rollback 1 edit' );
38 HistoryPage
.rollback
.click();
40 assert
.strictEqual( HistoryPage
.rollbackConfirmable
.getText(), 'Please confirm:' );
41 assert
.strictEqual( HistoryPage
.rollbackConfirmableYes
.getText(), 'Rollback' );
42 assert
.strictEqual( HistoryPage
.rollbackConfirmableNo
.getText(), 'Cancel' );
45 it( 'should offer a way to cancel rollbacks', function () {
46 HistoryPage
.rollback
.click();
48 HistoryPage
.rollbackConfirmableNo
.waitForVisible( 5000 );
50 HistoryPage
.rollbackConfirmableNo
.click();
52 browser
.pause( 1000 ); // Waiting to ensure we are NOT redirected and stay on the same page
54 assert
.strictEqual( HistoryPage
.heading
.getText(), 'Revision history of "' + name
+ '"' );
57 it
.skip( 'should perform rollbacks after confirming intention', function () {
58 HistoryPage
.rollback
.click();
60 HistoryPage
.rollbackConfirmableYes
.waitForVisible( 5000 );
62 HistoryPage
.rollbackConfirmableYes
.click();
64 // waitUntil indirectly asserts that the content we are looking for is present
65 browser
.waitUntil( function () {
66 return browser
.getText( '#firstHeading' ) === 'Action complete';
67 }, 5000, 'Expected rollback page to appear.' );
70 it( 'should verify rollbacks via GET requests are confirmed on a follow-up page', function () {
71 var rollbackActionUrl
= HistoryPage
.rollbackLink
.getAttribute( 'href' );
72 browser
.url( rollbackActionUrl
);
74 browser
.waitUntil( function () {
75 return HistoryPage
.rollbackNonJsConfirmable
.getText() === 'Revert edits to this page?';
76 }, 5000, 'Expected rollback confirmation page to appear for GET-based rollbacks.' );
78 HistoryPage
.rollbackNonJsConfirmableYes
.click();
80 browser
.waitUntil( function () {
81 return browser
.getText( '#firstHeading' ) === 'Action complete';
82 }, 5000, 'Expected rollback page to appear.' );
87 describe( 'Rollback without confirmation', function () {
92 // disable VisualEditor welcome dialog
93 browser
.deleteCookie();
95 browser
.localStorage( 'POST', { key
: 've-beta-welcome-dialog', value
: '1' } );
97 // Disable rollback confirmation for admin user
98 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
99 UserLoginPage
.loginAdmin();
100 HistoryPage
.toggleRollbackConfirmationSetting( false );
103 beforeEach( function () {
104 browser
.deleteCookie();
106 content
= Util
.getTestString( 'beforeEach-content-' );
107 name
= Util
.getTestString( 'BeforeEach-name-' );
109 HistoryPage
.vandalizePage( name
, content
);
111 UserLoginPage
.loginAdmin();
112 HistoryPage
.open( name
);
115 it( 'should perform rollback via POST request without asking the user to confirm', function () {
116 HistoryPage
.rollback
.click();
118 // waitUntil indirectly asserts that the content we are looking for is present
119 browser
.waitUntil( function () {
120 return HistoryPage
.headingText
=== 'Action complete';
121 }, 5000, 'Expected rollback page to appear.' );
124 it( 'should perform rollback via GET request without asking the user to confirm', function () {
125 var rollbackActionUrl
= HistoryPage
.rollbackLink
.getAttribute( 'href' );
126 browser
.url( rollbackActionUrl
);
128 browser
.waitUntil( function () {
129 return browser
.getText( '#firstHeading' ) === 'Action complete';
130 }, 5000, 'Expected rollback page to appear.' );