Commit graph

185 commits

Author SHA1 Message Date
jenkins-bot e88c445920 Merge "Add tests for MWTemplateSpecModel.getTitle()" 2021-09-20 14:41:30 +00:00
Thiemo Kreuz 696d066829 Add tests for MWTemplateSpecModel.getTitle()
I was (again) wondering why the try-catch is there. But it's actually
needed. Now covered by a test.

Bug: T290140
Bug: T291062
Change-Id: Iccc7274ed9e7b81b8491dbca7d3d771706b0ed09
2021-09-20 16:04:22 +02:00
Andrew Kostka 65e3ce0787 Drop substitution prefixes before querying for TemplateData
Bug: T290140
Change-Id: I57924df9b6d4d6e24c54b85f044072e216478e68
2021-09-20 10:17:39 +02:00
Thiemo Kreuz 5351217cc4 Add test for MWTemplateModel.getOriginalParameterName()
Bug: T285869
Change-Id: I4318af044037b5c7b3d661c5da54754ca883967b
2021-09-13 18:22:16 +00:00
jenkins-bot 26b3f5abf0 Merge "Consistent use of .forEach() in QUnit tests" 2021-09-13 13:41:28 +00:00
Gergő Tisza 986e5ab4d2
MWInternalLinkAnnotation: Make test work with both fragment modes
Avoid breaking the test if $wgFragmentMode has html5 first.

Bug: T186267
Bug: T290464
Change-Id: I0c846173c06698eb039ed289ad202fd3539e61a9
2021-09-11 17:41:22 -07:00
Thiemo Kreuz 3f97610e6e Add tests for .containsValuableData() methods
Bug: T272355
Bug: T290554
Change-Id: Icebf7139ed64cdad49522f7b082d1925a9a4a21b
2021-09-10 15:38:28 +00:00
Thiemo Kreuz f8cdcfe129 Consistent use of .forEach() in QUnit tests
* The extra brackets are not needed in ES6.
* Make sure the name of the test is on the next line. This makes
  the code easier to read.

Change-Id: Ib871dbfa27fcadc88e7335b9efb4d583bd4300ac
2021-09-07 14:27:25 +02:00
Thiemo Kreuz 9dbbc06273 Fix …TemplateSpecModel reporting missing pages as documented
The code in .cacheTemplateDataApiResponse() where the `specCache`
is filled skips missing pages. .setTemplateData() is never called.
While we could – in theory – check the `missing` flag (as done in
patchset 1), this flag never makes it to the spec.

Rather simple solution: Mark everything as undocumented, as long
as .setTemplateData() is not called.

This affects only missing pages. .setTemplateData() is called in
all other situations.

Bug: T272487
Bug: T276574
Bug: T290136
Change-Id: I7045e84f2f2ba5aa4591c94ea495b0249e6c40d6
2021-09-01 14:59:03 +02:00
Thiemo Kreuz 55beccbb79 Tests for some trivial but critical template model methods
Not only do we want to make sure getUniquePartId() always starts
at 0 and increments correctly, it should return a number (and
not e.g. "part_0").

I realize the getTitle() test is also testing functionality from
mw.libs.ve.… (can be found in the file ve.utils.parsoid.js).
This is intentional. What we care about at this point is not a
library but the very specific functionality of a very specific
method we use quite a lot in code we touch.

Bug: T289560
Change-Id: I43c1d00dacf27a68b16f62ecca4adda22f437391
2021-08-27 12:49:06 +00:00
Thiemo Kreuz a0e613d8fc Remove not needed boilerplate from QUnit tests
These tests obviously don't need this extra environment.
They run just fine (and faster) without.

Bug: T289560
Change-Id: Ib186a07cd556f741e0440ffa54ae6aaaf626adcd
2021-08-25 12:01:14 +00:00
WMDE-Fisch 9aaeac3318 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
2021-08-19 07:00:30 +00:00
Thiemo Kreuz b264a9c381 Add isDocumented() feature to ve.dm.MWTemplateSpecModel
Bug: T272487
Change-Id: I39c612358cc0238c515c8eb28aa1b40418a10cef
2021-08-13 12:47:28 +02:00
Thiemo Kreuz (WMDE) 8d9b4526c6 Revert "Hide deprecated parameters if they don't have a value"
This reverts commit 0d4dee341b.

Reason for revert: This made it entirely impossible to add a
deprecated parameter, even if done intentionally. Needs more tests.

Bug: T274551
Change-Id: I7389bad0845cd1ce78f9d7ef71592cb1ce2a063e
2021-08-03 08:24:24 +00:00
Andrew Kostka 0d4dee341b Hide deprecated parameters if they don't have a value
Bug: T274551
Change-Id: I6bfceae2579a5bcedae9da7eb5326fe8f60ea7c0
2021-07-22 12:24:57 +02:00
Thiemo Kreuz 3cd91100a9 Move code that belongs to the template specification
Separation of concerns:
* The template model knows which parameters are currently used,
  but doesn't know what's documented.
