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

Fix for #5930: missing tiddlers with checkbox indexes (#8964)

This commit is contained in:
Cameron Fischer 2025-02-27 13:02:43 -05:00 committed by GitHub
parent 0f79f88f58
commit 0dda07e3f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 6 deletions

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.
}
}
})
}
});
});