Merge "HISTORY: Add MediaWiki 1.12 post-release change notes"
[lhc/web/wiklou.git] / tests / selenium / specs / rollback.js
1 const assert = require( 'assert' ),
2 HistoryPage = require( '../pageobjects/history.page' ),
3 UserLoginPage = require( 'wdio-mediawiki/LoginPage' ),
4 Util = require( 'wdio-mediawiki/Util' );
5
6 describe( 'Rollback with confirmation', function () {
7 var content,
8 name;
9
10 before( function () {
11 // disable VisualEditor welcome dialog
12 browser.deleteCookie();
13 UserLoginPage.open();
14 browser.localStorage( 'POST', { key: 've-beta-welcome-dialog', value: '1' } );
15
16 // Enable rollback confirmation for admin user
17 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
18 UserLoginPage.loginAdmin();
19
20 browser.pause( 300 );
21 browser.execute( function () {
22 return ( new mw.Api() ).saveOption(
23 'showrollbackconfirmation',
24 '1'
25 );
26 } );
27 } );
28
29 beforeEach( function () {
30 browser.deleteCookie();
31
32 content = Util.getTestString( 'beforeEach-content-' );
33 name = Util.getTestString( 'BeforeEach-name-' );
34
35 HistoryPage.vandalizePage( name, content );
36
37 UserLoginPage.loginAdmin();
38 HistoryPage.open( name );
39 } );
40
41 it( 'should offer rollback options for admin users', function () {
42 assert.strictEqual( HistoryPage.rollback.getText(), 'rollback 1 edit' );
43
44 HistoryPage.rollback.click();
45
46 assert.strictEqual( HistoryPage.rollbackConfirmable.getText(), 'Please confirm:' );
47 assert.strictEqual( HistoryPage.rollbackConfirmableYes.getText(), 'Rollback' );
48 assert.strictEqual( HistoryPage.rollbackConfirmableNo.getText(), 'Cancel' );
49 } );
50
51 it( 'should offer a way to cancel rollbacks', function () {
52 HistoryPage.rollback.click();
53 HistoryPage.rollbackConfirmableNo.click();
54
55 browser.pause( 500 );
56
57 assert.strictEqual( HistoryPage.heading.getText(), 'Revision history of "' + name + '"' );
58 } );
59
60 it( 'should perform rollbacks after confirming intention', function () {
61 HistoryPage.rollback.click();
62 HistoryPage.rollbackConfirmableYes.click();
63
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.' );
68 } );
69
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 );
73
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.' );
77
78 HistoryPage.rollbackNonJsConfirmableYes.click();
79
80 browser.waitUntil( function () {
81 return browser.getText( '#firstHeading' ) === 'Action complete';
82 }, 5000, 'Expected rollback page to appear.' );
83 } );
84
85 } );
86
87 describe( 'Rollback without confirmation', function () {
88 var content,
89 name;
90
91 before( function () {
92 // disable VisualEditor welcome dialog
93 browser.deleteCookie();
94 UserLoginPage.open();
95 browser.localStorage( 'POST', { key: 've-beta-welcome-dialog', value: '1' } );
96
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
101 browser.pause( 300 );
102 browser.execute( function () {
103 return ( new mw.Api() ).saveOption(
104 'showrollbackconfirmation',
105 '0'
106 );
107 } );
108 } );
109
110 beforeEach( function () {
111 browser.deleteCookie();
112
113 content = Util.getTestString( 'beforeEach-content-' );
114 name = Util.getTestString( 'BeforeEach-name-' );
115
116 HistoryPage.vandalizePage( name, content );
117
118 UserLoginPage.loginAdmin();
119 HistoryPage.open( name );
120 } );
121
122 it( 'should perform rollback via POST request without asking the user to confirm', function () {
123 HistoryPage.rollback.click();
124
125 // waitUntil indirectly asserts that the content we are looking for is present
126 browser.waitUntil( function () {
127 return HistoryPage.headingText === 'Action complete';
128 }, 5000, 'Expected rollback page to appear.' );
129 } );
130
131 it( 'should perform rollback via GET request without asking the user to confirm', function () {
132 var rollbackActionUrl = HistoryPage.rollbackLink.getAttribute( 'href' );
133 browser.url( rollbackActionUrl );
134
135 browser.waitUntil( function () {
136 return browser.getText( '#firstHeading' ) === 'Action complete';
137 }, 5000, 'Expected rollback page to appear.' );
138 } );
139 } );