* The spec knows what's documented, but doesn't know what's
  currently used.

Change-Id: I97cac00d6775a17a07059d0e8a7a116adc6080b3
2021-07-07 16:45:35 +02:00
Thiemo Kreuz 9624f61701 Add missing test case with template parameter placeholder
There are some methods that behave different when a parameter
placeholder (where the parameter name is "") is present. Some
skip placeholders, some don't. This is critical to cover
before we make further changes to this class.

What I also do in this patch:
* Use shorter variable names to make the code easier to read.
* Don't reuse the `transclusionData` variable but use a copy
  of the expected value. This makes the assertions much
  easier to understand.
* Bring every test in the same "setup" → "execute" → "assert"
  order.

Change-Id: I41a691c56bc509b132dc719ff820ae1ade4ccc3a
2021-07-07 15:53:40 +02:00
jenkins-bot de71ebc9de Merge "Simplify ve.dm.MWTemplateModel.hasParameter() a lot" 2021-07-06 08:23:15 +00:00
jenkins-bot 4a5f811c82 Merge "Keep template parameter position when resolving aliases" 2021-07-05 11:44:19 +00:00
Thiemo Kreuz fbb7d211d0 Simplify ve.dm.MWTemplateModel.hasParameter() a lot
A lot of the checks are redundant. The first check still is
redundant because the later two cover everything as well. But
I left it for performance reasons.

Additionally:
* There was no test for the method.
* This patch also updates a few pieces of documentation in the
  same class.

Change-Id: I10f2944a844cc070bdc08dec6719929b383e34fa
2021-07-05 11:58:42 +02:00
Andrew Kostka 6af13f0d42 Fix parameter ordering when using aliases
If a known parameter is present using one of it's aliases, then
only the aliased name should be shown to the user. This patch,
therefore, resolves the issue of the same parameter being added
to the sidebar twice.

When adding a parameter that is aliased, it will receive the same
position as the non-aliased parameter it is replacing.

Bug: T274545
Change-Id: If4e58c941fd0f0e690d3603935f5a5d3f9938163
2021-07-05 08:14:42 +00:00
Thiemo Kreuz 8d0a623f40 Keep template parameter position when resolving aliases
This fixes a minor issue in the spec class. In the first step,
parameters from the template are added to the list of known
parameters. Later, aliases are resolved. The original behavior
was that such a parameter moved to the end of the list. This
is rather unexpected.

This dosn't have much of an impact. The pretty much only place
where the parameter order from the spec can be seen is in the
parameter search widget. Still I believe it's worth fixing.

Bug: T285483
Change-Id: I455818451811e92bba3e9320c2d41e1db8d563f2
2021-07-03 20:14:06 +02:00
Thiemo Kreuz 280ba23e2c Add missing fail-safe to MWTemplateSpecModel.extend()
I don't want this code to crash when the TemplateData API
returns an unexpected result.

Bug: T285483
Change-Id: I237cbfbb85892a53a08d9e7e34cf4974775d627a
2021-07-02 17:52:43 +02:00
Thiemo Kreuz 07344fce0f Rename misleading "extend" method in template spec class
This doesn't "extend". It was never used like this. What it
actually does is to link between a (cached) TemplateData blob
and the spec class that want's to use it.

Is this the best possible name?
* fillFromTemplateData( … )?
* propagateTemplateDocumentation( … )?
* readDocumentationFrom( templateData )?
* …?

Do we want to rename the "spec" class as well?
* MWTemplateDocumentation?
* MWTemplateMetadata?
* MWTemplateDataAccessor?
* …?

Bug: T285483
Change-Id: I6c52ef42d411c2f47fc0080768d36ebda4dd2a55
2021-07-02 11:26:04 +00:00
jenkins-bot 2e4ac455f0 Merge "Add more edge-case test cases for template spec class" 2021-07-01 18:57:51 +00:00
Thiemo Kreuz 99523b855c Use and document the term "known parameter" in template code
The so called "spec" class keeps track of parameters that have
been used before, no matter if documented via TemplateData or
not. Removed parameters are still "known" (i.e. have been seen
before).

This feature allows to easily find previously used parameters
names when an undocumented parameter was removed and the user
tries to add it again.

