From 9aaeac3318483d0d82382ae5c870523fcff8b1e0 Mon Sep 17 00:00:00 2001 From: WMDE-Fisch Date: Wed, 18 Aug 2021 14:43:46 +0200 Subject: [PATCH] Add getters for un-/documented parameters Will be needed to figure out when the new UI to add parameters should be visible. Bug: T272487 Change-Id: I97d2429b7845905784ef18e9d41cd5e6f85bbd01 --- .../dm/models/ve.dm.MWTemplateSpecModel.js | 17 ++++++++++++----- .../dm/models/ve.dm.MWTemplateSpecModel.test.js | 10 ++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js b/modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js index 95d8316c5e..fac1b2bf5c 100644 --- a/modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js +++ b/modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js @@ -171,7 +171,6 @@ ve.dm.MWTemplateSpecModel.prototype.isDocumented = function () { * parameters as they appear in TemplateData. Returns a copy, i.e. it's safe to manipulate the * array. * - * @private * @return {string[]} Preferred order of parameters via TemplateData, if given */ ve.dm.MWTemplateSpecModel.prototype.getDocumentedParameterOrder = function () { @@ -180,6 +179,17 @@ ve.dm.MWTemplateSpecModel.prototype.getDocumentedParameterOrder = function () { Object.keys( this.templateData.params ); }; +/** + * @return {string[]} + */ +ve.dm.MWTemplateSpecModel.prototype.getUndocumentedParameterNames = function () { + var documentedParameters = this.templateData.params; + + return this.getKnownParameterNames().filter( function ( name ) { + return !( name in documentedParameters ); + } ); +}; + /** * Same as {@see getKnownParameterNames}, but in a canonical order that's always the same, unrelated * to how the parameters appear in the wikitext. Primary parameter names documented via TemplateData @@ -189,10 +199,7 @@ ve.dm.MWTemplateSpecModel.prototype.getDocumentedParameterOrder = function () { * @return {string[]} */ ve.dm.MWTemplateSpecModel.prototype.getCanonicalParameterOrder = function () { - var documentedParameters = this.templateData.params, - undocumentedParameters = this.getKnownParameterNames().filter( function ( name ) { - return !( name in documentedParameters ); - } ); + var undocumentedParameters = this.getUndocumentedParameterNames(); undocumentedParameters.sort( function ( a, b ) { var aIsNaN = isNaN( a ), diff --git a/modules/ve-mw/tests/dm/models/ve.dm.MWTemplateSpecModel.test.js b/modules/ve-mw/tests/dm/models/ve.dm.MWTemplateSpecModel.test.js index 11e36e1801..aadb0eb05e 100644 --- a/modules/ve-mw/tests/dm/models/ve.dm.MWTemplateSpecModel.test.js +++ b/modules/ve-mw/tests/dm/models/ve.dm.MWTemplateSpecModel.test.js @@ -30,6 +30,7 @@ assert.strictEqual( spec.getLabel(), 'RawTemplateName', 'getLabel' ); assert.strictEqual( spec.getDescription(), null, 'getDescription' ); assert.deepEqual( spec.getDocumentedParameterOrder(), [], 'getDocumentedParameterOrder' ); + assert.deepEqual( spec.getUndocumentedParameterNames(), [], 'getUndocumentedParameterNames' ); assert.strictEqual( spec.isKnownParameterOrAlias( 'unknown' ), false, 'isKnownParameterOrAlias' ); assert.strictEqual( spec.isParameterAlias( 'unknown' ), false, 'isParameterAlias' ); assert.strictEqual( spec.getParameterLabel( 'unknown' ), 'unknown', 'getParameterLabel' ); @@ -57,6 +58,7 @@ assert.strictEqual( spec.getLabel(), 'RawTemplateName', 'getLabel' ); assert.strictEqual( spec.getDescription(), null, 'getDescription' ); assert.deepEqual( spec.getDocumentedParameterOrder(), [], 'getDocumentedParameterOrder' ); + assert.deepEqual( spec.getUndocumentedParameterNames(), [ 'p1', 'p2' ], 'getUndocumentedParameterNames' ); assert.strictEqual( spec.isKnownParameterOrAlias( 'p2' ), true, 'isKnownParameterOrAlias' ); assert.strictEqual( spec.isParameterAlias( 'p2' ), false, 'isParameterAlias' ); assert.strictEqual( spec.getParameterLabel( 'p2' ), 'p2', 'getParameterLabel' ); @@ -87,6 +89,7 @@ assert.strictEqual( spec.getLabel(), 'RawTemplateName', 'getLabel' ); assert.strictEqual( spec.getDescription(), null, 'getDescription' ); assert.deepEqual( spec.getDocumentedParameterOrder(), [], 'getDocumentedParameterOrder' ); + assert.deepEqual( spec.getUndocumentedParameterNames(), [ 'p1', 'p2' ], 'getUndocumentedParameterNames' ); assert.strictEqual( spec.isKnownParameterOrAlias( 'p2' ), true, 'isKnownParameterOrAlias' ); assert.strictEqual( spec.isParameterAlias( 'p2' ), false, 'isParameterAlias' ); assert.strictEqual( spec.getParameterLabel( 'p2' ), 'p2', 'getParameterLabel' ); @@ -120,6 +123,7 @@ spec.setTemplateData( templateData ); assert.deepEqual( spec.getDocumentedParameterOrder(), [], 'getDocumentedParameterOrder' ); + assert.deepEqual( spec.getUndocumentedParameterNames(), [], 'getUndocumentedParameterNames' ); assert.strictEqual( spec.getParameterLabel( 'p' ), 'p', 'getParameterLabel' ); assert.strictEqual( spec.getParameterDescription( 'p' ), null, 'getParameterDescription' ); assert.deepEqual( spec.getParameterSuggestedValues( 'p' ), [], 'getParameterSuggestedValues' ); @@ -144,6 +148,7 @@ assert.strictEqual( spec.getLabel(), 'RawTemplateName', 'getLabel' ); assert.strictEqual( spec.getDescription(), null, 'getDescription' ); assert.deepEqual( spec.getDocumentedParameterOrder(), [ 'p2' ], 'getDocumentedParameterOrder' ); + assert.deepEqual( spec.getUndocumentedParameterNames(), [ 'p1' ], 'getUndocumentedParameterNames' ); assert.strictEqual( spec.isKnownParameterOrAlias( 'p2' ), true, 'isKnownParameterOrAlias' ); assert.strictEqual( spec.isParameterAlias( 'p2' ), false, 'isParameterAlias' ); assert.strictEqual( spec.getParameterLabel( 'p2' ), 'p2', 'getParameterLabel' ); @@ -193,6 +198,7 @@ assert.strictEqual( spec.getLabel(), 'RawTemplateName', 'getLabel' ); assert.strictEqual( spec.getDescription(), 'TemplateDescription', 'getDescription' ); assert.deepEqual( spec.getDocumentedParameterOrder(), [ 'DummyOrder' ], 'getDocumentedParameterOrder' ); + assert.deepEqual( spec.getUndocumentedParameterNames(), [], 'getUndocumentedParameterNames' ); assert.strictEqual( spec.isKnownParameterOrAlias( 'a' ), true, 'isKnownParameterOrAlias' ); assert.strictEqual( spec.isParameterAlias( 'a' ), true, 'isParameterAlias' ); assert.strictEqual( spec.getParameterLabel( 'a' ), 'ParamLabel', 'getParameterLabel' ); @@ -220,12 +226,14 @@ assert.strictEqual( spec.isParameterAlias( 'p1-alias' ), false ); assert.strictEqual( spec.getParameterLabel( 'p1-alias' ), 'p1-alias' ); assert.deepEqual( spec.getKnownParameterNames(), [ 'p0', 'p1-alias', 'p2' ] ); + assert.deepEqual( spec.getUndocumentedParameterNames(), [ 'p0', 'p1-alias', 'p2' ], 'getUndocumentedParameterNames' ); spec.setTemplateData( { params: { p1: { aliases: [ 'p1-alias' ] } } } ); assert.strictEqual( spec.isParameterAlias( 'p1-alias' ), true ); assert.strictEqual( spec.getParameterLabel( 'p1-alias' ), 'p1-alias' ); assert.deepEqual( spec.getKnownParameterNames(), [ 'p0', 'p1', 'p2' ] ); + assert.deepEqual( spec.getUndocumentedParameterNames(), [ 'p0', 'p2' ], 'getUndocumentedParameterNames' ); } ); QUnit.test( 'Alias conflicts with another parameter', ( assert ) => { @@ -254,10 +262,12 @@ spec.setTemplateData( { params: { color: { aliases: [ 'colour' ] } } } ); assert.deepEqual( spec.getKnownParameterNames(), [ 'color' ] ); + assert.deepEqual( spec.getUndocumentedParameterNames(), [], 'getUndocumentedParameterNames' ); spec.fillFromTemplate(); assert.deepEqual( spec.getKnownParameterNames(), [ 'color' ] ); + assert.deepEqual( spec.getUndocumentedParameterNames(), [], 'getUndocumentedParameterNames' ); } ); [