mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-05-01 00:06:44 +00:00
Fix bug when using built-in list field as listField parameter to checkbox widget (#6897)
* Fix bug with checkbox widget and `list` field The `list` field is stored as a list and frozen against modifications, and getFieldList() returns it directly without creating a copy. So before we modify it, we need to make a copy so we're not modifying a frozen list. This bug doesn't manifest with custom fields, which are stored as strings, only with the built-in `list` field. * Fix checkboxes referencing non-existent tiddlers This fixes the "tiddler is undefined" error when a checkbox's listField property references a tiddler that doesn't (yet) exist. * Better logic for checkbox listField handling If the field contains an array, then it's almost certainly referenced elsewhere and needs a defensive copy made. If it contained a string, then it's safe to modify without making a defensive copy.
This commit is contained in:
@@ -234,6 +234,38 @@ Tests the checkbox widget thoroughly.
|
||||
},
|
||||
];
|
||||
|
||||
// https://github.com/Jermolene/TiddlyWiki5/issues/6871
|
||||
const listModeTestsWithListField = (
|
||||
listModeTests
|
||||
.filter(data => data.widgetText.includes("listField='colors'"))
|
||||
.map(data => {
|
||||
const newData = {
|
||||
...data,
|
||||
tiddlers: data.tiddlers.map(tiddler => ({...tiddler, list: tiddler.colors, colors: undefined})),
|
||||
widgetText: data.widgetText.replace("listField='colors'", "listField='list'"),
|
||||
expectedChange: {
|
||||
"Colors": { list: data.expectedChange.Colors.colors.split(' ') }
|
||||
},
|
||||
}
|
||||
return newData;
|
||||
})
|
||||
);
|
||||
const listModeTestsWithTagsField = (
|
||||
listModeTests
|
||||
.filter(data => data.widgetText.includes("listField='colors'"))
|
||||
.map(data => {
|
||||
const newData = {
|
||||
...data,
|
||||
tiddlers: data.tiddlers.map(tiddler => ({...tiddler, tags: tiddler.colors, colors: undefined})),
|
||||
widgetText: data.widgetText.replace("listField='colors'", "listField='tags'"),
|
||||
expectedChange: {
|
||||
"Colors": { tags: data.expectedChange.Colors.colors.split(' ') }
|
||||
},
|
||||
}
|
||||
return newData;
|
||||
})
|
||||
);
|
||||
|
||||
const indexListModeTests = listModeTests.map(data => {
|
||||
const newData = {...data};
|
||||
const newName = data.testName.replace('list mode', 'index list mode');
|
||||
@@ -453,6 +485,8 @@ Tests the checkbox widget thoroughly.
|
||||
const checkboxTestData = fieldModeTests.concat(
|
||||
indexModeTests,
|
||||
listModeTests,
|
||||
listModeTestsWithListField,
|
||||
listModeTestsWithTagsField,
|
||||
indexListModeTests,
|
||||
filterModeTests,
|
||||
);
|
||||
@@ -495,7 +529,7 @@ Tests the checkbox widget thoroughly.
|
||||
for (const fieldName of Object.keys(change)) {
|
||||
const expectedValue = change[fieldName];
|
||||
const fieldValue = tiddler.fields[fieldName];
|
||||
expect(fieldValue).toBe(expectedValue);
|
||||
expect(fieldValue).toEqual(expectedValue);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user