Bug: T285483
Change-Id: Ia1555eea87cd99e7a3f386f4279ec5a80fb98a79
2021-07-01 12:03:38 +00:00
Thiemo Kreuz d8f4da199d Add more edge-case test cases for template spec class
Bug: T285483
Change-Id: I0a9bf7fe51242161dbc57c9301f360c9e8f35b93
2021-07-01 10:13:00 +02:00
jenkins-bot 127ea9ea27 Merge "Avoid the term "canonical order" in template related docs" 2021-06-30 11:35:27 +00:00
jenkins-bot 5943b5a25e Merge "Fix spec.fillFromTemplate() not skipping aliases any more" 2021-06-30 11:11:24 +00:00
jenkins-bot 6aaec0c88b Merge "Rename temporary "x" variable in spec class tests" 2021-06-30 11:09:54 +00:00
Thiemo Kreuz 84329a40c8 Rename temporary "x" variable in spec class tests
I forgot to give this variable a proper name. The "x" was not
meant to stay.

Bug: T285483
Change-Id: I482b9282676082f44d5f98a574e5ada05dfb6318
2021-06-30 12:16:50 +02:00
Thiemo Kreuz 466e428a81 Fix spec.fillFromTemplate() not skipping aliases any more
In I04b8a14fbec7be5a1c4defabf92e94f694c1e638 we sepearted params from
aliases. There we missed that re-filling the parameters from the 
template could re-add the aliases.

Bug: T285483
Bug: T285843
Change-Id: I1928b443a5f708bc8c57efa5ad0a86b5915b159c
2021-06-30 10:14:43 +00:00
Thiemo Kreuz bc4aeed86e Avoid the term "canonical order" in template related docs
While the term "canonical" is not wrong, I find it still
somewhat ambiguous.

1. "Canonical" could mean different things. E.g. is the order
of parameters as they appear in the article's wikitext the
"canonical" one? It's possible to argue like this, esp. if a
template doesn't have TemplateData documentation. In this case
the only order known is the one from the wikitext.

2. "Canonical" sounds like the parameters must be reordered.
But this should never happen. Not having dirty diffs is more
important than having the parameters in a specific order.

Bug: T285483
Change-Id: I23658d37fea50b727667677ac6a49066673b2135
2021-06-30 09:38:28 +02:00
Thiemo Kreuz 8dca99d38c Fix broken template serialization test setup
This was not really testing anything before. Introduced in
I76c6fe8.

Bug: T285382
Change-Id: I5f8343c9805b9a1adc2efdd13a103a7f1196e15b
2021-06-29 16:29:11 +02:00
Thiemo Kreuz b7d88c541b Fix all spec methods to not crash on unknown parameters
Change-Id: I16708b048a785f0712084bd2d087e4aab77fb72b
2021-06-25 08:36:23 +02:00
Thiemo Kreuz b8382513fc Use separate data structure to store aliases in spec
Wait, what's going on here? This patch looks like it changes the
behavior of this code. But it doesn't. Here is what happened
before:
* Let's say a template contains 2 parameters, A and B.
* We don't know yet if these names are aliases.
* getParameterNames() returns [ "A", "B" ].
* extend() is called. The TemplateData documentation contains
  the parameters "B" and "C". "C" does have an alias "A".
* extend() can't find "C" and adds it to the end, as if it's a
  new parameter.
* extend() also iterates the aliases. For each alias it creates
  a reference to the specification object. In this case a
  reference from "A" to "C" is created.
* But "A" already exists. The position of "A" doesn't change,
  but the specification now says it's an alias.
* getParameterNames() skips aliases. It skips "A" and instead
  returns the new "C" from the end of the list.

This was the behavior before. It's unchanged, proven by the tests.

Change-Id: I04b8a14fbec7be5a1c4defabf92e94f694c1e638
2021-06-25 08:29:48 +02:00
Thiemo Kreuz 8f6098c03b Simplify spec code dealing with default values
The idea is to not actually store all these default values, but
fall back to the default only when needed.

Some more details:
* The only remaining property is ….name. The only reason to
  have this property is to distinguish between aliases and
  primary parameter names. This will be reworked in a later
  patch.
* The description falls back to null because this is the
  documented fallback, not undefined.
* The default value falls back to "", same as the auto-value.
  Why not null you might ask. This is intentional. Both the
  auto- and default value are effectively wikitext snippets,
  while the example is a label in the VE UI.

Bug: T285483
Change-Id: I1be3cca18f9ad6fc1c16362b24633f7613f02539
2021-06-24 18:13:41 +02:00
Thiemo Kreuz bab08440ea Fix getDescription/Sets possibly returning undefined
This is done for two reasons:

1. It fixes the behavior of two methods in rare edge-case
situations. They aren't documented to return undefined.

2. It reduces the amount of stuff this class stores when it's
nothing but a default value anyway. Note this patch does this
for the template-level properties only. Another patch will do
the same for the parameter-level properties.

