1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-02-23 14:30:02 +00:00

Test for loading language plugins at startup

This commit is contained in:
Jeremy Ruston 2025-02-21 16:47:00 +00:00
parent 0c80e1b35c
commit 01beac1d7c
3 changed files with 61 additions and 9 deletions

View File

@ -61,13 +61,13 @@ PluginSwitcher.prototype.switchPlugins = function() {
};
accumulatePlugin(selectedPluginTitle);
// Read the plugin info for the incoming plugins
var changes = $tw.wiki.readPluginInfo(plugins);
var changes = this.wiki.readPluginInfo(plugins);
// Unregister any existing theme tiddlers
var unregisteredTiddlers = $tw.wiki.unregisterPluginTiddlers(this.pluginType);
var unregisteredTiddlers = this.wiki.unregisterPluginTiddlers(this.pluginType);
// Register any new theme tiddlers
var registeredTiddlers = $tw.wiki.registerPluginTiddlers(this.pluginType,plugins);
var registeredTiddlers = this.wiki.registerPluginTiddlers(this.pluginType,plugins,plugins[0] === "$:/languages/fr-FR");
// Unpack the current theme tiddlers
$tw.wiki.unpackPluginTiddlers();
this.wiki.unpackPluginTiddlers();
// Call the switch handler
if(this.onSwitch) {
this.onSwitch(plugins);

View File

@ -0,0 +1,46 @@
title: Plugins/Language
description: Loading of correct language plugin at startup
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
{{First}}
+
title: $:/language
$:/languages/fr-FR
+
title: $:/languages/en-GB
list: readme
name: en-GB
plugin-type: language
type: application/json
{
"tiddlers": {
"First": {
"title": "First",
"text": "This is English"
}
}
}
+
title: $:/languages/fr-FR
list: readme
name: fr-FR
plugin-type: language
type: application/json
{
"tiddlers": {
"First": {
"title": "First",
"text": "This is French"
}
}
}
+
title: ExpectedResult
<p>This is French</p>

View File

@ -39,10 +39,19 @@ describe("Wiki-based tests", function() {
wiki.registerPluginTiddlers("plugin");
wiki.unpackPluginTiddlers();
wiki.addIndexersToWiki();
// Clear changes queue
wiki.clearTiddlerEventQueue();
// Install the plugin change event handler
$tw.utils.installPluginChangeHandler(wiki);
// Install the language switcher
$tw.languageSwitcher = new $tw.PluginSwitcher({
wiki: wiki,
pluginType: "language",
controllerTitle: "$:/language",
defaultPlugins: [
"$:/languages/en-GB"
]
});
// Clear changes queue
wiki.clearTiddlerEventQueue();
// Complain if we don't have the ouput and expected results
if(!wiki.tiddlerExists("Output")) {
throw "Missing 'Output' tiddler";
@ -53,8 +62,6 @@ describe("Wiki-based tests", function() {
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"));
@ -65,7 +72,6 @@ describe("Wiki-based tests", function() {
wiki.processOutstandingTiddlerEvents();
refreshWidgetNode(widgetNode,wrapper);
}
wiki.processOutstandingTiddlerEvents();
// Test the rendering
refreshWidgetNode(widgetNode,wrapper);
expect(wrapper.innerHTML).toBe(wiki.getTiddlerText("ExpectedResult"));