Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / tests / selenium / specs / rollback.js
1 const assert = require( 'assert' ),
2 BlankPage = require( 'wdio-mediawiki/BlankPage' ),
3 HistoryPage = require( '../pageobjects/history.page' ),
4 UserLoginPage = require( 'wdio-mediawiki/LoginPage' ),
5 Util = require( 'wdio-mediawiki/Util' );
6
7 describe( 'Rollback with confirmation', function () {
8 var content,
9 name;
10
11 before( function () {
12 // disable VisualEditor welcome dialog
13 browser.deleteCookie();
14 BlankPage.open();
15 browser.localStorage( 'POST', { key: 've-beta-welcome-dialog', value: '1' } );
16
17 // Enable rollback confirmation for admin user
18 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
19 UserLoginPage.loginAdmin();
20 HistoryPage.toggleRollbackConfirmationSetting( true );
21 } );
22
23 beforeEach( function () {
24 browser.deleteCookie();
25
26 content = Util.getTestString( 'beforeEach-content-' );
27 name = Util.getTestString( 'BeforeEach-name-' );
28
29 HistoryPage.vandalizePage( name, content );
30
31 UserLoginPage.loginAdmin();
32 HistoryPage.open( name );
33 } );
34
35 it.skip( 'should offer rollback options for admin users', function () {
36 assert.strictEqual( HistoryPage.rollback.getText(), 'rollback 1 edit' );
37
38 HistoryPage.rollback.click();
39
40 assert.strictEqual( HistoryPage.rollbackConfirmable.getText(), 'Please confirm:' );
41 assert.strictEqual( HistoryPage.rollbackConfirmableYes.getText(), 'Rollback' );
42 assert.strictEqual( HistoryPage.rollbackConfirmableNo.getText(), 'Cancel' );
43 } );
44
45 it.skip( 'should offer a way to cancel rollbacks', function () {
46 HistoryPage.rollback.click();
47
48 HistoryPage.rollbackConfirmableNo.waitForVisible( 5000 );
49
50 HistoryPage.rollbackConfirmableNo.click();
51
52 browser.pause( 1000 ); // Waiting to ensure we are NOT redirected and stay on the same page
53
54 assert.strictEqual( HistoryPage.heading.getText(), 'Revision history of "' + name + '"' );
55 } );
56
57 it.skip( 'should perform rollbacks after confirming intention', function () {
58 HistoryPage.rollback.click();
59
60 HistoryPage.rollbackConfirmableYes.waitForVisible( 5000 );
61
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.skip( '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 BlankPage.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 HistoryPage.toggleRollbackConfirmationSetting( false );
101 } );
102
103 beforeEach( function () {
104 browser.deleteCookie();
105
106 content = Util.getTestString( 'beforeEach-content-' );
107 name = Util.getTestString( 'BeforeEach-name-' );
108
109 HistoryPage.vandalizePage( name, content );
110
111 UserLoginPage.loginAdmin();
112 HistoryPage.open( name );
113 } );
114
115 it( 'should perform rollback via POST request without asking the user to confirm', function () {
116 HistoryPage.rollback.click();
117
118 // waitUntil indirectly asserts that the content we are looking for is present
119 browser.waitUntil( function () {
120 return HistoryPage.headingText === 'Action complete';
121 }, 5000, 'Expected rollback page to appear.' );
122 } );
123
124 it.skip( 'should perform rollback via GET request without asking the user to confirm', function () {
125 var rollbackActionUrl = HistoryPage.rollbackLink.getAttribute( 'href' );
126 browser.url( rollbackActionUrl );
127
128 browser.waitUntil( function () {
129 return browser.getText( '#firstHeading' ) === 'Action complete';
130 }, 5000, 'Expected rollback page to appear.' );
131 } );
132 } );