- Added two new tests for lock button toggle.

This commit is contained in:
Olli Suutari 2016-09-18 01:53:47 +03:00
parent 09da152372
commit 190baf19d5
1 changed files with 32 additions and 6 deletions

View File

@ -169,17 +169,43 @@ class TestMediaItem(TestCase, TestMixin):
self.media_item.quick_search_edit.clear.assert_called_once_with(),
self.media_item.quick_search_edit.setFocus.assert_called_once_with()
def test_on_lock_button_toggled_search_tab(self):
def test_on_lock_button_toggled_search_tab_lock_icon(self):
"""
Test that "on_lock_button_toggled" gives focus to the right field.
Test that "on_lock_button_toggled" gives focus to the right field and toggles the lock properly.
"""
# GIVEN: Mocked functions
# GIVEN: Mocked sender & Search edit, quickTab returning value = True on isVisible.
self.media_item.sender = MagicMock()
self.media_item.quickTab = MagicMock()
self.media_item.quick_search_edit = MagicMock()
self.media_item.quickTab = MagicMock(**{'isVisible.return_value': True})
# WHEN: on_lock_button_toggled is called and quickTab.isVisible() returns = True.
self.media_item.lock_icon = 'lock icon'
sender_instance_mock = MagicMock()
self.media_item.sender = MagicMock(return_value=sender_instance_mock)
# WHEN: on_lock_button_toggled is called and checked returns = True.
self.media_item.on_lock_button_toggled(True)
# THEN: on_quick_search_edit should receive focus.
# THEN: on_quick_search_edit should receive focus and Lock icon should be set.
self.media_item.quick_search_edit.setFocus.assert_called_once_with()
sender_instance_mock.setIcon.assert_called_once_with('lock icon')
def test_on_lock_button_toggled_select_tab_unlock_icon(self):
"""
Test that "on_lock_button_toggled" does not give focus to Search field in Select
and lock toggles properly.
"""
# GIVEN: Mocked sender & Search edit, quickTab returning value = False on isVisible.
self.media_item.sender = MagicMock()
self.media_item.quick_search_edit = MagicMock()
self.media_item.quickTab = MagicMock(**{'isVisible.return_value': False})
self.media_item.unlock_icon = 'unlock icon'
sender_instance_mock = MagicMock()
self.media_item.sender = MagicMock(return_value=sender_instance_mock)
# WHEN: on_lock_button_toggled is called and checked returns = False.
self.media_item.on_lock_button_toggled(False)
# THEN: on_quick_search_edit should not receive focus and Unlock icon should be set.
self.media_item.quick_search_edit.setFocus.assert_not_called_once_with()
sender_instance_mock.setIcon.assert_called_once_with('unlock icon')