mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-03-03 18:25:15 +00:00
parent
0f79f88f58
commit
0dda07e3f1
@ -157,7 +157,7 @@ CheckboxWidget.prototype.getValue = function() {
|
|||||||
if(this.checkboxTag) {
|
if(this.checkboxTag) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(this.checkboxField) {
|
if(this.checkboxField || this.checkboxIndex) {
|
||||||
if(this.checkboxDefault === this.checkboxChecked) {
|
if(this.checkboxDefault === this.checkboxChecked) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,13 @@ Tests the checkbox widget thoroughly.
|
|||||||
startsOutChecked: false,
|
startsOutChecked: false,
|
||||||
expectedChange: { "TiddlerOne": { expand: "yes" } }
|
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",
|
testName: "field mode indeterminate -> true",
|
||||||
tiddlers: [{title: "TiddlerOne", text: "Jolly Old World", expand: "some other value"}],
|
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 indexModeTests = fieldModeTests.map(data => {
|
||||||
var newData = {...data};
|
var newData = {...data};
|
||||||
var newName = data.testName.replace('field mode', 'index mode');
|
var newName = data.testName.replace('field mode', 'index mode');
|
||||||
|
var tiddlerOneAlreadyExists = false;
|
||||||
var newTiddlers = data.tiddlers.map(tiddler => {
|
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`}
|
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 newWidgetText = data.widgetText.replace("field='expand'", "index='expand'");
|
||||||
var newChange = {};
|
var newChange = {};
|
||||||
for (var key of Object.keys(data.expectedChange)) {
|
for (var key of Object.keys(data.expectedChange)) {
|
||||||
var oldChange = data.expectedChange[key];
|
var oldChange = data.expectedChange[key];
|
||||||
if (oldChange.expand) {
|
var text;
|
||||||
newChange[key] = { text: `one: a\nexpand: ${oldChange.expand}\ntwo: b` }
|
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 {
|
} else {
|
||||||
// In index tiddlers, the "expand" field gets completely removed, not turned into "expand: (undefined)"
|
// 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.testName = newName;
|
||||||
newData.tiddlers = newTiddlers;
|
newData.tiddlers = newTiddlers;
|
||||||
@ -514,7 +530,9 @@ Tests the checkbox widget thoroughly.
|
|||||||
/*
|
/*
|
||||||
* Checkbox widget tests using the test data above
|
* 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() {
|
it('checkbox widget test: ' + data.testName, function() {
|
||||||
// Setup
|
// Setup
|
||||||
|
|
||||||
@ -553,7 +571,7 @@ Tests the checkbox widget thoroughly.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user