Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add <$testcase> widget #7817

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open

Add <$testcase> widget #7817

wants to merge 41 commits into from

Conversation

Jermolene
Copy link
Owner

This PR adds a new <$testcase> widget to try to solve a problem with the examples that we feature in the documentation. The existing macros are workable for simple, self-contained examples, but can be extremely hard to follow in cases where the examples are also using additional tiddlers. The <$testcase> widget solves that problem by displaying interactive examples that show the output together with a tabbed display of the constituent tiddlers that produce it:

image

Try out the Vercel preview

The testcase widget is essentially a lightweight version of the existing <$innerwiki> plugin. It constructs an entirely separate wiki store object, fills it with the required tiddlers, and then renders a template that by default provides the tabbed view of the source tiddlers alongside the output.

The example above was generated with:

<$testcase>
<$data title="Description" text="How to calculate 2 plus 2"/>
<$data title="FirstNumber" text="2"/>
<$data title="SecondNumber" text="2"/>
<$data title="Output" text="<$text text={{{ [{FirstNumber}add{SecondNumber}] }}}/>"/>
</$testcase>

The <$data> widget that originated in the <$innerwiki> plugin is moved into the core and extended with support for reading tiddlers from "compound tiddlers", which are the special format used by the test suite for embedding multiple tiddlers within a single tiddler. Here is an example.

Our test cases are a useful form of documentation. The ultimate goal of this work is to be able to include our wikitext tests suite within the main documentation of TiddlyWiki. Advanced users wondering how \function works could dig down into potentially dozens of test cases to explore the behaviour of edge cases.

Progress:

  • Update some of the existing tw5.com examples to use the <$testcase> widget

This PR was cherry picked from #7406.

@vercel
Copy link

vercel bot commented Oct 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
tiddlywiki5 ✅ Ready (Inspect) Visit Preview May 15, 2024 11:40am

@pmario
Copy link
Contributor

pmario commented Oct 27, 2023

Looks good. Will need to run some tests.

@Jermolene
Copy link
Owner Author

Thanks @pmario I've pushed an update to fix those issues

@CodaCodr
Copy link
Contributor

RSOE
You can see the cursor in the screenshot

image

@Jermolene
Copy link
Owner Author

Thanks @CodaCodr I've just pushed a fix.

@CodaCodr
Copy link
Contributor

Thanks @CodaCodr I've just pushed a fix.

confirmed.

@CodaCodr
Copy link
Contributor

Look Mum! No ActionWidgets!

image

@DesignThinkerer
Copy link

DesignThinkerer commented Nov 3, 2023

CSS affect tiddlers outside of the testcase, is that intended?

image

@Jermolene
Copy link
Owner Author

CSS affect tiddlers outside of the testcase, is that intended?

The testcase widget shares the same rendering context as the main wiki and so CSS and other globla DOM properties are shared. In such cases the innerwiki widget can be used to create an entirely separate embedded wiki.

The purpose of the testcase widget is to be a lighter weight and more performant version of the innerwiki widget. It wouldn't be practical to use the innerwiki widget for hundreds of documentation examples; each of those iframes would overwhelm a mobile device.

The documentation needs to clarify the limitations and constraints of the testcase widget.

@Jermolene Jermolene marked this pull request as ready for review November 21, 2023 11:16
|<<.attr $compound-tiddler>> |Optional title of a tiddler containing payload tiddlers in `text/vnd.tiddlywiki-multiple` format (see below) |
|//any attribute<br>not starting<br>with $// |Field values to be assigned to the payload tiddler(s) |

The data widget is not rendered when used within the <<.wlink TestCaseWidget>> widget or the [[Innerwiki Plugin]] but for ease of testing, when used elsewhere it renders a JSON representation of the payload tiddlers.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when used elsewhere it renders a JSON representation of the payload tiddlers

I'm not able to get this behavior to work. Outside of the testcase widget, I find the data widget to render empty.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @btheado I had replaced that feature of the data widget with the ability for the testcase widget to display its payload in JSON via a special template. I've pushed an update with the docs in 0db4c44 that explains how to do that. I've also added the JSON output feature back to the data widget in 1d89c79 with tests in 0db4c44

The content of the `<$testcase>` widget is not displayed but instead is scanned for <<.wlink DataWidget>> widgets that define the payload tiddlers to be included in the test case. The `$:/core` plugin is automatically included in the payload.

|!Attribute |!Description |
|<<.attr template>> |Optional title of the template used to display the testcase (defaults to $:/core/ui/testcases/DefaultTemplate). Note that custom templates will need to be explicitly added to the payload |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention the other core provided template $:/core/ui/testcases/RawJSONTemplate as being useful for troubleshooting $data widgets?

</div>
<div class="tc-testcase-divider">
</div>
<div class="tc-testcase-output">
Copy link
Contributor

@btheado btheado Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to add a linkcatcher widget here and select the tab corresponding to the clicked link?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @btheado I've belatedly implemented your suggestion in Thank you @btheado in 648855e

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Works great!

@btheado
Copy link
Contributor

btheado commented May 8, 2024

@Jermolene, nice improvements! I like that test case tiddler titles are links to open the tiddler separately. Very useful. I also like the new Narrative feature.

The test case tiddlers and test case widget seem like a really good replacement for the wikitext-example-without-html macro. Having the widget examples be live-editable will be a great improvement. One nice feature of the wikitext-example macro is the "copy to clipboard" button. Have any thoughts about the equivalent for the test case widget?

