selenium: Replace ES5 one-var assignments with const/let per line
[lhc/web/wiklou.git] / tests / selenium / specs / rollback.js
1 const assert = require( 'assert' );
2 const HistoryPage = require( '../pageobjects/history.page' );
3 const UserLoginPage = require( 'wdio-mediawiki/LoginPage' );
4 const Util = require( 'wdio-mediawiki/Util' );
5
6 describe( 'Rollback with confirmation', function () {
7 let content, name;
8
9 before( function () {
10 browser.deleteAllCookies();
11
12 // Enable rollback confirmation for admin user
13 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
14 UserLoginPage.loginAdmin();
15 HistoryPage.toggleRollbackConfirmationSetting( true );
16 } );
17
18 beforeEach( function () {
19 browser.deleteAllCookies();
20
21 content = Util.getTestString( 'beforeEach-content-' );
22 name = Util.getTestString( 'BeforeEach-name-' );
23
24 HistoryPage.vandalizePage( name, content );
25
26 UserLoginPage.loginAdmin();
27 HistoryPage.open( name );
28 } );
29
30 it.skip( 'should offer rollback options for admin users', function () {
31 assert.strictEqual( HistoryPage.rollback.getText(), 'rollback 1 edit' );
32
33 HistoryPage.rollbackLink.click();
34
35 assert.strictEqual( HistoryPage.rollbackConfirmable.getText(), 'Please confirm:' );
36 assert.strictEqual( HistoryPage.rollbackConfirmableYes.getText(), 'Rollback' );
37 assert.strictEqual( HistoryPage.rollbackConfirmableNo.getText(), 'Cancel' );
38 } );
39
40 it.skip( 'should offer a way to cancel rollbacks', function () {
41 HistoryPage.rollback.click();
42
43 HistoryPage.rollbackConfirmableNo.waitForDisplayed( 5000 );
44
45 HistoryPage.rollbackConfirmableNo.click();
46
47 browser.pause( 1000 ); // Waiting to ensure we are NOT redirected and stay on the same page
48
49 assert.strictEqual( HistoryPage.heading.getText(), 'Revision history of "' + name + '"' );
50 } );
51
52 it.skip( 'should perform rollbacks after confirming intention', function () {
53 HistoryPage.rollback.click();
54
55 HistoryPage.rollbackConfirmableYes.waitForDisplayed( 5000 );
56
57 HistoryPage.rollbackConfirmableYes.click();
58
59 // waitUntil indirectly asserts that the content we are looking for is present
60 browser.waitUntil( function () {
61 return browser.getText( '#firstHeading' ) === 'Action complete';
62 }, 5000, 'Expected rollback page to appear.' );
63 } );
64
65 it.skip( 'should verify rollbacks via GET requests are confirmed on a follow-up page', function () {
66 const rollbackActionUrl = HistoryPage.rollbackLink.getAttribute( 'href' );
67 browser.url( rollbackActionUrl );
68
69 browser.waitUntil( function () {
70 return HistoryPage.rollbackNonJsConfirmable.getText() === 'Revert edits to this page?';
71 }, 5000, 'Expected rollback confirmation page to appear for GET-based rollbacks.' );
72
73 HistoryPage.rollbackNonJsConfirmableYes.click();
74
75 browser.waitUntil( function () {
76 return browser.getText( '#firstHeading' ) === 'Action complete';
77 }, 5000, 'Expected rollback page to appear.' );
78 } );
79
80 } );
81
82 describe( 'Rollback without confirmation', function () {
83 let content, name;
84
85 before( function () {
86 browser.deleteAllCookies();
87
88 // Disable rollback confirmation for admin user
89 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
90 UserLoginPage.loginAdmin();
91 HistoryPage.toggleRollbackConfirmationSetting( false );
92 } );
93
94 beforeEach( function () {
95 browser.deleteAllCookies();
96
97 content = Util.getTestString( 'beforeEach-content-' );
98 name = Util.getTestString( 'BeforeEach-name-' );
99
100 HistoryPage.vandalizePage( name, content );
101
102 UserLoginPage.loginAdmin();
103 HistoryPage.open( name );
104 } );
105
106 it( 'should perform rollback via POST request without asking the user to confirm', function () {
107 HistoryPage.rollback.click();
108
109 // waitUntil indirectly asserts that the content we are looking for is present
110 browser.waitUntil( function () {
111 return HistoryPage.heading.getText() === 'Action complete';
112 }, 5000, 'Expected rollback page to appear.' );
113 } );
114
115 it.skip( 'should perform rollback via GET request without asking the user to confirm', function () {
116 const rollbackActionUrl = HistoryPage.rollbackLink.getAttribute( 'href' );
117 browser.url( rollbackActionUrl );
118
119 browser.waitUntil( function () {
120 return browser.getText( '#firstHeading' ) === 'Action complete';
121 }, 5000, 'Expected rollback page to appear.' );
122 } );
123 } );