Refactor TemplateData Editor

Refactor and rewrite the templatedata editor to make it more flexible and
adaptable to new types. Separating the model from the gui, and adding new and
improved unit tests.

Also added features:
* Map depracated param types into current types.
* Retrieve template code from top template page if we are in a subpage.
* Mark parameters that do not appear in the template code.
* Add parameter types and a more flexible way to add and adjust the types.
* Add a link to TemplateData documentation from the main edit page.
* Add support for paramOrder; order the parameters according to the given array.
* Make the template parameter table sortable so users can change the paraOrder.

Bug: 59745
Bug: 65951
Bug: 66920
Bug: 67310
Bug: 67621
Change-Id: I65a76c2b772ef76c5dbbe71dd433c881c097b202
This commit is contained in:
Moriel Schottlender 2014-05-20 18:51:46 -04:00 committed by James D. Forrester
parent 23b0922cab
commit b313bbe485
8 changed files with 1589 additions and 1056 deletions

View file

@ -2,6 +2,7 @@
// Enforcing
"bitwise": true,
"eqeqeq": true,
"es3": true,
"freeze": true,
"latedef": true,
"noarg": true,
@ -10,9 +11,6 @@
"unused": true,
"strict": false,
// Relaxing
"es5": false,
// Environment
"browser": true,

View file

