diff --git a/tests/functional/openlp_core/api/endpoint/test_controller.py b/tests/functional/openlp_core/api/endpoint/test_controller.py index 90aba6e03..c8fc70057 100644 --- a/tests/functional/openlp_core/api/endpoint/test_controller.py +++ b/tests/functional/openlp_core/api/endpoint/test_controller.py @@ -22,8 +22,24 @@ from unittest import TestCase from unittest.mock import MagicMock +from PyQt5 import QtCore + from openlp.core.common.registry import Registry from openlp.core.api.endpoint.controller import controller_text, controller_direction +from openlp.core.display.renderer import Renderer +from openlp.core.display.screens import ScreenList +from openlp.core.lib import ServiceItem + +from tests.utils import convert_file_service_item +from tests.utils.constants import RESOURCE_PATH + +TEST_PATH = str(RESOURCE_PATH / 'service') + +SCREEN = { + 'primary': False, + 'number': 1, + 'size': QtCore.QRect(0, 0, 1024, 768) +} class TestController(TestCase): @@ -38,11 +54,18 @@ class TestController(TestCase): Registry.create() self.registry = Registry() self.mocked_live_controller = MagicMock() + self.desktop = MagicMock() + self.desktop.primaryScreen.return_value = SCREEN['primary'] + self.desktop.screenCount.return_value = SCREEN['number'] + self.desktop.screenGeometry.return_value = SCREEN['size'] + self.screens = ScreenList.create(self.desktop) + renderer = Renderer() + renderer.empty_height = 1000 Registry().register('live_controller', self.mocked_live_controller) - def test_controller_text(self): + def test_controller_text_empty(self): """ - Remote API Tests : test the controller text method can be called + Remote API Tests : test the controller text method can be called with empty service item """ # GIVEN: A mocked service with a dummy service item self.mocked_live_controller.service_item = MagicMock() @@ -53,6 +76,22 @@ class TestController(TestCase): assert isinstance(results['item'], MagicMock) assert len(results['slides']) == 0 + def test_controller_text(self): + """ + Remote API Tests : test the controller text method can be called with a real service item + """ + # GIVEN: A mocked service with a dummy service item + line = convert_file_service_item(TEST_PATH, 'serviceitem_custom_1.osj') + self.mocked_live_controller.service_item = ServiceItem(None) + self.mocked_live_controller.service_item.set_from_service(line) + self.mocked_live_controller.service_item.render(True) + # WHEN: I trigger the method + ret = controller_text("SomeText") + # THEN: I get a basic set of results + results = ret['results'] + assert isinstance(ret, dict) + assert len(results['slides']) == 2 + def test_controller_direction_next(self): """ Text the live next method is triggered