Show confirmation prompt on rollback links
[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(), 'Rollback of one edit?' );
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
71 describe( 'Rollback without confirmation', function () {
72 var content,
73 name;
74
75 before( function () {
76 // disable VisualEditor welcome dialog
77 browser.deleteCookie();
78 UserLoginPage.open();
79 browser.localStorage( 'POST', { key: 've-beta-welcome-dialog', value: '1' } );
80
81 // Disable rollback confirmation for admin user
82 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
83 UserLoginPage.loginAdmin();
84
85 browser.pause( 300 );
86 browser.execute( function () {
87 return ( new mw.Api() ).saveOption(
88 'showrollbackconfirmation',
89 '0'
90 );
91 } );
92 } );
93
94 beforeEach( function () {
95 browser.deleteCookie();
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 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.headingText === 'Action complete';
112 }, 5000, 'Expected rollback page to appear.' );
113 } );
114 } );