openlp/tests/openlp_core/ui/test_servicenotedialog.py

75 lines
3.1 KiB
Python
Raw Permalink Normal View History

2014-03-14 20:06:24 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2022-02-01 10:10:57 +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-27 20:36:18 +00:00
"""
Package to test the openlp.core.ui package.
2013-01-27 20:36:18 +00:00
"""
2020-03-11 21:53:41 +00:00
import pytest
from unittest.mock import 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.servicenoteform import ServiceNoteForm
2013-02-16 06:51:25 +00:00
2013-01-27 20:36:18 +00:00
2021-09-08 05:00:11 +00:00
@pytest.fixture
2020-03-11 21:53:41 +00:00
def form(settings):
frm = ServiceNoteForm()
return frm
2013-01-27 20:36:18 +00:00
2020-03-11 21:53:41 +00:00
def test_basic_display(form):
"""
Test Service Note form functionality
"""
# GIVEN: A dialog with an empty text box
form.text_edit.setPlainText('')
2013-01-27 20:36:18 +00:00
2020-03-11 21:53:41 +00:00
# WHEN displaying the UI and pressing enter
2021-09-08 05:00:11 +00:00
with patch('openlp.core.ui.servicenoteform.QtWidgets.QDialog.exec'):
2020-03-11 21:53:41 +00:00
form.exec()
ok_widget = form.button_box.button(form.button_box.Save)
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
2013-01-27 20:36:18 +00:00
2020-03-11 21:53:41 +00:00
# THEN the following input text is returned
assert form.text_edit.toPlainText() == '', 'The returned text should be empty'
2013-01-27 20:36:18 +00:00
2020-03-11 21:53:41 +00:00
# WHEN displaying the UI, having set the text and pressing enter
text = 'OpenLP is the best worship software'
form.text_edit.setPlainText(text)
2021-09-08 05:00:11 +00:00
with patch('openlp.core.ui.servicenoteform.QtWidgets.QDialog.exec'):
2020-03-11 21:53:41 +00:00
form.exec()
ok_widget = form.button_box.button(form.button_box.Save)
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
2013-01-27 20:36:18 +00:00
2020-03-11 21:53:41 +00:00
# THEN the following text is returned
assert form.text_edit.toPlainText() == text, 'The text originally entered should still be there'
2013-01-27 20:36:18 +00:00
2020-03-11 21:53:41 +00:00
# WHEN displaying the UI, having set the text and pressing enter
form.text_edit.setPlainText('')
2021-09-08 05:00:11 +00:00
with patch('openlp.core.ui.servicenoteform.QtWidgets.QDialog.exec'):
2020-03-11 21:53:41 +00:00
form.exec()
form.text_edit.setPlainText(text)
ok_widget = form.button_box.button(form.button_box.Save)
QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton)
2013-01-27 20:36:18 +00:00
2020-03-11 21:53:41 +00:00
# THEN the following text is returned
assert form.text_edit.toPlainText() == text, 'The new text should be returned'