1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-03-10 13:38:10 +00:00

Merge branch 'master' into feat-ai-tools

This commit is contained in:
Jeremy Ruston 2025-03-06 17:42:02 +00:00
commit ce9209f00e
3 changed files with 25 additions and 7 deletions

View File

@ -128,7 +128,7 @@ exports.minall = makeNumericReducingOperator(
exports.median = makeNumericArrayOperator(
function(values) {
var len = values.length, median;
values.sort();
values.sort(function(a,b) {return a-b});
if(len % 2) {
// Odd, return the middle number
median = values[(len - 1) / 2];

View File

@ -157,7 +157,7 @@ CheckboxWidget.prototype.getValue = function() {
if(this.checkboxTag) {
return false;
}
if(this.checkboxField) {
if(this.checkboxField || this.checkboxIndex) {
if(this.checkboxDefault === this.checkboxChecked) {
return true;
}

View File

@ -78,6 +78,13 @@ Tests the checkbox widget thoroughly.
startsOutChecked: false,
expectedChange: { "TiddlerOne": { expand: "yes" } }
},
{
testName: "field mode default when missing -> true",
tiddlers: [],
widgetText: "<$checkbox tiddler='TiddlerOne' field='expand' default='yes' checked='yes' unchecked='no' />",
startsOutChecked: true,
expectedChange: { "TiddlerOne": { expand: "no" } }
},
{
testName: "field mode indeterminate -> true",
tiddlers: [{title: "TiddlerOne", text: "Jolly Old World", expand: "some other value"}],
@ -98,19 +105,28 @@ Tests the checkbox widget thoroughly.
var indexModeTests = fieldModeTests.map(data => {
var newData = {...data};
var newName = data.testName.replace('field mode', 'index mode');
var tiddlerOneAlreadyExists = false;
var newTiddlers = data.tiddlers.map(tiddler => {
if(tiddler.title === "TiddlerOne") {
tiddlerOneAlreadyExists = true;
}
return {title: tiddler.title, type: "application/x-tiddler-dictionary", text: `one: a\nexpand: ${tiddler.expand}\ntwo: b`}
});
var newWidgetText = data.widgetText.replace("field='expand'", "index='expand'");
var newChange = {};
for (var key of Object.keys(data.expectedChange)) {
var oldChange = data.expectedChange[key];
if (oldChange.expand) {
newChange[key] = { text: `one: a\nexpand: ${oldChange.expand}\ntwo: b` }
var text;
if (!tiddlerOneAlreadyExists) {
// If it wasn't there, the created one will be JSON
text = `{\n "expand": "${oldChange.expand}"\n}`;
} else if (oldChange.expand) {
text = `one: a\nexpand: ${oldChange.expand}\ntwo: b`;
} else {
// In index tiddlers, the "expand" field gets completely removed, not turned into "expand: (undefined)"
newChange[key] = { text: `one: a\ntwo: b` }
text = `one: a\ntwo: b`;
}
newChange[key] = { text: text };
}
newData.testName = newName;
newData.tiddlers = newTiddlers;
@ -514,7 +530,9 @@ Tests the checkbox widget thoroughly.
/*
* Checkbox widget tests using the test data above
*/
for (var data of checkboxTestData) {
// MAKE SURE TO USE $tw.utils.each HERE!!!
// If you use a forloop, the closure of the tests will all use the last value "data" was assigned to, and thus all run the same test.
$tw.utils.each(checkboxTestData, function(data) {
it('checkbox widget test: ' + data.testName, function() {
// Setup
@ -553,7 +571,7 @@ Tests the checkbox widget thoroughly.
}
}
})
}
});
});