|
24 | 24 | from qubesadmin.tests.mock_app import MockDispatcher
|
25 | 25 | from ..search_page import SearchPage
|
26 | 26 |
|
27 |
| - |
28 | 27 | def test_search(test_desktop_file_path, test_qapp, test_builder):
|
29 | 28 | dispatcher = MockDispatcher(test_qapp)
|
30 | 29 | vm_manager = VMManager(test_qapp, dispatcher)
|
@@ -90,3 +89,71 @@ def test_search(test_desktop_file_path, test_qapp, test_builder):
|
90 | 89 | if search_page._is_app_fitting(row)]
|
91 | 90 | assert len(found_entries) == 1
|
92 | 91 | assert found_entries[0].app_info.app_name == 'Xfce Appearance Settings'
|
| 92 | + |
| 93 | +@mock.patch('gi.repository.Gtk.Application') |
| 94 | +def test_recent_searches(mock_application, test_desktop_file_path, test_qapp, |
| 95 | + test_builder): |
| 96 | + dispatcher = MockDispatcher(test_qapp) |
| 97 | + vm_manager = VMManager(test_qapp, dispatcher) |
| 98 | + |
| 99 | + with mock.patch.object(DesktopFileManager, 'desktop_dirs', |
| 100 | + [test_desktop_file_path]): |
| 101 | + desktop_file_manager = DesktopFileManager(test_qapp) |
| 102 | + |
| 103 | + search_page = SearchPage(vm_manager, test_builder, desktop_file_manager) |
| 104 | + |
| 105 | + assert search_page.search_entry.get_sensitive() |
| 106 | + |
| 107 | + search_page.search_entry.set_text('dragons') |
| 108 | + |
| 109 | + # find a dom0 app |
| 110 | + search_page.search_entry.set_text('dom0') |
| 111 | + |
| 112 | + for row in search_page.app_list.get_children(): |
| 113 | + if search_page._is_app_fitting(row): |
| 114 | + with mock.patch('subprocess.Popen') as mock_run, mock.patch.object( |
| 115 | + row.get_toplevel(), 'get_application', side_effect=mock_application): |
| 116 | + row.activate() |
| 117 | + assert mock_run.call_count == 1 |
| 118 | + assert mock.call().emit('app-started', 'test3.desktop') in mock_application.mock_calls |
| 119 | + |
| 120 | + # we are faking signals here |
| 121 | + search_page.recent_apps_manager.add_new_recent_app(None, 'test3.desktop') |
| 122 | + |
| 123 | + texts = [row.search_text for row in search_page.recent_list.get_children()] |
| 124 | + assert texts == ['dom0'] |
| 125 | + apps = [row.app_info.entry_name for row in |
| 126 | + search_page.recent_app_list.get_children()] |
| 127 | + assert apps == ['test3.desktop'] |
| 128 | + |
| 129 | + # do two more searches, but one should be the same as an existing search |
| 130 | + search_page.search_entry.set_text('') |
| 131 | + search_page.search_entry.set_text('xTeRm') |
| 132 | + |
| 133 | + for row in search_page.app_list.get_children(): |
| 134 | + if search_page._is_app_fitting(row): |
| 135 | + with mock.patch('subprocess.Popen') as mock_run, mock.patch.object( |
| 136 | + row.get_toplevel(), 'get_application', side_effect=mock_application): |
| 137 | + row.activate() |
| 138 | + assert mock_run.call_count == 1 |
| 139 | + assert mock.call().emit('app-started', 'test1.desktop') in mock_application.mock_calls |
| 140 | + |
| 141 | + search_page.recent_apps_manager.add_new_recent_app(None, 'test1.desktop') |
| 142 | + search_page.search_entry.set_text('') |
| 143 | + search_page.search_entry.set_text('dom0') |
| 144 | + |
| 145 | + for row in search_page.app_list.get_children(): |
| 146 | + if search_page._is_app_fitting(row): |
| 147 | + with mock.patch('subprocess.Popen') as mock_run, mock.patch.object( |
| 148 | + row.get_toplevel(), 'get_application', side_effect=mock_application): |
| 149 | + row.activate() |
| 150 | + assert mock_run.call_count == 1 |
| 151 | + assert mock.call().emit('app-started', 'test3.desktop') in mock_application.mock_calls |
| 152 | + |
| 153 | + search_page.recent_apps_manager.add_new_recent_app(None, 'test3.desktop') |
| 154 | + |
| 155 | + texts = [row.search_text for row in search_page.recent_list.get_children()] |
| 156 | + assert texts == ['dom0', 'xTeRm'] |
| 157 | + apps = [row.app_info.entry_name for row in |
| 158 | + search_page.recent_app_list.get_children()] |
| 159 | + assert apps == ['test3.desktop', 'test1.desktop'] |
0 commit comments