Being able to easily copy the text of the example is useful. In addition or instead, maybe an easy way to get the json for all the tiddlers in the test case widget?

Tagging @AnthonyMuscio as I've seen him advocate for more use of "copy to clipboard" in the past.

@btheado
Copy link
Contributor

btheado commented May 8, 2024

Originally I was thinking all the uses of wikitext-example-without-html would be converted to test case tiddlers. Maybe that isn't necessary. A least as a first step is much easier to change the macro to use the test case widget.

For example, at https://tiddlywiki5-git-testcase-widget-jermolenes-projects.vercel.app/#%24%3A%2Feditions%2Ftw5.com%2Fwikitext-macros

Change this

\procedure wikitext-example-without-html(src)
<div class="doc-example">
	<$macrocall $name="copy-to-clipboard-above-right" src=<<src>>/>
	<$codeblock code=<<src>>/>
	<p>
		That renders as:
	</p>
	<$transclude $variable="src" $mode="block"/>
</div>
\end

to this

\procedure wikitext-example-without-html(src)
    <$macrocall $name="copy-to-clipboard-above-right" src=<<src>>/>
    <$testcase>
        <$data title="Output" text=<<src>>/>
    </$testcase>
\end

@btheado
Copy link
Contributor

btheado commented May 10, 2024

I'm seeing some strange rendering behavior regarding <<currentTiddler>> variable

With the following test case tiddler, the test case is passing. It must be finding <<currentTiddler>> to match Output

However, visibly I see it rendered as TestCases/TestCaseTiddler/currentTiddler rather than Output.

created: 20240510013024332
description: currentTiddler should be properly set
modified: 20240510013609588
tags: $:/tags/wiki-test-spec
title: TestCases/TestCaseTiddler/currentTiddler
type: text/vnd.tiddlywiki-multiple

title: Narrative

currentTiddler variable in Output tiddler should be "Output"
+
title: Output

<$text text=<<currentTiddler>>>
+
title: ExpectedResult

<p>Output</p>

Here is a json attachement of the tiddler: TestCases_TestCaseTiddler_currentTiddler.json

Edit: I see the same issue (not surprisingly) by directly using the testcase widget

<$testcase testOutput="Output" testExpectedResult="ExpectedResult">
  <$data title="Description" text="<<currentTiddler>> should render as 'Output'"/>
  <$data title="Output" text="<<currentTiddler>>"/>
  <$data title="ExpectedResult" text="<p>Output</p>"/>
</$testcase>

@Jermolene
Copy link
Owner Author

Thanks @btheado

The test case tiddlers and test case widget seem like a really good replacement for the wikitext-example-without-html macro.

Yes, although given that these examples only have a single payload tiddler perhaps it would be nicer to use a more streamlined template.

Having the widget examples be live-editable will be a great improvement. One nice feature of the wikitext-example macro is the "copy to clipboard" button. Have any thoughts about the equivalent for the test case widget?

Being able to easily copy the text of the example is useful. In addition or instead, maybe an easy way to get the json for all the tiddlers in the test case widget?

Great idea, I agree. We should have both a "copy to clipboard" button on each source tiddler, and a way to drag and drop the tiddlers to another wiki (or the host wiki), and to save the JSON directly.

Originally I was thinking all the uses of wikitext-example-without-html would be converted to test case tiddlers. Maybe that isn't necessary. A least as a first step is much easier to change the macro to use the test case widget.

Yes, that's an excellent idea. We should still aim to convert the usages to test case tiddlers so that we can specify ExpectedResult, and hence run them as tests.

I'm seeing some strange rendering behavior regarding <<currentTiddler>> variable

Ouch, I will investigate. I'm not surprised to see this kind of wrinkle; the testcase widget mixes widgets from different wikis in a way that hasn't been tested before.

@btheado
Copy link
Contributor

btheado commented May 11, 2024

Yes, although given that these examples only have a single payload tiddler perhaps it would be nicer to use a more streamlined template.

There are still many examples for which the default template is very instructive. Whenever an example such as the RevealWidget creates a tiddler, a new tab appears. For a learner, that makes it easy to see what changes are happening.

A least as a first step is much easier to change the macro to use the test case widget.

But even this approach requires caution. There are many examples which depend on tiddlers in the main wiki. For example (just a partial list):

  • DiffTextWidget - uses SampleTiddlerFirst and SampleTiddlerSecond tiddlers
  • SetMultipleVariablesWidget - assumes presence of HelloThere tiddler
  • SetWidget - a few of these examples assume presence of tiddlers tagged HelloThere.
  • Conditional Shortcut Syntax tiddler assumes the presence of $:/info/url/protocol tiddler, but no [prefix[$:/info]] tiddlers are propagated to the subwiki by default.

@Jermolene
Copy link
Owner Author

I'm seeing some strange rendering behavior regarding <<currentTiddler>> variable

Thanks @btheado this is now fixed in eb4e9d8

There are still many examples for which the default template is very instructive

Yes, that's very true.

But even this approach requires caution

Good point. My instinct is to merge this quite soon, and then we can tackle updating the examples gradually. One advantage of the structure introduced in this PR is that the testcases are part of the tw5.com wiki, and can thus be updated directly to tiddlywiki.com because they are part of the documentation.

@btheado
Copy link
Contributor

btheado commented May 15, 2024

Thanks @btheado this is now fixed in eb4e9d8

Great, thanks.

My instinct is to merge this quite soon, and then we can tackle updating the examples gradually

For sure, I agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants