Merge "docs/kss/package.json: Update Gerrit /r/p/ link to /r/"
[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 UserLoginPage.waitForScriptsToBeReady();
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
54 HistoryPage.rollbackConfirmableNo.waitForVisible( 5000 );
55
56 HistoryPage.rollbackConfirmableNo.click();
57
58 browser.pause( 1000 ); // Waiting to ensure we are NOT redirected and stay on the same page
59
60 assert.strictEqual( HistoryPage.heading.getText(), 'Revision history of "' + name + '"' );
61 } );
62
63 it( 'should perform rollbacks after confirming intention', function () {
64 HistoryPage.rollback.click();
65
66 HistoryPage.rollbackConfirmableYes.waitForVisible( 5000 );
67
68 HistoryPage.rollbackConfirmableYes.click();
69
70 // waitUntil indirectly asserts that the content we are looking for is present
71 browser.waitUntil( function () {
72 return browser.getText( '#firstHeading' ) === 'Action complete';
73 }, 5000, 'Expected rollback page to appear.' );
74 } );
75
76 it( 'should verify rollbacks via GET requests are confirmed on a follow-up page', function () {
77 var rollbackActionUrl = HistoryPage.rollbackLink.getAttribute( 'href' );
78 browser.url( rollbackActionUrl );
79
80 browser.waitUntil( function () {
81 return HistoryPage.rollbackNonJsConfirmable.getText() === 'Revert edits to this page?';
82 }, 5000, 'Expected rollback confirmation page to appear for GET-based rollbacks.' );
83
84 HistoryPage.rollbackNonJsConfirmableYes.click();
85
86 browser.waitUntil( function () {
87 return browser.getText( '#firstHeading' ) === 'Action complete';
88 }, 5000, 'Expected rollback page to appear.' );
89 } );
90
91 } );
92
93 describe( 'Rollback without confirmation', function () {
94 var content,
95 name;
96
97 before( function () {
98 // disable VisualEditor welcome dialog
99 browser.deleteCookie();
100 UserLoginPage.open();
101 browser.localStorage( 'POST', { key: 've-beta-welcome-dialog', value: '1' } );
102
103 // Disable rollback confirmation for admin user
104 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
105 UserLoginPage.loginAdmin();
106
107 UserLoginPage.waitForScriptsToBeReady();
108 browser.execute( function () {
109 return ( new mw.Api() ).saveOption(
110 'showrollbackconfirmation',
111 '0'
112 );
113 } );
114 } );
115
116 beforeEach( function () {
117 browser.deleteCookie();
118
119 content = Util.getTestString( 'beforeEach-content-' );
120 name = Util.getTestString( 'BeforeEach-name-' );
121
122 HistoryPage.vandalizePage( name, content );
123
124 UserLoginPage.loginAdmin();
125 HistoryPage.open( name );
126 } );
127
128 it( 'should perform rollback via POST request without asking the user to confirm', function () {
129 HistoryPage.rollback.click();
130
131 // waitUntil indirectly asserts that the content we are looking for is present
132 browser.waitUntil( function () {
133 return HistoryPage.headingText === 'Action complete';
134 }, 5000, 'Expected rollback page to appear.' );
135 } );
136
137 it( 'should perform rollback via GET request without asking the user to confirm', function () {
138 var rollbackActionUrl = HistoryPage.rollbackLink.getAttribute( 'href' );
139 browser.url( rollbackActionUrl );
140
141 browser.waitUntil( function () {
142 return browser.getText( '#firstHeading' ) === 'Action complete';
143 }, 5000, 'Expected rollback page to appear.' );
144 } );
145 } );