Bug: T285483
Change-Id: If2e4d56da1fa52e32dc94191f36d7dc6a1487829
2021-06-24 18:07:46 +02:00
Thiemo Kreuz 2529d33f51 Better name for spec.isParameterKnown() method
This reflects much better how this method is meant to behave.

Note I will continue to remove documentation that doesn't
explain anything in addition to what the code already says.

Bug: T285483
Change-Id: I81fa8a5d9d0752f3aeac4015c9a27b50e054d4df
2021-06-24 18:05:14 +02:00
Thiemo Kreuz 30dc85f53b Better name for spec.getParameterName() method
This reflects much better what the method is for.

Bug: T285483
Change-Id: I7c90643421e32946fce4de813c7614b806b261f0
2021-06-24 18:02:52 +02:00
Thiemo Kreuz 3d02c1f364 Add new QUnit test for ve.dm.MWTemplateSpecModel
This patch also marks 2 methods as @private that are not and
should not be used outside of this class.

Bug: T285483
Change-Id: I8a8ffc4868a369b5c47068beb0e83f023872543d
2021-06-24 17:59:38 +02:00
Adam Wight 1909fdff92 Revert "Revert "Fall back from explicit parameter order to TemplateData sort""
This reverts the revert commit d47b95eb4a.

When no `paramOrder` is given, known parameters should appear in the
order returned from the TemplateData API.

Previously, when TemplateData was present but no paramOrder
specified, then the parameters would appear in alphabetical order as
"unknown" parameters.  Now they will appear in the order listed in
TemplateData.  This is similar to the fully-specified behavior when
paramOrder is present.

This will only affect the Visual Editor template dialog, and has no
effect on serialization.

Bug: T274545
Change-Id: If8315781572af688ea1c1b14b3694b828f076b4a
2021-06-23 16:39:13 +02:00
Adam Wight 05bcb89f3f Tests for parameter serialization order
The results show that parameter order always follows the appearance
in the template invocation, regardless of `paramOrder`, whether the
parameters are aliased, or whether there are unknown params.

Bug: T285382
Change-Id: I76c6fe8f0a2482cf0856bbafd9f21ba9fc4919a4
2021-06-23 16:38:30 +02:00
Awight d47b95eb4a Revert "Fall back from explicit parameter order to TemplateData sort"
This reverts commit 12f3ce5ed3.

Reason for revert: Considered undesirable, per T138200

Change-Id: I089a47b41a0bb0405841690ca577035cf95a8016
2021-06-22 17:50:16 +00:00
Adam Wight 12f3ce5ed3 Fall back from explicit parameter order to TemplateData sort
When no `paramOrder` is given, known parameters should appear in the
order returned from the TemplateData API.

Previously, when TemplateData was present but no paramOrder
specified, then the parameters would appear in alphabetical order as
"unknown" parameters.  Now they will appear in the order listed in
TemplateData.  This is similar to the fully-specified behavior when
paramOrder is present.

This will only affect the Visual Editor template dialog.

Bug: T274545
Change-Id: I32538de07641c288081042a41fe39eedfed7d939
2021-06-22 13:24:44 +02:00
Adam Wight 33701872c7 Tests for getAllParametersOrdered
Note that the tests expose a bug, getAllParametersOrdered fails to
list an unused parameter.  Fixed in I32538de07641c.

Also, a minor fix to avoid an impossible template spec: paramOrder
must include all parameters.

Bug: T274545
Change-Id: Icfa7a765773d04ef05a76ecc09467305e311f6cb
2021-06-22 13:23:59 +02:00
Adam Wight 9e1c76f0fc Tests for MWTemplateModel parameter ordering
Documents existing logic.

Bug: T274545
Change-Id: Iebcbdb186862060724d29b36112b2d262112c4c8
2021-06-18 13:43:15 +02:00
Thiemo Kreuz 346216c050 Update more test code to use ES6 syntax
This patch is mostly about the arrow syntax.

Some places can not be updated because the arrow syntax also
changes the meaning of `this.…`, but some code relies on that.

Change-Id: Ida3ab0e0950a428fbd1a85f281013778ee879df4
2021-04-30 10:08:45 +00:00
Thiemo Kreuz 2611f907a9 Update all tests in the ve-mw module to use ES6 syntax
Change-Id: I75f8864c66c9b2a78c683d425d54a94515b74f24
2021-04-30 08:07:54 +00:00
Bartosz Dziewoński d23045bb0b Update VE core submodule to master (145cf95d8)
New changes:
2cbc5f9b2 Update OOUI to v0.41.2
e4e467a6b Use wrapper paragraphs in empty branch nodes

Bug: T65356
Change-Id: I222824c53e43f587c999b6478bec52ef686fed7e
2021-03-11 16:00:01 +00:00