Skip to content

Commit a8933db

Browse files
committed
fix(component editor): Fix saved data is used ASAP
1 parent 9330629 commit a8933db

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

ardupilot_methodic_configurator/backend_filesystem_json_with_schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,7 @@ def save_json_data(self, data: dict, data_dir: str) -> tuple[bool, str]: # noqa
159159
logging_error(msg)
160160
return True, msg
161161

162+
# Update the in-memory data after successful save
163+
self.data = data
164+
162165
return False, ""

tests/test_backend_filesystem_json_with_schema.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,12 @@ def test_user_can_save_valid_data_successfully(self, json_manager_with_schema) -
419419
420420
GIVEN: A user has valid data that conforms to the schema
421421
WHEN: They call save_json_data() with the data and directory
422-
THEN: The data should be validated and saved successfully
422+
THEN: The data should be validated, saved successfully, and cached internally
423423
"""
424424
# Arrange: Valid data and directory
425425
valid_data = {"name": "Test Output", "count": 42}
426426
data_dir = "/output/directory"
427+
json_manager_with_schema.data = None # Start with empty cache
427428

428429
with (
429430
patch.object(json_manager_with_schema, "validate_json_against_schema", return_value=(True, "")),
@@ -445,18 +446,23 @@ def test_user_can_save_valid_data_successfully(self, json_manager_with_schema) -
445446
assert error_message == ""
446447
mock_file.assert_called_once_with("/output/directory/output.json", "w", encoding="utf-8", newline="\n")
447448
mock_dumps.assert_called_once_with(valid_data, indent=4)
449+
# Assert: Internal cache updated immediately (regression test for commit ccc53bb)
450+
assert json_manager_with_schema.data == valid_data
451+
assert json_manager_with_schema.data is valid_data
448452

449453
def test_user_cannot_save_invalid_data(self, json_manager_with_schema) -> None:
450454
"""
451455
User receives error when trying to save data that fails schema validation.
452456
453457
GIVEN: A user has data that doesn't conform to the schema
454458
WHEN: They call save_json_data()
455-
THEN: The save should fail with validation error and no file operations
459+
THEN: The save should fail with validation error, no file operations, and cache unchanged
456460
"""
457-
# Arrange: Invalid data missing required field
461+
# Arrange: Invalid data missing required field and existing cache
462+
original_data = {"name": "Original Config", "count": 50}
458463
invalid_data = {"count": 42} # Missing required "name" field
459464
data_dir = "/output/directory"
465+
json_manager_with_schema.data = original_data
460466

461467
with (
462468
patch.object(
@@ -474,6 +480,8 @@ def test_user_cannot_save_invalid_data(self, json_manager_with_schema) -> None:
474480
assert "Missing required field" in error_message
475481
mock_file.assert_not_called()
476482
mock_error.assert_called_once()
483+
assert json_manager_with_schema.data == original_data
484+
assert json_manager_with_schema.data is not invalid_data
477485

478486
def test_user_handles_missing_directory_error(self, json_manager_with_schema) -> None:
479487
"""

0 commit comments

Comments
 (0)