Fix bug #1098 by checking that the selectedItem is not None

This commit is contained in:
Raoul Snyman 2022-07-21 16:12:31 -07:00
parent 229d40f638
commit 2f9a16260f
2 changed files with 14 additions and 1 deletions

View File

@ -1181,7 +1181,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
"""
item = self.service_manager_list.currentItem()
# Since we only have 2 levels we find them by checking for children
if item.childCount():
if item and item.childCount():
if not self.service_manager_list.isExpanded(self.service_manager_list.currentIndex()):
self.service_manager_list.expandItem(item)
self.service_manager.expanded(item)

View File

@ -1854,6 +1854,19 @@ class TestServiceManager(TestCase, TestMixin):
# THEN the on_expand_selection function should have been called.
self.service_manager.on_expand_selection.assert_called_once_with()
def test_on_expand_selection_item_none(self):
"""
Test that on_expand_selection exits early when there is no item selected.
"""
# GIVEN a mocked expand function
self.service_manager.service_manager_list = MagicMock(**{'currentItem.return_value': None})
# WHEN on_expand_selection is called
self.service_manager.on_expand_selection()
# THEN on_expand_selection should have exited early
self.service_manager.service_manager_list.isExpanded.assert_not_called()
def test_collapse_selection_on_left_arrow(self):
"""
Test that a left arrow key press event calls the on_collapse_selection function