mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-09 11:29:58 +00:00
ece8b0ee01
* Initial Commit
* Add note to preview build
* Fix whitespace and indenting
Thanks @pmario
* Fix crash with unset $tiddler attribute on <$data> widget
Thanks @CodaCodr
* Don't duplicate "description" field in test cases
* Use different background colours for nested testcase widgets
* Extend the testcase widget to run tests
* Add testcases to control panel
* Add a view template body template to render testcase tiddlers
* Test edition should display testcases
* Whitespace fixes
* Make testcase tiddler tempalte link to itself
* Styling tweaks
* Docs improvements
* Styling tweaks
* Run the new tw5.com testcases in the test edition
* Update data widget to display its content in JSON
* Add testcase convenience procedure
* Clearer testcases for data widget, and docs tweaks
* Don't expect our intentionally failing test to pass
* Extend testcase default template so that the display format can be chosen
It is selected by setting the variable "displayFormat"
* DataWidget docs typo
* Fix data widget not refreshing
* Links in testcase output switch to the tab containing that tiddler
Thanks to @btheado for the suggestion
* Docs update for 648855e8a5
* Wording tweak
* Add support for narrative tiddlers in test cases
* Documentation improvements
* Cleanup comments
* Remove obsolete code comments
* Simplify template
* Docs update
* Rename $:/core/ui/testcases/DefaultTemplate/SourceTabs from $:/core/ui/testcases/DefaultTemplate/Source
* Use the view template body for failing tests
* Don't reference the geospatial plugin
* "Test case" should be two words
* Fix handling of currentTiddler variable
Fixes problem reported by @btheado in https://github.com/Jermolene/TiddlyWiki5/pull/7817#issuecomment-2103704468
* Prepare for merging
98 lines
2.8 KiB
JavaScript
98 lines
2.8 KiB
JavaScript
/*\
|
|
title: $:/plugins/tiddlywiki/jasmine/run-wiki-based-tests.js
|
|
type: application/javascript
|
|
tags: [[$:/tags/test-spec]]
|
|
|
|
Tests the wiki based tests
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
var TEST_WIKI_TIDDLER_FILTER = "[all[tiddlers+shadows]type[text/vnd.tiddlywiki-multiple]tag[$:/tags/wiki-test-spec]]";
|
|
|
|
var widget = require("$:/core/modules/widgets/widget.js");
|
|
|
|
describe("Wiki-based tests", function() {
|
|
|
|
// Step through the test tiddlers
|
|
var tests = $tw.wiki.filterTiddlers(TEST_WIKI_TIDDLER_FILTER);
|
|
$tw.utils.each(tests,function(title) {
|
|
var tiddler = $tw.wiki.getTiddler(title);
|
|
it(tiddler.fields.title + ": " + tiddler.fields.description, function() {
|
|
// Add our tiddlers
|
|
var wiki = new $tw.Wiki(),
|
|
coreTiddler = $tw.wiki.getTiddler("$:/core");
|
|
if(coreTiddler) {
|
|
wiki.addTiddler(coreTiddler);
|
|
}
|
|
wiki.addTiddlers(readMultipleTiddlersTiddler(title));
|
|
// Complain if we don't have the ouput and expected results
|
|
if(!wiki.tiddlerExists("Output")) {
|
|
throw "Missing 'Output' tiddler";
|
|
}
|
|
if(!wiki.tiddlerExists("ExpectedResult")) {
|
|
throw "Missing 'ExpectedResult' tiddler";
|
|
}
|
|
// Construct the widget node
|
|
var text = "{{Output}}\n\n";
|
|
var widgetNode = createWidgetNode(parseText(text,wiki),wiki);
|
|
// Render the widget node to the DOM
|
|
var wrapper = renderWidgetNode(widgetNode);
|
|
// Clear changes queue
|
|
wiki.clearTiddlerEventQueue();
|
|
// 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"));
|
|
});
|
|
});
|
|
|
|
function readMultipleTiddlersTiddler(title) {
|
|
var rawTiddlers = $tw.wiki.getTiddlerText(title).split(/\r?\n\+\r?\n/mg);
|
|
var tiddlers = [];
|
|
$tw.utils.each(rawTiddlers,function(rawTiddler) {
|
|
var fields = Object.create(null),
|
|
split = rawTiddler.split(/\r?\n\r?\n/mg);
|
|
if(split.length >= 1) {
|
|
fields = $tw.utils.parseFields(split[0],fields);
|
|
}
|
|
if(split.length >= 2) {
|
|
fields.text = split.slice(1).join("\n\n");
|
|
}
|
|
tiddlers.push(fields);
|
|
});
|
|
return tiddlers;
|
|
}
|
|
|
|
function createWidgetNode(parser,wiki) {
|
|
return wiki.makeWidget(parser);
|
|
}
|
|
|
|
function parseText(text,wiki,options) {
|
|
return wiki.parseText("text/vnd.tiddlywiki",text,options);
|
|
}
|
|
|
|
function renderWidgetNode(widgetNode) {
|
|
$tw.fakeDocument.setSequenceNumber(0);
|
|
var wrapper = $tw.fakeDocument.createElement("div");
|
|
widgetNode.render(wrapper,null);
|
|
// console.log(require("util").inspect(wrapper,{depth: 8}));
|
|
return wrapper;
|
|
}
|
|
|
|
function refreshWidgetNode(widgetNode,wrapper) {
|
|
widgetNode.refresh(widgetNode.wiki.changedTiddlers,wrapper);
|
|
// console.log(require("util").inspect(wrapper,{depth: 8}));
|
|
}
|
|
|
|
});
|
|
|
|
})();
|