Add test for dynamically loading a language plugin

This commit is contained in:
Jeremy Ruston
2025-02-26 17:20:03 +00:00
parent 26b2768294
commit 41cd335cf4
5 changed files with 107 additions and 16 deletions
+28 -3
View File
@@ -38,6 +38,7 @@ function PluginSwitcher(options) {
}
PluginSwitcher.prototype.switchPlugins = function() {
var self = this;
// Get the name of the current theme
var selectedPluginTitle = this.wiki.getTiddlerText(this.controllerTitle);
// If it doesn't exist, then fallback to one of the default themes
@@ -61,13 +62,37 @@ PluginSwitcher.prototype.switchPlugins = function() {
};
accumulatePlugin(selectedPluginTitle);
// Read the plugin info for the incoming plugins
var changes = this.wiki.readPluginInfo(plugins);
var changedPluginInfo = this.wiki.readPluginInfo(plugins);
// Collect the shadow tiddlers of any deleted plugins
var changedShadowTiddlers = {};
$tw.utils.each(changedPluginInfo.deletedPlugins,function(pluginTitle) {
var contents = changedPluginInfo.deletedPluginContents[pluginTitle];
if(contents && contents.tiddlers) {
$tw.utils.each(Object.keys(contents.tiddlers),function(title) {
changedShadowTiddlers[title] = true;
});
}
});
// Collect the shadow tiddlers of any modified plugins
$tw.utils.each(changedPluginInfo.modifiedPlugins,function(pluginTitle) {
var pluginInfo = self.wiki.getPluginInfo(pluginTitle);
if(pluginInfo && pluginInfo.tiddlers) {
$tw.utils.each(Object.keys(pluginInfo.tiddlers),function(title) {
changedShadowTiddlers[title] = false;
});
}
});
// Unregister any existing theme tiddlers
var unregisteredTiddlers = this.wiki.unregisterPluginTiddlers(this.pluginType);
// Register any new theme tiddlers
var registeredTiddlers = this.wiki.registerPluginTiddlers(this.pluginType,plugins,plugins[0] === "$:/languages/fr-FR");
var registeredTiddlers = this.wiki.registerPluginTiddlers(this.pluginType,plugins);
// Unpack the current theme tiddlers
this.wiki.unpackPluginTiddlers();
this.wiki.unpackPluginTiddlers(this.doDebug);
// Queue change events for the changed shadow tiddlers
$tw.utils.each(changedShadowTiddlers,function(status,title) {
self.wiki.enqueueTiddlerEvent(title,changedShadowTiddlers[title], true);
});
// Call the switch handler
if(this.onSwitch) {
this.onSwitch(plugins);
+23 -1
View File
@@ -69,11 +69,24 @@ TestCaseWidget.prototype.render = function(parent,nextSibling) {
});
var jsonPayload = JSON.stringify(tiddlers);
this.testcaseWiki.addTiddlers(tiddlers);
// Suppress next tick dispatch for wiki change events
this.testcaseWiki.setDispatchMode(true);
// Unpack plugin tiddlers
this.testcaseWiki.readPluginInfo();
this.testcaseWiki.registerPluginTiddlers("plugin");
this.testcaseWiki.unpackPluginTiddlers();
this.testcaseWiki.addIndexersToWiki();
// Install the plugin change event handler
$tw.utils.installPluginChangeHandler(this.testcaseWiki);
// Install the language switcher
var languageSwitcher = new $tw.PluginSwitcher({
wiki: this.testcaseWiki,
pluginType: "language",
controllerTitle: "$:/language",
defaultPlugins: [
"$:/languages/en-GB"
]
});
// Generate a `transclusion` variable that depends on the values of the payload tiddlers so that the template can easily make unique state tiddlers
this.setVariable("transclusion",$tw.utils.hashString(jsonPayload));
// Generate a `payloadTiddlers` variable that contains the payload in JSON format
@@ -95,13 +108,20 @@ TestCaseWidget.prototype.render = function(parent,nextSibling) {
}
});
testcaseOutputWidget.render(testcaseOutputContainer);
// Install the wiki change event handler
this.testcaseWiki.addEventListener("change",function(changes) {
testcaseOutputWidget.refresh(changes,testcaseOutputContainer);
});
}
// Clear changes queue
this.testcaseWiki.clearTiddlerEventQueue();
// Run the actions if provided
if(this.testcaseWiki.tiddlerExists(this.testcaseTestActions)) {
testcaseOutputWidget.invokeActionString(this.testcaseWiki.getTiddlerText(this.testcaseTestActions));
testcaseOutputWidget.refresh(this.testcaseWiki.changedTiddlers,testcaseOutputContainer);
// Make sure all wiki events have been cleared
while(this.testcaseWiki.eventsTriggered) {
this.testcaseWiki.processOutstandingTiddlerEvents();
}
}
// Set up the test result variables
var testResult = "",
@@ -131,6 +151,8 @@ TestCaseWidget.prototype.render = function(parent,nextSibling) {
parentWidget: this
});
rootWidget.render(domNode);
// Re-enable next tick dispatch for wiki change events
this.testcaseWiki.setDispatchMode(false);
// Trap changes in the wiki and refresh the rendering
this.testcaseWiki.addEventListener("change",function(changes) {
rootWidget.refresh(changes,domNode);
+2 -1
View File
@@ -103,7 +103,8 @@ code-body: yes
-Description
-Narrative
-[[$:/temp/testcase/draft-title]]
-[has[plugin-type]]
-[[$:/status/RequireReloadDueToPluginChange]]
-[[$:/core]]
-[prefix<tf.state>]
-[prefix[$:/state/popup/export]]
-[prefix[$:/HistoryList]]