| 1 |
from unittest.mock import Mock |
| 2 |
|
| 3 |
from fenrirscreenreader.commands.commands import export_clipboard_to_x |
| 4 |
from fenrirscreenreader.commands.commands import import_clipboard_from_x |
| 5 |
|
| 6 |
|
| 7 |
class FakeTaskManager: |
| 8 |
def __init__(self): |
| 9 |
self.callback = None |
| 10 |
self.function = None |
| 11 |
self.args = None |
| 12 |
|
| 13 |
def submit_task(self, function, callback, *args): |
| 14 |
self.function = function |
| 15 |
self.callback = callback |
| 16 |
self.args = args |
| 17 |
return 7 |
| 18 |
|
| 19 |
def cancel_task(self, _task_id): |
| 20 |
pass |
| 21 |
|
| 22 |
|
| 23 |
def test_clipboard_import_changes_history_only_after_result_event(): |
| 24 |
task_manager = FakeTaskManager() |
| 25 |
memory_manager = Mock() |
| 26 |
environment = { |
| 27 |
"runtime": { |
| 28 |
"BackgroundTaskManager": task_manager, |
| 29 |
"MemoryManager": memory_manager, |
| 30 |
"OutputManager": Mock(), |
| 31 |
} |
| 32 |
} |
| 33 |
command = import_clipboard_from_x.command() |
| 34 |
command.initialize(environment) |
| 35 |
|
| 36 |
command.run() |
| 37 |
memory_manager.add_value_to_first_index.assert_not_called() |
| 38 |
|
| 39 |
task_manager.callback( |
| 40 |
{"task_id": 7, "succeeded": True, "value": "copied text"} |
| 41 |
) |
| 42 |
memory_manager.add_value_to_first_index.assert_called_once_with( |
| 43 |
"clipboardHistory", "copied text" |
| 44 |
) |
| 45 |
|
| 46 |
|
| 47 |
def test_clipboard_export_updates_sync_state_only_after_result_event(): |
| 48 |
task_manager = FakeTaskManager() |
| 49 |
memory_manager = Mock( |
| 50 |
is_index_list_empty=Mock(return_value=False), |
| 51 |
get_index_list_element=Mock(return_value="copied text"), |
| 52 |
) |
| 53 |
sync_manager = Mock() |
| 54 |
environment = { |
| 55 |
"runtime": { |
| 56 |
"BackgroundTaskManager": task_manager, |
| 57 |
"ClipboardSyncManager": sync_manager, |
| 58 |
"DebugManager": Mock(), |
| 59 |
"MemoryManager": memory_manager, |
| 60 |
"OutputManager": Mock(), |
| 61 |
} |
| 62 |
} |
| 63 |
command = export_clipboard_to_x.command() |
| 64 |
command.initialize(environment) |
| 65 |
|
| 66 |
command.run() |
| 67 |
sync_manager.mark_written_to_x.assert_not_called() |
| 68 |
|
| 69 |
task_manager.callback( |
| 70 |
{"task_id": 7, "succeeded": True, "value": True} |
| 71 |
) |
| 72 |
sync_manager.mark_written_to_x.assert_called_once_with("copied text") |