openlp/tests/openlp_core/ui/test_starttimedialog.py

99 lines
4.6 KiB
Python
Raw Permalink Normal View History

2014-03-14 22:08:44 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2022-02-06 09:10:17 +00:00
# Copyright (c) 2008-2022 OpenLP Developers #
2019-04-13 13:00:22 +00:00
# ---------------------------------------------------------------------- #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
2013-01-02 21:50:20 +00:00
"""
Package to test the openlp.core.ui package.
2013-01-02 21:50:20 +00:00
"""
2020-03-11 21:53:41 +00:00
import pytest
from unittest.mock import MagicMock, patch
2013-02-16 06:51:25 +00:00
2020-03-11 21:53:41 +00:00
from PyQt5 import QtCore, QtTest
2013-02-16 06:51:25 +00:00
2020-03-11 21:53:41 +00:00
from openlp.core.ui.starttimeform import StartTimeForm
2013-01-02 21:50:20 +00:00
2020-03-11 21:53:41 +00:00
@pytest.fixture()
def form(mock_settings):
frm = StartTimeForm()
return frm
2013-01-02 21:50:20 +00:00
2020-03-11 21:53:41 +00:00
def test_ui_defaults(form):
"""
Test StartTimeDialog are defaults correct
"""
assert form.hour_spin_box.minimum() == 0, 'The minimum hour should stay the same as the dialog'
assert form.hour_spin_box.maximum() == 4, 'The maximum hour should stay the same as the dialog'
assert form.minute_spin_box.minimum() == 0, 'The minimum minute should stay the same as the dialog'
assert form.minute_spin_box.maximum() == 59, 'The maximum minute should stay the same as the dialog'
assert form.second_spin_box.minimum() == 0, 'The minimum second should stay the same as the dialog'
assert form.second_spin_box.maximum() == 59, 'The maximum second should stay the same as the dialog'
assert form.hour_finish_spin_box.minimum() == 0, \
'The minimum finish hour should stay the same as the dialog'
assert form.hour_finish_spin_box.maximum() == 4, \
'The maximum finish hour should stay the same as the dialog'
assert form.minute_finish_spin_box.minimum() == 0, \
'The minimum finish minute should stay the same as the dialog'
assert form.minute_finish_spin_box.maximum() == 59, \
'The maximum finish minute should stay the same as the dialog'
assert form.second_finish_spin_box.minimum() == 0, \
'The minimum finish second should stay the same as the dialog'
assert form.second_finish_spin_box.maximum() == 59, \
'The maximum finish second should stay the same as the dialog'
2013-01-02 21:50:20 +00:00
2020-03-11 21:53:41 +00:00
def test_time_display(form):
"""
Test StartTimeDialog display functionality
"""
# GIVEN: A service item with with time
mocked_serviceitem = MagicMock()
mocked_serviceitem.start_time = 61000
mocked_serviceitem.end_time = 3701000
mocked_serviceitem.media_length = 3701000
2013-01-02 21:50:20 +00:00
2020-03-11 21:53:41 +00:00
# WHEN displaying the UI and pressing enter
form.item = {'service_item': mocked_serviceitem}
with patch('PyQt5.QtWidgets.QDialog.exec'):
form.exec()
ok_widget = form.button_box.button(form.button_box.Ok)
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
2013-01-21 06:52:55 +00:00
2020-03-11 21:53:41 +00:00
# THEN the following input values are returned
assert form.hour_spin_box.value() == 0
assert form.minute_spin_box.value() == 1
assert form.second_spin_box.value() == 1
assert form.item['service_item'].start_time == 61000, 'The start time should stay the same'
2020-03-11 21:53:41 +00:00
# WHEN displaying the UI, changing the time to 2min 3secs and pressing enter
form.item = {'service_item': mocked_serviceitem}
with patch('PyQt5.QtWidgets.QDialog.exec'):
form.exec()
form.minute_spin_box.setValue(2)
form.second_spin_box.setValue(3)
ok_widget = form.button_box.button(form.button_box.Ok)
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
2020-03-11 21:53:41 +00:00
# THEN the following values are returned
assert form.hour_spin_box.value() == 0
assert form.minute_spin_box.value() == 2
assert form.second_spin_box.value() == 3
assert form.item['service_item'].start_time == 123000, 'The start time should have changed'