def test_on_slide_selected_index_service_item_command(self, mocked_execute): """ Test that when there is a command service item, the command is executed """ # GIVEN: A mocked service item and a slide controller with a service item mocked_item = MagicMock() mocked_item.is_command.return_value = True mocked_item.name = 'Mocked Item' mocked_update_preview = MagicMock() mocked_preview_widget = MagicMock() mocked_slide_selected = MagicMock() Registry.create() slide_controller = SlideController(None) slide_controller.service_item = mocked_item slide_controller.update_preview = mocked_update_preview slide_controller.preview_widget = mocked_preview_widget slide_controller.slide_selected = mocked_slide_selected slide_controller.is_live = True # WHEN: The method is called slide_controller.on_slide_selected_index([9]) # THEN: It should have sent a notification mocked_item.is_command.assert_called_once_with() mocked_execute.assert_called_once_with('mocked item_slide', [mocked_item, True, 9]) mocked_update_preview.assert_called_once_with() assert 0 == mocked_preview_widget.change_slide.call_count, 'Change slide should not have been called' assert 0 == mocked_slide_selected.call_count, 'slide_selected should not have been called'
def test_on_slide_selected_index_service_item_not_command(self, mocked_execute): """ Test that when there is a service item but it's not a command, the preview widget is updated """ # GIVEN: A mocked service item and a slide controller with a service item mocked_item = MagicMock() mocked_item.is_command.return_value = False mocked_item.name = 'Mocked Item' mocked_update_preview = MagicMock() mocked_preview_widget = MagicMock() mocked_slide_selected = MagicMock() Registry.create() slide_controller = SlideController(None) slide_controller.service_item = mocked_item slide_controller.update_preview = mocked_update_preview slide_controller.preview_widget = mocked_preview_widget slide_controller.slide_selected = mocked_slide_selected # WHEN: The method is called slide_controller.on_slide_selected_index([7]) # THEN: It should have sent a notification mocked_item.is_command.assert_called_once_with() assert 0 == mocked_execute.call_count, 'Execute should not have been called' assert 0 == mocked_update_preview.call_count, 'Update preview should not have been called' mocked_preview_widget.change_slide.assert_called_once_with(7) mocked_slide_selected.assert_called_once_with()
def test_on_slide_selected_index_no_service_item(self): """ Test that when there is no service item, the on_slide_selected_index() method returns immediately """ # GIVEN: A mocked service item and a slide controller without a service item mocked_item = MagicMock() slide_controller = SlideController(None) slide_controller.service_item = None # WHEN: The method is called slide_controller.on_slide_selected_index([10]) # THEN: It should have exited early assert 0 == mocked_item.is_command.call_count, 'The service item should have not been called'