Debian Codegraph @

tests/selenium/specs/page.js

raw symbols SCIP
1 'use strict';
2
3 const BlankPage = require( 'wdio-mediawiki/BlankPage' );
4 const Api = require( 'wdio-mediawiki/Api' );
5 const DeletePage = require( '../pageobjects/delete.page' );
6 const RestorePage = require( '../pageobjects/restore.page' );
7 const EditPage = require( '../pageobjects/edit.page' );
8 const HistoryPage = require( '../pageobjects/history.page' );
9 const UndoPage = require( '../pageobjects/undo.page' );
10 const ProtectPage = require( '../pageobjects/protect.page' );
11 const LoginPage = require( 'wdio-mediawiki/LoginPage' );
12 const Util = require( 'wdio-mediawiki/Util' );
13
14 describe( 'Page', () => {
15 let content, name, bot;
16
17 before( async () => {
18 bot = await Api.bot();
19 } );
20
21 beforeEach( async function () {
22 await browser.deleteAllCookies();
23 content = Util.getTestString( 'beforeEach-content-' );
24 name = Util.getTestString( 'BeforeEach-name-' );
25
26 // First try to load a blank page, so the next command works.
27 await BlankPage.open();
28 // Don't try to run wikitext-specific tests if the test namespace isn't wikitext by default.
29 if ( await Util.isTargetNotWikitext( name ) ) {
30 this.skip();
31 }
32 } );
33
34 it( 'should be previewable @daily', async () => {
35 await LoginPage.loginAdmin();
36 await EditPage.preview( name, content );
37
38 await expect( EditPage.heading ).toHaveText( `Creating ${ name }` );
39 await expect( EditPage.displayedContent ).toHaveText( content );
40 await expect( EditPage.content ).toBeDisplayed( { message: 'editor is still present' } );
41 await expect( EditPage.conflictingContent ).not.toBeDisplayed( { message: 'no edit conflict happened' } );
42
43 // T269566: Popup with text
44 // 'Leave site? Changes that you made may not be saved. Cancel/Leave'
45 // appears after the browser tries to leave the page with the preview.
46 await browser.reloadSession();
47 } );
48
49 it( 'should be creatable', async () => {
50 // create
51 await LoginPage.loginAdmin();
52 await EditPage.edit( name, content );
53
54 // check
55 await expect( EditPage.heading ).toHaveText( name );
56 await expect( EditPage.displayedContent ).toHaveText( content );
57 } );
58
59 it( 'should be re-creatable', async () => {
60 const initialContent = Util.getTestString( 'initialContent-' );
61
62 // create and delete
63 await bot.edit( name, initialContent, 'create for delete' );
64 await bot.delete( name, 'delete prior to recreate' );
65
66 // re-create
67 await LoginPage.loginAdmin();
68 await EditPage.edit( name, content );
69
70 // check
71 await expect( EditPage.heading ).toHaveText( name );
72 await expect( EditPage.displayedContent ).toHaveText( content );
73 } );
74
75 it( 'should be editable @daily', async () => {
76 // create
77 await bot.edit( name, content, 'create for edit' );
78
79 // edit
80 const editContent = Util.getTestString( 'editContent-' );
81 await EditPage.edit( name, editContent );
82
83 // check
84 await expect( EditPage.heading ).toHaveText( name );
85 await expect( EditPage.displayedContent ).toHaveTextContaining( editContent );
86 } );
87
88 it( 'should have history @daily', async () => {
89 // create
90 await bot.edit( name, content, `created with "${ content }"` );
91
92 // check
93 await HistoryPage.open( name );
94 await expect( HistoryPage.comment ).toHaveText( `created with "${ content }"` );
95 } );
96
97 it( 'should be deletable', async () => {
98 // create
99 await bot.edit( name, content, 'create for delete' );
100
101 // login
102 await LoginPage.loginAdmin();
103 // delete
104 await DeletePage.delete( name, 'delete reason' );
105
106 // check
107 await expect( DeletePage.displayedContent ).toHaveTextContaining( `"${ name }" has been deleted.` );
108 } );
109
110 it( 'should be restorable', async () => {
111 // create and delete
112 await bot.edit( name, content, 'create for delete' );
113 await bot.delete( name, 'delete for restore' );
114
115 // login
116 await LoginPage.loginAdmin();
117
118 // restore
119 await RestorePage.restore( name, 'restore reason' );
120
121 // check
122 await expect( RestorePage.displayedContent ).toHaveTextContaining( `${ name } has been undeleted` );
123 } );
124
125 it( 'should be protectable', async () => {
126
127 await bot.edit( name, content, 'create for protect' );
128
129 // login
130 await LoginPage.loginAdmin();
131
132 await ProtectPage.protect(
133 name,
134 'protect reason',
135 'Allow only administrators'
136 );
137
138 // Logout
139 await browser.deleteAllCookies();
140
141 // Check that we can't edit the page anymore
142 await EditPage.openForEditing( name );
143 await expect( EditPage.save ).not.toExist();
144 await expect( EditPage.heading ).toHaveText( `View source for ${ name }` );
145 } );
146
147 it( 'should be undoable @daily', async () => {
148
149 // create
150 await bot.edit( name, content, 'create to edit and undo' );
151
152 // edit
153 const response = await bot.edit( name, Util.getTestString( 'editContent-' ) );
154 const previousRev = response.edit.oldrevid;
155 const undoRev = response.edit.newrevid;
156
157 await UndoPage.undo( name, previousRev, undoRev );
158
159 await expect( EditPage.displayedContent ).toHaveText( content );
160 } );
161
162 } );