2014-03-14 22:08:44 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2020-01-01 02:53:08 +00:00
|
|
|
# Copyright (c) 2008-2020 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-03-07 12:34:35 +00:00
|
|
|
"""
|
|
|
|
Package to test the openlp.plugins.songs.forms.editverseform package.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
from PyQt5 import QtCore, QtTest, QtWidgets
|
2013-03-07 12:34:35 +00:00
|
|
|
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
|
|
|
from openlp.core.common.settings import Settings
|
2013-03-07 12:34:35 +00:00
|
|
|
from openlp.plugins.songs.forms.editverseform import EditVerseForm
|
2014-03-14 22:08:44 +00:00
|
|
|
from tests.helpers.testmixin import TestMixin
|
2013-03-07 12:34:35 +00:00
|
|
|
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2017-05-30 20:06:27 +00:00
|
|
|
__default_settings__ = {
|
|
|
|
'songs/enable chords': True,
|
|
|
|
}
|
|
|
|
|
2013-03-07 12:34:35 +00:00
|
|
|
|
2014-03-14 22:08:44 +00:00
|
|
|
class TestEditVerseForm(TestCase, TestMixin):
|
2013-03-14 22:22:18 +00:00
|
|
|
"""
|
|
|
|
Test the EditVerseForm class
|
|
|
|
"""
|
|
|
|
|
2013-03-07 12:34:35 +00:00
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the UI
|
|
|
|
"""
|
|
|
|
Registry.create()
|
2014-10-22 20:43:05 +00:00
|
|
|
self.setup_application()
|
2015-11-07 00:49:40 +00:00
|
|
|
self.main_window = QtWidgets.QMainWindow()
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register('main_window', self.main_window)
|
2017-05-30 20:06:27 +00:00
|
|
|
self.build_settings()
|
|
|
|
Settings().extend_default_settings(__default_settings__)
|
2013-03-07 12:34:35 +00:00
|
|
|
self.form = EditVerseForm()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Delete all the C++ objects at the end so that we don't have a segfault
|
|
|
|
"""
|
2017-05-30 20:06:27 +00:00
|
|
|
self.destroy_settings()
|
2013-03-07 12:34:35 +00:00
|
|
|
del self.form
|
|
|
|
del self.main_window
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_ui_defaults(self):
|
2013-03-07 12:34:35 +00:00
|
|
|
"""
|
|
|
|
Test the EditVerseForm defaults are correct
|
|
|
|
"""
|
2013-03-11 08:07:17 +00:00
|
|
|
# GIVEN: An EditVerseForm instance
|
|
|
|
# WHEN: The form is shown
|
|
|
|
# THEN: The default value is correct
|
2017-12-23 09:09:45 +00:00
|
|
|
assert self.form.verse_text_edit.toPlainText() == '', 'The verse edit box is empty.'
|
2013-03-11 08:07:17 +00:00
|
|
|
|
2016-06-01 23:14:58 +00:00
|
|
|
def test_type_verse_text(self):
|
2013-03-11 21:47:55 +00:00
|
|
|
"""
|
|
|
|
Test that typing into the verse text edit box returns the correct text
|
|
|
|
"""
|
2013-03-14 22:22:18 +00:00
|
|
|
# GIVEN: An instance of the EditVerseForm and some text to type
|
|
|
|
text = 'Amazing Grace, how sweet the sound!'
|
|
|
|
|
2013-03-11 21:47:55 +00:00
|
|
|
# WHEN: Some verse text is typed into the text edit
|
2013-03-14 22:22:18 +00:00
|
|
|
QtTest.QTest.keyClicks(self.form.verse_text_edit, text)
|
2013-03-11 21:47:55 +00:00
|
|
|
|
|
|
|
# THEN: The verse text edit should have the verse text in it
|
2017-12-23 09:09:45 +00:00
|
|
|
assert text == self.form.verse_text_edit.toPlainText(), \
|
|
|
|
'The verse text edit should have the typed out verse'
|
2013-03-11 21:47:55 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_insert_verse(self):
|
2013-03-11 08:07:17 +00:00
|
|
|
"""
|
2013-03-11 21:24:55 +00:00
|
|
|
Test that clicking the insert button inserts the correct verse marker
|
2013-03-11 08:07:17 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: An instance of the EditVerseForm
|
|
|
|
# WHEN: The Insert button is clicked
|
|
|
|
QtTest.QTest.mouseClick(self.form.insert_button, QtCore.Qt.LeftButton)
|
|
|
|
|
|
|
|
# THEN: The verse text edit should have a Verse:1 in it
|
2017-12-23 09:09:45 +00:00
|
|
|
assert '---[Verse:1]---' in self.form.verse_text_edit.toPlainText(), \
|
|
|
|
'The verse text edit should have a verse marker'
|
2013-03-11 21:24:55 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_insert_verse_2(self):
|
2013-03-11 21:24:55 +00:00
|
|
|
"""
|
|
|
|
Test that clicking the up button on the spin box and then clicking the insert button inserts the correct marker
|
|
|
|
"""
|
|
|
|
# GIVEN: An instance of the EditVerseForm
|
|
|
|
# WHEN: The spin button and then the Insert button are clicked
|
|
|
|
QtTest.QTest.keyClick(self.form.verse_number_box, QtCore.Qt.Key_Up)
|
|
|
|
QtTest.QTest.mouseClick(self.form.insert_button, QtCore.Qt.LeftButton)
|
|
|
|
|
|
|
|
# THEN: The verse text edit should have a Verse:1 in it
|
2017-12-23 09:09:45 +00:00
|
|
|
assert '---[Verse:2]---' in self.form.verse_text_edit.toPlainText(), \
|
|
|
|
'The verse text edit should have a "Verse 2" marker'
|
2013-03-11 21:47:55 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_insert_chorus(self):
|
2013-03-11 21:47:55 +00:00
|
|
|
"""
|
|
|
|
Test that clicking the verse type combo box and then clicking the insert button inserts the correct marker
|
|
|
|
"""
|
|
|
|
# GIVEN: An instance of the EditVerseForm
|
|
|
|
# WHEN: The verse type combo box and then the Insert button are clicked
|
|
|
|
QtTest.QTest.keyClick(self.form.verse_type_combo_box, QtCore.Qt.Key_Down)
|
|
|
|
QtTest.QTest.mouseClick(self.form.insert_button, QtCore.Qt.LeftButton)
|
|
|
|
|
|
|
|
# THEN: The verse text edit should have a Chorus:1 in it
|
2017-12-23 09:09:45 +00:00
|
|
|
assert '---[Chorus:1]---' in self.form.verse_text_edit.toPlainText(), \
|
|
|
|
'The verse text edit should have a "Chorus 1" marker'
|