Debian Codegraph @

extensions/VisualEditor/build/screenshots-client/utils.js

raw symbols SCIP
1 module.exports = function () {
2 const veDone = arguments[ arguments.length - 1 ];
3
4 window.seleniumUtils = {
5 getBoundingRect: function ( elements ) {
6 let boundingRect;
7 for ( let i = 0, l = elements.length; i < l; i++ ) {
8 const rect = elements[ i ].getBoundingClientRect();
9 if ( !boundingRect ) {
10 boundingRect = {
11 left: rect.left,
12 top: rect.top,
13 right: rect.right,
14 bottom: rect.bottom
15 };
16 } else {
17 boundingRect.left = Math.min( boundingRect.left, rect.left );
18 boundingRect.top = Math.min( boundingRect.top, rect.top );
19 boundingRect.right = Math.max( boundingRect.right, rect.right );
20 boundingRect.bottom = Math.max( boundingRect.bottom, rect.bottom );
21 }
22 }
23 if ( boundingRect ) {
24 boundingRect.width = boundingRect.right - boundingRect.left;
25 boundingRect.height = boundingRect.bottom - boundingRect.top;
26 }
27 return boundingRect;
28 },
29 collapseToolbar: function () {
30 ve.init.target.toolbar.items.forEach( ( group ) => {
31 if ( group.setActive ) {
32 group.setActive( false );
33 }
34 } );
35 },
36 runMenuTask: function ( done, tool, expanded, highlight, extraElements ) {
37 const toolGroup = tool.toolGroup;
38
39 seleniumUtils.collapseToolbar();
40 toolGroup.setActive( true );
41 if ( toolGroup.updateCollapsibleState ) {
42 toolGroup.expanded = !!expanded;
43 toolGroup.updateCollapsibleState();
44 }
45
46 if ( highlight ) {
47 tool.$link[ 0 ].focus();
48 }
49
50 setTimeout( () => {
51 done(
52 seleniumUtils.getBoundingRect( [
53 toolGroup.$element[ 0 ],
54 toolGroup.$group[ 0 ]
55 ].concat( extraElements || [] ) )
56 );
57 } );
58 },
59 runDiffTest: function ( oldHtml, newHtml, done ) {
60 const target = ve.init.target,
61 surface = target.surface;
62
63 if ( target.saveDialog ) {
64 target.saveDialog.clearDiff();
65 target.saveDialog.close();
66 while ( surface.getModel().canUndo() ) {
67 surface.getModel().undo();
68 }
69 }
70
71 target.originalDmDoc = target.constructor.static.createModelFromDom( target.constructor.static.parseDocument( oldHtml ), 'visual' );
72
73 surface.getModel().getDocument().getStore().merge( target.originalDmDoc.getStore() );
74
75 surface.getModel().getLinearFragment( new ve.Range( 0 ) ).insertDocument(
76 target.constructor.static.createModelFromDom( target.constructor.static.parseDocument( newHtml ), 'visual' )
77 ).collapseToEnd().adjustLinearSelection( 0, 3 ).removeContent();
78
79 target.once( 'saveReview', () => {
80 setTimeout( () => {
81 const dialog = surface.dialogs.currentWindow;
82 dialog.reviewModeButtonSelect.selectItemByData( 'visual' );
83
84 // Fake parsed edit summary
85 dialog.$previewEditSummary.text( '(Lorem ipsum)' );
86
87 done(
88 seleniumUtils.getBoundingRect( [
89 dialog.$frame[ 0 ]
90 ] )
91 );
92 }, 500 );
93 } );
94 surface.execute( 'mwSaveDialog', 'review' );
95 }
96 };
97
98 // Welcome dialog suppressed by query string (vehidebetadialog)
99 // Suppress user education indicators
100 mw.storage.set( 've-hideusered', 1 );
101 mw.hook( 've.activationComplete' ).add( () => {
102 const target = ve.init.target,
103 surfaceView = target.getSurface().getView();
104
105 // eslint-disable-next-line no-jquery/no-deferred
106 const welcomeDialogPromise = target.welcomeDialogPromise || $.Deferred().resolve().promise();
107
108 welcomeDialogPromise.then( () => {
109 // Hide edit notices
110 target.toolbar.tools.notices.getPopup().toggle( false );
111 surfaceView.focus();
112 // Modify the document to make the save button blue
113 target.surface.getModel().getFragment().insertContent( ' ' ).collapseToStart().select();
114 // Wait for save button fade
115 setTimeout( () => {
116 veDone( { width: window.innerWidth, height: window.innerHeight } );
117 }, 100 );
118 } );
119 } );
120 };