Merge "Remove broken explode() from MediaWikiMediaTestCase::dataFile()"
[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 browser.pause( 300 );
54 HistoryPage.rollbackConfirmableNo.click();
55
56 browser.pause( 500 );
57
58 assert.strictEqual( HistoryPage.heading.getText(), 'Revision history of "' + name + '"' );
59 } );
60
61 it( 'should perform rollbacks after confirming intention', function () {
62 HistoryPage.rollback.click();
63 HistoryPage.rollbackConfirmableYes.click();
64
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.' );
69 } );
70
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 );
74
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.' );
78
79 HistoryPage.rollbackNonJsConfirmableYes.click();
80
81 browser.waitUntil( function () {
82 return browser.getText( '#firstHeading' ) === 'Action complete';
83 }, 5000, 'Expected rollback page to appear.' );
84 } );
85
86 } );
87
88 describe( 'Rollback without confirmation', function () {
89 var content,
90 name;
91
92 before( function () {
93 // disable VisualEditor welcome dialog
94 browser.deleteCookie();
95 UserLoginPage.open();
96 browser.localStorage( 'POST', { key: 've-beta-welcome-dialog', value: '1' } );
97
98 // Disable rollback confirmation for admin user
99 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
100 UserLoginPage.loginAdmin();
101
102 browser.pause( 300 );
103 browser.execute( function () {
104 return ( new mw.Api() ).saveOption(
105 'showrollbackconfirmation',
106 '0'
107 );
108 } );
109 } );
110
111 beforeEach( function () {
112 browser.deleteCookie();
113
114 content = Util.getTestString( 'beforeEach-content-' );
115 name = Util.getTestString( 'BeforeEach-name-' );
116
117 HistoryPage.vandalizePage( name, content );
118
119 UserLoginPage.loginAdmin();
120 HistoryPage.open( name );
121 } );
122
123 it( 'should perform rollback via POST request without asking the user to confirm', function () {
124 HistoryPage.rollback.click();
125
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.' );
130 } );
131
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 );
135
136 browser.waitUntil( function () {
137 return browser.getText( '#firstHeading' ) === 'Action complete';
138 }, 5000, 'Expected rollback page to appear.' );
139 } );
140 } );