Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/tests/ui/dialogs/ve.ui.MWTransclusionDialog.test.js

raw symbols SCIP
1 /*!
2 * VisualEditor Template Dialog and Transclusion Dialog tests
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 {
8 QUnit.module( 've.ui.MWTransclusionDialog', ve.test.utils.newMwEnvironment( {
9 config: {
10 // Set config variable to activate new sidebar feature
11 // TODO: remove this when sidebar feature will be default
12 wgVisualEditorConfig: ve.extendObject( {}, mw.config.get( 'wgVisualEditorConfig' ), {
13 transclusionDialogNewSidebar: true
14 } )
15 }
16 } ) );
17
18 const createFragmentFromDoc = function ( doc ) {
19 // convert doc to something ui magical
20 const surface = new ve.dm.Surface( doc );
21 // VE block from surface
22 const fragment = surface.getLinearFragment( new ve.Range( 1 ) );
23
24 // return fragment as data for the dialog
25 return { fragment: fragment };
26 };
27
28 QUnit.test.skip( 'onReplacePart', ( assert ) => {
29 // don't kill test until this promise is resolved, to allow the async workflow to complete
30 const finishTest = assert.async();
31
32 // new wiki page and fragment
33 const doc = ve.dm.Document.static.newBlankDocument();
34 const fragment = createFragmentFromDoc( doc );
35
36 // new popup window
37 const dialog = new ve.ui.MWTransclusionDialog();
38 const windowManager = new OO.ui.WindowManager();
39 windowManager.addWindows( [ dialog ] );
40 const windowInstance = windowManager.openWindow( dialog, fragment );
41
42 windowInstance.opened.done( () => {
43 const transclusion = dialog.transclusionModel;
44 // mock api call with template data for Test
45 const templateData = {
46 title: 'Template:Test',
47 params: {
48 Blub: {
49 label: 'Blub',
50 description: 'blub',
51 type: 'string',
52 required: true
53 },
54 Foo: {
55 label: 'Foo',
56 description: 'Foo',
57 type: 'string',
58 required: true
59 }
60 }
61 };
62 transclusion.cacheTemplateDataApiResponse( { pages: [ templateData ] } );
63
64 // add a template with an undocumented parameter to the dialog
65 const data = {
66 target: {
67 title: 'Template:Test',
68 wt: 'Test',
69 href: 'Template:Test'
70 },
71 params: {
72 test: {
73 }
74 },
75 i: 0
76 };
77 const template = ve.dm.MWTemplateModel.newFromData( transclusion, data );
78
79 // change transclusion model (onReplacePart happens automatically)
80 const promise = transclusion.addPart( template );
81
82 promise.done( () => {
83 // checking for parameter checkboxes
84 // (should be 3 because of 2 predefined and 1 undocumented)
85 assert.strictEqual(
86 dialog.$element.find( '.ve-ui-mwTransclusionOutlineParameterWidget' ).length, 3
87 );
88 dialog.close();
89 } );
90
91 } ).fail( () => {
92 assert.true( false );
93 finishTest();
94 } );
95
96 windowInstance.closed.then( () => {
97 assert.true( true );
98 finishTest();
99 } );
100 } );
101 }