Feature: Add a dropdown options setter (#8833)

* Feature: Add a setOptions method to field_dropdown

* add test for changing droopdown options

* split out setOptions tests into their own test suite

* Add additional tests

* auto format files
This commit is contained in:
RoboErikG
2025-04-17 12:03:35 -07:00
committed by GitHub
parent 5df6284de2
commit a2d76216b2
2 changed files with 69 additions and 16 deletions

View File

@@ -195,6 +195,52 @@ suite('Dropdown Fields', function () {
assertFieldValue(this.field, 'B', 'b');
});
});
suite('setOptions', function () {
setup(function () {
this.field = new Blockly.FieldDropdown([
['a', 'A'],
['b', 'B'],
['c', 'C'],
]);
});
test('With array updates options', function () {
this.field.setOptions([
['d', 'D'],
['e', 'E'],
['f', 'F'],
]);
assertFieldValue(this.field, 'D', 'd');
});
test('With generator updates options', function () {
this.field.setOptions(function () {
return [
['d', 'D'],
['e', 'E'],
['f', 'F'],
];
});
assertFieldValue(this.field, 'D', 'd');
});
test('With trimmable options gets trimmed', function () {
this.field.setOptions([
['a d b', 'D'],
['a e b', 'E'],
['a f b', 'F'],
]);
assert.deepEqual(this.field.prefixField, 'a');
assert.deepEqual(this.field.suffixField, 'b');
assert.deepEqual(this.field.getOptions(), [
['d', 'D'],
['e', 'E'],
['f', 'F'],
]);
});
test('With an empty array of options throws', function () {
assert.throws(function () {
this.field.setOptions([]);
});
});
});
suite('Validators', function () {
setup(function () {