@ -66,6 +66,7 @@ $wgResourceModules['ext.templateDataGenerator.editPage'] = array(
),
'messages' => array(
'templatedata-editbutton',
'templatedata-helplink',
'templatedata-errormsg-jsonbadformat',
)
);
@ -80,6 +81,7 @@ $wgResourceModules['ext.templateDataGenerator.core'] = array(
'dependencies' => array(
'jquery.ui.dialog',
'jquery.ui.button',
'jquery.ui.sortable',
),
'messages' => array(
'templatedata-modal-button-addparam',
@ -89,6 +91,7 @@ $wgResourceModules['ext.templateDataGenerator.core'] = array(
'templatedata-modal-button-importParams',
'templatedata-modal-errormsg',
'templatedata-modal-errormsg-import-noparams',
'templatedata-modal-errormsg-import-paramsalreadyexist',
'templatedata-modal-notice-import-numparams',
'templatedata-modal-table-param-actions',
'templatedata-modal-table-param-aliases',
@ -99,14 +102,18 @@ $wgResourceModules['ext.templateDataGenerator.core'] = array(
'templatedata-modal-table-param-required',
'templatedata-modal-table-param-suggested',
'templatedata-modal-table-param-type',
'templatedata-modal-table-param-type-file',
'templatedata-modal-table-param-type-boolean',
'templatedata-modal-table-param-type-content',
'templatedata-modal-table-param-type-wiki-file-name',
'templatedata-modal-table-param-type-line',
'templatedata-modal-table-param-type-number',
'templatedata-modal-table-param-type-boolean',
'templatedata-modal-table-param-type-date',
'templatedata-modal-table-param-type-page',
'templatedata-modal-table-param-type-wiki-page-name',
'templatedata-modal-table-param-type-string',
'templatedata-modal-table-param-type-unbalanced-wikitext',
'templatedata-modal-table-param-type-undefined',
'templatedata-modal-table-param-type-user',
'templatedata-modal-table-param-type-wiki-user-name',
'templatedata-modal-table-param-uneditablefield',
'templatedata-modal-title',
'templatedata-modal-title-templatedesc',

View file

@ -28,14 +28,16 @@
"templatedata-invalid-value": "Invalid value for property \"$1\".",
"templatedata-invalid-length": "Data too large to save ({{formatnum:$1}} {{PLURAL:$1|byte|bytes}}, {{PLURAL:$2|limit is}} {{formatnum:$2}})",
"templatedata-editbutton": "Manage template documentation",
"templatedata-helplink": "Information about TemplateData",
"templatedata-errormsg-jsonbadformat": "Bad JSON format. Either correct it, or delete the current <templatedata> tags and try again.",
"templatedata-modal-button-addparam": "Add parameter",
"templatedata-modal-button-apply": "Apply",
"templatedata-modal-button-cancel": "Cancel",
"templatedata-modal-button-delparam": "Delete parameter",
"templatedata-modal-button-delparam": "Remove",
"templatedata-modal-button-importParams": "Import parameters",
"templatedata-modal-errormsg": "Errors found. Please make sure there are no empty or duplicate parameter names, and that the parameter name does not include \"$1\", \"$2\" or \"$3\".",
"templatedata-modal-errormsg-import-noparams": "No new parameters found during import.",
"templatedata-modal-errormsg-import-paramsalreadyexist": "Some parameters were not imported, because they already exist in the editor: $1",
"templatedata-modal-notice-import-numparams": "$1 new {{PLURAL:$1|parameter was|parameters were}} imported.",
"templatedata-modal-table-param-actions": "Actions",
"templatedata-modal-table-param-aliases": "Aliases (comma separated)",
@ -46,14 +48,17 @@
"templatedata-modal-table-param-required": "Required",
"templatedata-modal-table-param-suggested": "Suggested",
"templatedata-modal-table-param-type": "Type",
"templatedata-modal-table-param-type-file": "File",
"templatedata-modal-table-param-type-content": "Content",
"templatedata-modal-table-param-type-unbalanced-wikitext": "Unbalanced wikitext",
"templatedata-modal-table-param-type-line": "Line",
"templatedata-modal-table-param-type-wiki-file-name": "File",
"templatedata-modal-table-param-type-number": "Number",
"templatedata-modal-table-param-type-boolean": "Boolean",
"templatedata-modal-table-param-type-date": "Date",
"templatedata-modal-table-param-type-page": "Page",
"templatedata-modal-table-param-type-wiki-page-name": "Page",
"templatedata-modal-table-param-type-string": "String",
"templatedata-modal-table-param-type-undefined": "Undefined",
"templatedata-modal-table-param-type-user": "User",
"templatedata-modal-table-param-type-wiki-user-name": "User",
"templatedata-modal-table-param-uneditablefield": "Uneditable",
"templatedata-modal-title": "Template documentation editor",
"templatedata-modal-title-templatedesc": "Template description",

View file

@ -32,6 +32,7 @@
"templatedata-invalid-value": "Error message when a property that cannot contain free-form text has an invalid value.\n* $1 - name of property. e.g. \"params.1.type\"",
"templatedata-invalid-length": "Error message when generated JSON's length exceed database limits.\n* $1 - length of generated JSON\n* $2 - maximal allowed length",
"templatedata-editbutton": "The label of the button to manage templatedata, appearing above the editor field.",
"templatedata-helplink": "The label of the link to the TemplateData documentation, appearing above the editor field.",
"templatedata-errormsg-jsonbadformat": "Error message that appears in case the JSON string is not possible to parse. The user is asked to either correct the json syntax or delete the values between the &lt;templatedata&gt; tags and try again.",
"templatedata-modal-button-addparam": "Button to add a parameter.\n{{Identical|Add parameter}}",
"templatedata-modal-button-apply": "Label of the apply button.\n{{Identical|Apply}}",
@ -39,7 +40,8 @@
"templatedata-modal-button-delparam": "Button to delete a parameter",
"templatedata-modal-button-importParams": "Label of the import button",
"templatedata-modal-errormsg": "Error message that appears in the TemplateData generator GUI in case there are empty, duplicate or invalid parameter names.\n\nInvalid characters are supplied as parameters to avoid parsing errors in translation strings.\n\nParameters:\n* $1 - pipe (<code>|</code>)\n* $2 - equal sign (<code>=</code>)\n* $3 - double curly brackets (<code><nowiki>}}</nowiki></code>)",
"templatedata-modal-errormsg-import-noparams": "Message that appears in the TemplateData generator GUI in case no template parameters were found during the import attempt.",
"templatedata-modal-errormsg-import-noparams": "Error message that appears in the TemplateData generator GUI in case no template parameters were found during the import attempt.",
"templatedata-modal-errormsg-import-paramsalreadyexist": "Error message that appears when some parameters were not imported from the template code because they already exist in the editor. $1 - list of parameters that were not imported.",
"templatedata-modal-notice-import-numparams": "Message that appears in the TemplateData generator GUI showing how many new parameters were imported into the GUI from an existing template.\n\nParameters:\n* $1 - number of parameters",
"templatedata-modal-table-param-actions": "Label for a table heading: Parameter actions in the table",
"templatedata-modal-table-param-aliases": "Label for a table heading: Aliases of the parameter, instruct the user to separate aliases with commas.",
@ -50,14 +52,17 @@
"templatedata-modal-table-param-required": "Label for a table heading: Required status of the parameter.\n{{Identical|Required}}",
"templatedata-modal-table-param-suggested": "Label for a table heading: Suggested status of the parameter.\n{{Identical|Suggested}}",
"templatedata-modal-table-param-type": "Label for a table heading: Type of the parameter.\n{{Identical|Type}}",
"templatedata-modal-table-param-type-file": "A possible parameter type: File\n{{Related|Templatedata-modal-table-param-type}}\n{{Identical|File}}",
"templatedata-modal-table-param-type-content": "A possible parameter type: Content\n{{Related|Templatedata-modal-table-param-type}}",
"templatedata-modal-table-param-type-unbalanced-wikitext": "A possible parameter type: Unbalanced wikitext\n{{Related|Templatedata-modal-table-param-type}}",
"templatedata-modal-table-param-type-line": "A possible parameter type: Line\n{{Related|Templatedata-modal-table-param-type}}",
"templatedata-modal-table-param-type-wiki-file-name": "A possible parameter type: File\n{{Related|Templatedata-modal-table-param-type}}\n{{Identical|File}}",
"templatedata-modal-table-param-type-number": "A possible parameter type: Number\n{{Related|Templatedata-modal-table-param-type}}\n{{Identical|Number}}",
"templatedata-modal-table-param-type-boolean": "A possible parameter type: Boolean\n{{Related|Templatedata-modal-table-param-type}}",
"templatedata-modal-table-param-type-date": "A possible parameter type: Date\n{{Related|Templatedata-modal-table-param-type}}\n{{Identical|Date}}",
"templatedata-modal-table-param-type-page": "A possible parameter type: Page\n{{Related|Templatedata-modal-table-param-type}}\n{{Identical|Page}}",
"templatedata-modal-table-param-type-wiki-page-name": "A possible parameter type: Page\n{{Related|Templatedata-modal-table-param-type}}\n{{Identical|Page}}",
"templatedata-modal-table-param-type-string": "A possible parameter type: String\n{{Related|Templatedata-modal-table-param-type}}\n{{Identical|String}}",
"templatedata-modal-table-param-type-undefined": "A possible parameter type: Undefined\n{{Related|Templatedata-modal-table-param-type}}\n{{Identical|Undefined}}",
"templatedata-modal-table-param-type-user": "A possible parameter type: User\n{{Related|Templatedata-modal-table-param-type}}\n{{Identical|User}}",
"templatedata-modal-table-param-type-wiki-user-name": "A possible parameter type: User\n{{Related|Templatedata-modal-table-param-type}}\n{{Identical|User}}",
"templatedata-modal-table-param-uneditablefield": "Placeholder text notifying the user the field is uneditable",
"templatedata-modal-title": "Title of the modal popup.",
"templatedata-modal-title-templatedesc": "The title for the template description textbox",

File diff suppressed because it is too large Load diff

View file

@ -3,46 +3,48 @@
font-size: 120%;
}
.tdg-editTable {
.tdg-editscreen-main-helplink {
margin-left: 15px;
}
.tdg-parameters-table {
width: 100%;
}
.tdg-editTable th, .tdg-editTable td{
padding:0;
.tdg-editTable th,
.tdg-parameters-table td {
padding: 0;
}
.tdg-editTable > tbody > tr {
vertical-align: top;
}
.tdg-editTable th {
.tdg-parameters-table th {
text-align: left;
}
.tdg-editTable > tbody > tr > td:hover,
.tdg-editTable > tbody > tr:hover > td {
.tdg-parameters-table > tbody > tr:hover > td {
background-color: #BECDD4;
}
.tdg-editTable input,
.tdg-editTable select,
.tdg-editTable textarea,
.tdg-template-description{
.tdg-parameters-table input,
.tdg-parameters-table select,
.tdg-parameters-table textarea,
.tdg-template-description {
background: transparent;
border: 1px solid #999999;
padding: 5px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
}
.tdg-editTable input:not([type="checkbox"]),
.tdg-editTable select,
.tdg-editTable textarea{
.tdg-parameters-table input:not([type="checkbox"]),
.tdg-parameters-table select,
.tdg-parameters-table textarea {
width: 100%;
border: 1px solid #999999;
padding: 5px;
height: 40px;
}
.tdg-editTable .tdg-title-delbutton, .tdg-title-required {
.tdg-editTable .tdg-title-delbutton,
.tdg-title-required {
width: 80px;
}
.tdg-editTable .tdg-attr-required {
@ -63,26 +65,25 @@
background-color: #F2CBCB;
}
/** Start small, grow on focus: */
.tdg-title-name,
.tdg-title-aliases,
.tdg-title-label {
.tdg-not-in-template {
background: #E6E6FF;
}
/* Start small, grow on focus: */
.tdg-table-head-delbutton {
width: 100px;
}
.tdg-element-attr-name,
.tdg-element-attr-aliases,
.tdg-element-attr-label {
.tdg-table-head-suggested,
.tdg-table-head-required {
width: 100px;
}
.tdg-element-attr-name:focus,
.tdg-element-attr-aliases:focus,
.tdg-element-attr-label:focus {
width: 200px;
textarea.param-type-input:focus,
input[type="text"].param-type-input:focus {
min-width: 200px;
}
.tdg-element-attr-description:focus,
.tdg-element-attr-default:focus {
textarea.param-type-input:focus {
height: 70px;
}

View file

@ -7,35 +7,12 @@
*/
'use strict';
$( document ).ready(function () {
var tmplDataGen, editboxObjects,
$textbox = $( '#wpTextbox1' );
$( function () {
var $textbox = $( '#wpTextbox1' );
// Check if there's an editor textarea and if we're in the proper namespace
if ( $textbox.length > 0 && mw.config.get( 'wgCanonicalNamespace' ) === 'Template' ) {
tmplDataGen = mw.libs.templateDataGenerator;
editboxObjects = tmplDataGen.init();
// Add the button and modal element to the document
$( '#mw-content-text' )
.prepend(
editboxObjects.$modalBox,
editboxObjects.$errorBox,
editboxObjects.$editButton
);
$( '.tdg-editscreen-main-button' ).click( function () {
var $modalBox = tmplDataGen.createModal( $textbox.val() );
// open the dialog
$modalBox.dialog( 'open' );
// respond to modal close event
$modalBox.on( 'TemplateDataGeneratorDone', function ( e, output ) {
$textbox.val( output );
} );
} );
if ( $textbox.length && mw.config.get( 'wgCanonicalNamespace' ) === 'Template' ) {
mw.libs.templateDataGenerator.init( $( '#mw-content-text' ), $textbox );
}
} );

View file

@ -7,266 +7,205 @@
QUnit.module( 'ext.templateData', QUnit.newMwEnvironment() );
var wikitext = 'Some initial test sentence.\n' +
'<templatedata>\n' +
'{\n' +
' "description": "This is a description of the template.",\n' +
var originalWikitext = 'Some text here that is not templatedata information.' +
'<templatedata>' +
'{' +
' "description": "Label unsigned comments in a conversation.",' +
' "params": {' +
' "user": {' +
' "label": "Username",' +
' "type": "wiki-user-name",' +
' "required": true,' +
' "description": "User name of person who forgot to sign their comment.",' +
' "aliases": ["1"]' +
' },' +
' "date": {' +
' "label": "Date",' +
' "description": {' +
' "en": "Timestamp of when the comment was posted, in YYYY-MM-DD format."' +
' },' +
' "aliases": ["2"],' +
' "suggested": true' +
' },' +
' "year": {' +
' "label": "Year",' +
' "type": "number"' +
' },' +
' "month": {' +
' "label": "Month",' +
' "inherits": "year"' +
' },' +
' "day": {' +
' "label": "Day",' +
' "inherits": "year"' +
' },' +
' "comment": {' +
' "required": false' +
' }' +
' },' +
' "sets": [' +
' {' +
' "label": "Date",' +
' "params": ["year", "month", "day"]' +
' }' +
' ]' +
'}' +
'</templatedata>' +
'Trailing text at the end.',
finalJsonStringOnly = '{\n' +
' "description": "Label unsigned comments in a conversation.",\n' +
' "params": {\n' +
' "user": {\n' +
' "label": "Username",\n' +
' "type": "string/wiki-user-name",\n' +
' "default": "some default value here.",\n' +
' "required": true,\n' +
' "description": { "en": "User who forgot to sign their comment." },\n' +
' "aliases": ["1"]\n' +
' "label": "New user label",\n' +
' "type": "wiki-user-name",\n' +
' "description": "User name of person who forgot to sign their comment.",\n' +
' "aliases": [\n' +
' "1"\n' +
' ]\n' +
' },\n' +
' "date": {\n' +
' "label": "Date",\n' +
' "aliases": ["2", "3"]\n' +
' "description": {\n' +
' "en": "Timestamp of when the comment was posted, in YYYY-MM-DD format."\n' +
' },\n' +
' "aliases": [\n' +
' "2"\n' +
' ],\n' +
' "suggested": true\n' +
' },\n' +
' "year": {\n' +
' "label": "Year",\n' +
' "type": "number"\n' +
' },\n' +
' "month": {\n' +
' "label": "Month",\n' +
' "inherits": "year"\n' +
' },\n' +
' "comment": {\n' +
' "required": false\n' +
' },\n' +
' "someNewParameter": {\n' +
' "required": true\n' +
' }\n' +
' }\n' +
'}\n' +
'</templatedata>\n' +
'Some following sentence.';
' },\n' +
' "sets": [\n' +
' {\n' +
' "label": "Date",\n' +
' "params": [\n' +
' "year",\n' +
' "month",\n' +
' "day"\n' +
' ]\n' +
' }\n' +
' ]\n' +
'}',
tdManualParamsObject = {
'user': {
// The parameter data model adds 'name' attribute
'name': 'user',
'label': 'Username',
'type': 'wiki-user-name',
'required': true,
'description': 'User name of person who forgot to sign their comment.',
'aliases': ['1']
},
'date': {
'name': 'date',
'label': 'Date',
'description': {
'en': 'Timestamp of when the comment was posted, in YYYY-MM-DD format.'
},
'aliases': ['2'],
'suggested': true
},
'year': {
'name': 'year',
'label': 'Year',
'type': 'number'
},
'month': {
'name': 'month',
'label': 'Month',
'inherits': 'year'
},
'day': {
'name': 'day',
'label': 'Day',
'inherits': 'year'
},
'comment': {
'name': 'comment',
'required': false
}
};
QUnit.test( 'TemplateData modal display', 11, function ( assert ) {
var $modalBox, tmplDataGenTest1;
/** Parameter data model tests **/
QUnit.asyncTest( 'TemplateData Parameter Model', 6, function ( assert ) {
var tdgTests;
tmplDataGenTest1 = mw.libs.templateDataGenerator;
tmplDataGenTest1.init();
mw.libs.templateDataGenerator.init( null, null, { 'useGUI': false, 'fetchCodeFromSource': false } );
tdgTests = mw.libs.templateDataGenerator.tests;
// Load data into model
$modalBox = tmplDataGenTest1.createModal( wikitext );
tdgTests.loadTemplateDataJson( originalWikitext ).done( function ( pmodel ) {
// Tests
assert.deepEqual(
tdManualParamsObject,
pmodel,
'Loading parameters data model'
);
// Tests
assert.equal(
$modalBox.find( '.tdg-template-description' ).val(),
'This is a description of the template.',
'Template description'
);
// Make sure description sticks
assert.equal(
tdgTests.getTDMeta().description,
'Label unsigned comments in a conversation.',
'Template description.'
);
assert.equal(
$modalBox.find( '.tdg-element-attr-name' ).length,
4,
'Number of parameters in edit modal table.'
);
// Change attributes
tdManualParamsObject.user.label = 'New user label';
delete tdManualParamsObject.user.required;
// Check for proper parsing
assert.equal(
$modalBox.find( '#param-user .tdg-element-attr-name' ).val(),
'user',
'Parameter details: name.'
);
tdgTests.modelUpdateParamAttribute( 'user', 'label', 'New user label' );
tdgTests.modelUpdateParamAttribute( 'user', 'required', false );
assert.equal(
$modalBox.find( '#param-date .tdg-element-attr-aliases' ).val(),
'2,3',
'Parameter details: aliases (multiple).'
);
assert.deepEqual(
tdManualParamsObject,
pmodel,
'Changing parameter attributes'
);
assert.equal(
$modalBox.find( '#param-user .tdg-element-attr-aliases' ).val(),
'1',
'Parameter details: aliases (single).'
);
// Add parameter
tdManualParamsObject.newparam = { 'name': 'someNewParameter', 'required': true };
tdgTests.modelAddParam( 'newparam', { 'name': 'someNewParameter', 'required': true } );
assert.equal(
$modalBox.find( '#param-user .tdg-element-attr-label' ).val(),
'Username',
'Parameter details: label.'
);
assert.deepEqual(
tdManualParamsObject,
pmodel,
'Adding a new parameter'
);
// HACK: This is commented-out because the functionality is temporarily disabled for blocks
/* assert.equal(
$modalBox.find( '#param-user .tdg-element-attr-description' ).val(),
'User who forgot to sign their comment.',
'Parameter details: description.'
);*/
assert.equal(
$modalBox.find( '#param-user .tdg-element-attr-description' ).data( 'tdg-uneditable' ),
true,
'Block description as object: parameter description.'
);
// Delete a parameter
delete tdManualParamsObject.day;
tdgTests.modelDeleteParam( 'day' );
assert.equal(
$modalBox.find( '#param-user .tdg-element-attr-type' ).val(),
'string/wiki-user-name',
'Parameter details: type.'
);
assert.deepEqual(
tdManualParamsObject,
pmodel,
'Deleting a parameter'
);
assert.equal(
$modalBox.find( '#param-user .tdg-element-attr-default' ).val(),
'some default value here.',
'Parameter details: default.'
);
// Outputting final templatedata string
assert.equal(
finalJsonStringOnly,
tdgTests.modelOutputJsonString(),
'Outputting templatedata json string from model'
);
assert.equal(
$modalBox.find( '#param-user .tdg-element-attr-required' ).prop( 'checked' ),
true,
'Parameter details: required.'
);
assert.equal(
$modalBox.find( '#param-year .tdg-element-attr-required' ).prop( 'checked' ),
false,
'Parameter details: non required.'
);
} );
QUnit.test( 'TemplateData JSON manipulation', 4, function ( assert ) {
var $modalDomElements, parsedJson, expectedTextResult,
exampleJson, changedParsedJson, reparsedJson,
tmplDataGenTest2 = mw.libs.templateDataGenerator,
origText = 'Some initial test sentence.\n' +
'<templatedata>\n' +
'{\n' +
' "description": "This is a description of the template.",\n' +
' "params": {\n' +
' "user": {\n' +
' "label": "Username",\n' +
' "type": "string/wiki-user-name",\n' +
' "default": "some default value here.",\n' +
' "required": true,\n' +
' "description": "User name of person who forgot to sign their comment.",\n' +
' "aliases": ["1"]\n' +
' },\n' +
' "date": {\n' +
' "label": "Date",\n' +
' "aliases": ["2", "3"]\n' +
' },\n' +
' "year": {\n' +
' "label": "Year",\n' +
' "type": "number"\n' +
' },\n' +
' "comment": {\n' +
' "required": false,\n' +
' "somethingelse": "this should stay"\n' +
' }\n' +
' },\n' +
' "testing": {\n' +
' "something": {\n' +
' "completely": "random"\n' +
' }\n' +
' }\n' +
'}\n' +
'</templatedata>\n' +
'Some following sentence.';
parsedJson = tmplDataGenTest2.parseTemplateData( origText );
assert.equal(
parsedJson.testing.something.completely,
'random',
'Parse original JSON and preserve all data.'
);
// Copy the parsed JSON object so we can manually
// manipulate it
changedParsedJson = $.extend( true, {}, parsedJson );
// Partial dom elements on purpose, to make sure
// that the rest of the json object, even fields that are
// not represented in the dom elements, are preserved
$modalDomElements = {
'user': {
'name': $( '<input>' ).val( 'user' ),
'label': $( '<input>' ).val( 'changed to another label' )
}
};
// Manually change the object we copied earlier to test against
changedParsedJson.params.user.label = 'changed to another label';
assert.deepEqual(
mw.libs.templateDataGenerator.applyChangesToJSON( parsedJson, $modalDomElements, true ),
changedParsedJson,
'Preserve parameters on edit.'
);
// Name change
// Notice, parsedJson also had its user.label change, so we have
// to do the same to our new test and change both label and name.
$modalDomElements = {
'user': {
'name': $( '<input>' ).val( 'anotherName' ),
'label': $( '<input>' ).val( 'changed to another label' )
}
};
// Copy the parsed JSON object so we can manually
// manipulate it
changedParsedJson = $.extend( true, {}, parsedJson );
changedParsedJson.params.anotherName = {};
$.extend( true, changedParsedJson.params.anotherName, parsedJson.params.user );
delete changedParsedJson.params.user;
// Re-parse the json so we can manipulate it in exampleJson
reparsedJson = mw.libs.templateDataGenerator.parseTemplateData( origText );
// Get the system's response to changing the name
exampleJson = mw.libs.templateDataGenerator.applyChangesToJSON( reparsedJson, $modalDomElements, true );
assert.deepEqual(
exampleJson,
changedParsedJson,
'Change parameter name.'
);
// Back to wikitext
// Since 'parsedJson' was changed in previous tests, we'll use it
expectedTextResult = 'Some initial test sentence.\n' +
'<templatedata>\n' +
'{\n' +
' "description": "This is a description of the template.",\n' +
' "params": {\n' +
' "date": {\n' +
' "label": "Date",\n' +
' "aliases": [\n' +
' "2",\n' +
' "3"\n' +
' ]\n' +
' },\n' +
' "year": {\n' +
' "label": "Year",\n' +
' "type": "number"\n' +
' },\n' +
' "comment": {\n' +
' "required": false,\n' +
' "somethingelse": "this should stay"\n' +
' },\n' +
' "anotherName": {\n' +
' "label": "changed to another label",\n' +
' "type": "string/wiki-user-name",\n' +
' "default": "some default value here.",\n' +
' "required": true,\n' +
' "description": "User name of person who forgot to sign their comment.",\n' +
' "aliases": [\n' +
' "1"\n' +
' ]\n' +
' }\n' +
' },\n' +
' "testing": {\n' +
' "something": {\n' +
' "completely": "random"\n' +
' }\n' +
' }\n' +
'}\n' +
'</templatedata>\n' +
'Some following sentence.';
// Using 'exampleJson' with the previous name change and label change
assert.equal(
mw.libs.templateDataGenerator.amendWikitext( exampleJson, origText ),
expectedTextResult,
'Returning edited json into original wikitext.'
);
} )
.always( function () {
QUnit.start();
} );
} );