Debian Codegraph @

extensions/AbuseFilter/tests/selenium/specs/editingFilters.js

raw symbols SCIP
1 'use strict';
2
3 const assert = require( 'assert' ),
4 LoginPage = require( 'wdio-mediawiki/LoginPage' ),
5 ViewEditPage = require( '../pageobjects/viewedit.page' ),
6 ViewListPage = require( '../pageobjects/viewlist.page' );
7
8 describe( 'Filter editing', () => {
9 describe( 'The editing interface', () => {
10 it( 'is not visible to logged-out users', async () => {
11 await ViewEditPage.open( 'new' );
12 assert( await ViewEditPage.error.isDisplayed() );
13 } );
14
15 it( 'is visible to logged-in admins', async () => {
16 await LoginPage.loginAdmin();
17 await ViewEditPage.open( 'new' );
18 assert( await ViewEditPage.name.isDisplayed() );
19 } );
20 } );
21
22 describe( 'Trying to open a non-existing filter', () => {
23 before( async () => {
24 await LoginPage.loginAdmin();
25 } );
26
27 it( 'I should receive an error', async () => {
28 await ViewEditPage.open( 1234567 );
29 assert( await ViewEditPage.error.isDisplayed() );
30 assert.strictEqual( await ViewEditPage.error.getText(), 'The filter you specified does not exist' );
31 } );
32 } );
33
34 const filterSpecs = {
35 name: 'My test filter',
36 rules: '"confirmed" in user_groups & true === false',
37 comments: 'Some notes',
38 warnMsg: 'abusefilter-warning-foobar'
39 };
40 let filterID, historyID;
41
42 async function assertFirstVersionSaved() {
43 assert.strictEqual( await ViewEditPage.name.getValue(), filterSpecs.name );
44 assert.strictEqual( await ViewEditPage.rules.getValue(), filterSpecs.rules + '\n' );
45 assert.strictEqual( await ViewEditPage.comments.getValue(), filterSpecs.comments + '\n' );
46 await ViewEditPage.warnCheckbox.isSelected();
47 assert.strictEqual( await ViewEditPage.warnOtherMessage.getValue(), filterSpecs.warnMsg );
48 }
49
50 describe( 'Creating a new filter', () => {
51 before( async () => {
52 await LoginPage.loginAdmin();
53 await ViewEditPage.open( 'new' );
54 } );
55
56 it( 'edit can be saved (1)', async () => {
57 await ViewEditPage.switchEditor();
58
59 await ViewEditPage.name.setValue( filterSpecs.name );
60 await ViewEditPage.rules.setValue( filterSpecs.rules );
61 await ViewEditPage.comments.setValue( filterSpecs.comments );
62 await ViewEditPage.warnCheckbox.click();
63 await ViewEditPage.setWarningMessage( filterSpecs.warnMsg );
64 await ViewEditPage.submit();
65
66 assert( await ViewListPage.filterSavedNotice.isDisplayed() );
67
68 filterID = await ViewListPage.savedFilterID();
69 assert.ok( filterID );
70 historyID = await ViewListPage.savedFilterHistoryID();
71 assert.ok( historyID );
72 } );
73
74 it( 'saved data is retained (1)', async () => {
75 await ViewEditPage.open( filterID );
76 await assertFirstVersionSaved();
77 } );
78 } );
79
80 describe( 'Editing an existing filter', () => {
81 before( async () => {
82 await LoginPage.loginAdmin();
83 await ViewEditPage.open( filterID );
84 } );
85
86 const newName = 'New filter name',
87 newNotes = 'More filter notes';
88
89 it( 'edit can be saved (2)', async () => {
90 await ViewEditPage.name.setValue( newName );
91 await ViewEditPage.comments.addValue( newNotes );
92 await ViewEditPage.submit();
93 assert( await ViewListPage.filterSavedNotice.isDisplayed() );
94 } );
95
96 it( 'saved data is retained (2)', async () => {
97 await ViewEditPage.open( filterID );
98 assert.strictEqual( await ViewEditPage.name.getValue(), newName );
99 assert.strictEqual( await ViewEditPage.comments.getValue(), newNotes + filterSpecs.comments + '\n' );
100 } );
101 } );
102
103 describe( 'Restoring an old version of a filter', () => {
104 before( async () => {
105 await LoginPage.loginAdmin();
106 } );
107
108 it( 'edit can be saved (3)', async () => {
109 await ViewEditPage.open( 'history/' + filterID + '/item/' + historyID );
110 await ViewEditPage.submit();
111 assert( await ViewListPage.filterSavedNotice.isDisplayed() );
112 } );
113
114 it( 'saved data is retained (3)', async () => {
115 await ViewEditPage.open( filterID );
116 await assertFirstVersionSaved();
117 } );
118 } );
119
120 describe( 'CSRF protection', () => {
121 before( async () => {
122 await LoginPage.loginAdmin();
123 await ViewEditPage.open( 'new' );
124 } );
125
126 const filterName = 'Testing CSRF';
127
128 it( 'a CSRF token is required to save the filter', async () => {
129 await ViewEditPage.invalidateToken();
130 await ViewEditPage.name.setValue( filterName );
131 await ViewEditPage.submit();
132 assert( await ViewEditPage.warning.isDisplayed() );
133 } );
134 it( 'even if the token is invalid, the ongoing edit is not lost', async () => {
135 assert.strictEqual( await ViewEditPage.name.getValue(), filterName );
136 } );
137 } );
138
139 describe( 'Trying to save a filter with bad data', () => {
140 before( async () => {
141 await LoginPage.loginAdmin();
142 await ViewEditPage.open( 'new' );
143 } );
144
145 it( 'cannot save an empty filter', async () => {
146 await ViewEditPage.submit();
147 assert( await ViewEditPage.error.isDisplayed() );
148 } );
149
150 const rules = 'action === "edit"';
151
152 it( 'cannot save a filter with rules but no name', async () => {
153 await ViewEditPage.switchEditor();
154 await ViewEditPage.rules.setValue( rules );
155 await ViewEditPage.submit();
156 assert( await ViewEditPage.error.isDisplayed() );
157 } );
158
159 // Skipped on 2023-04-04 in 905717 because of T334001
160 it.skip( 'data is retained if saving fails', async () => {
161 const rulesValue = await ViewEditPage.rules.getValue();
162 assert.strictEqual( rulesValue, rules + '\n' );
163 } );
164 } );
165 } );