1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-24 10:37:20 +00:00

Add a test for custom action widgets

This commit is contained in:
jeremy@jermolene.com 2022-04-26 13:05:44 +01:00
parent 0e4e037bb7
commit 66d4b07f7e
2 changed files with 35 additions and 8 deletions

View File

@ -0,0 +1,28 @@
title: Ubertransclude/CustomWidget/ActionWidget
description: Custom widget definition
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
<$ubertransclude $tiddler='Result'>
</$ubertransclude>
_
title: Actions
\whitespace trim
<!-- Define the <$action-mywidget> widget by defining a transcludable variable with that name -->
<$set name="<$action-mywidget>" value="""\whitespace trim
<$parameters one='Jaguar'>
<$action-setfield $tiddler="Result" $field="text" $value=<<one>>/>
</$parameters>"""
>
<$action-mywidget one="Dingo">
Crocodile
</$action-mywidget>
</$set>
_
title: ExpectedResult
<p>Dingo</p>

View File

@ -38,6 +38,11 @@ describe("Wiki-based tests", function() {
var widgetNode = createWidgetNode(parseText(text,wiki),wiki);
// Render the widget node to the DOM
var wrapper = renderWidgetNode(widgetNode);
// Run the actions if provided
if(wiki.tiddlerExists("Actions")) {
widgetNode.invokeActionString(wiki.getTiddlerText("Actions"));
refreshWidgetNode(widgetNode,wrapper);
}
// Test the rendering
expect(wrapper.innerHTML).toBe(wiki.getTiddlerText("ExpectedResult"));
});
@ -80,14 +85,8 @@ describe("Wiki-based tests", function() {
return wrapper;
}
function refreshWidgetNode(widgetNode,wrapper,changes) {
var changedTiddlers = {};
if(changes) {
$tw.utils.each(changes,function(title) {
changedTiddlers[title] = true;
});
}
widgetNode.refresh(changedTiddlers,wrapper,null);
function refreshWidgetNode(widgetNode,wrapper) {
widgetNode.refresh(widgetNode.wiki.changedTiddlers,wrapper);
// console.log(require("util").inspect(wrapper,{depth: 8}));
}