1 const assert
= require( 'assert' ),
2 HistoryPage
= require( '../pageobjects/history.page' ),
3 UserLoginPage
= require( 'wdio-mediawiki/LoginPage' ),
4 Util
= require( 'wdio-mediawiki/Util' );
6 describe( 'Rollback with confirmation', function () {
11 // disable VisualEditor welcome dialog
12 browser
.deleteCookie();
14 browser
.localStorage( 'POST', { key
: 've-beta-welcome-dialog', value
: '1' } );
16 // Enable rollback confirmation for admin user
17 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
18 UserLoginPage
.loginAdmin();
21 browser
.execute( function () {
22 return ( new mw
.Api() ).saveOption(
23 'showrollbackconfirmation',
29 beforeEach( function () {
30 browser
.deleteCookie();
32 content
= Util
.getTestString( 'beforeEach-content-' );
33 name
= Util
.getTestString( 'BeforeEach-name-' );
35 HistoryPage
.vandalizePage( name
, content
);
37 UserLoginPage
.loginAdmin();
38 HistoryPage
.open( name
);
41 it( 'should offer rollback options for admin users', function () {
42 assert
.strictEqual( HistoryPage
.rollback
.getText(), 'rollback 1 edit' );
44 HistoryPage
.rollback
.click();
46 assert
.strictEqual( HistoryPage
.rollbackConfirmable
.getText(), 'Please confirm:' );
47 assert
.strictEqual( HistoryPage
.rollbackConfirmableYes
.getText(), 'Rollback' );
48 assert
.strictEqual( HistoryPage
.rollbackConfirmableNo
.getText(), 'Cancel' );
51 it( 'should offer a way to cancel rollbacks', function () {
52 HistoryPage
.rollback
.click();
54 HistoryPage
.rollbackConfirmableNo
.click();
58 assert
.strictEqual( HistoryPage
.heading
.getText(), 'Revision history of "' + name
+ '"' );
61 it( 'should perform rollbacks after confirming intention', function () {
62 HistoryPage
.rollback
.click();
63 HistoryPage
.rollbackConfirmableYes
.click();
65 // waitUntil indirectly asserts that the content we are looking for is present
66 browser
.waitUntil( function () {
67 return browser
.getText( '#firstHeading' ) === 'Action complete';
68 }, 5000, 'Expected rollback page to appear.' );
71 it( 'should verify rollbacks via GET requests are confirmed on a follow-up page', function () {
72 var rollbackActionUrl
= HistoryPage
.rollbackLink
.getAttribute( 'href' );
73 browser
.url( rollbackActionUrl
);
75 browser
.waitUntil( function () {
76 return HistoryPage
.rollbackNonJsConfirmable
.getText() === 'Revert edits to this page?';
77 }, 5000, 'Expected rollback confirmation page to appear for GET-based rollbacks.' );
79 HistoryPage
.rollbackNonJsConfirmableYes
.click();
81 browser
.waitUntil( function () {
82 return browser
.getText( '#firstHeading' ) === 'Action complete';
83 }, 5000, 'Expected rollback page to appear.' );
88 describe( 'Rollback without confirmation', function () {
93 // disable VisualEditor welcome dialog
94 browser
.deleteCookie();
96 browser
.localStorage( 'POST', { key
: 've-beta-welcome-dialog', value
: '1' } );
98 // Disable rollback confirmation for admin user
99 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
100 UserLoginPage
.loginAdmin();
102 browser
.pause( 300 );
103 browser
.execute( function () {
104 return ( new mw
.Api() ).saveOption(
105 'showrollbackconfirmation',
111 beforeEach( function () {
112 browser
.deleteCookie();
114 content
= Util
.getTestString( 'beforeEach-content-' );
115 name
= Util
.getTestString( 'BeforeEach-name-' );
117 HistoryPage
.vandalizePage( name
, content
);
119 UserLoginPage
.loginAdmin();
120 HistoryPage
.open( name
);
123 it( 'should perform rollback via POST request without asking the user to confirm', function () {
124 HistoryPage
.rollback
.click();
126 // waitUntil indirectly asserts that the content we are looking for is present
127 browser
.waitUntil( function () {
128 return HistoryPage
.headingText
=== 'Action complete';
129 }, 5000, 'Expected rollback page to appear.' );
132 it( 'should perform rollback via GET request without asking the user to confirm', function () {
133 var rollbackActionUrl
= HistoryPage
.rollbackLink
.getAttribute( 'href' );
134 browser
.url( rollbackActionUrl
);
136 browser
.waitUntil( function () {
137 return browser
.getText( '#firstHeading' ) === 'Action complete';
138 }, 5000, 'Expected rollback page to appear.' );