openlp/tests/interfaces/openlp_plugins/songs/forms/test_editverseform.py

99 lines
3.7 KiB
Python
Raw Normal View History

2013-03-07 12:34:35 +00:00
"""
Package to test the openlp.plugins.songs.forms.editverseform package.
"""
from unittest import TestCase
from PyQt4 import QtCore, QtGui, QtTest
2013-03-07 12:34:35 +00:00
2013-12-13 17:44:05 +00:00
from openlp.core.common import Registry
2013-03-07 12:34:35 +00:00
from openlp.plugins.songs.forms.editverseform import EditVerseForm
class TestEditVerseForm(TestCase):
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()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
2013-03-07 12:34:35 +00:00
self.main_window = QtGui.QMainWindow()
2013-08-31 18:17:38 +00:00
Registry().register('main_window', self.main_window)
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
"""
del self.form
del self.main_window
def ui_defaults_test(self):
"""
Test the EditVerseForm defaults are correct
"""
# GIVEN: An EditVerseForm instance
# WHEN: The form is shown
# THEN: The default value is correct
2013-08-31 18:17:38 +00:00
self.assertEqual(self.form.verse_text_edit.toPlainText(), '', 'The verse edit box is empty.')
2013-03-11 21:47:55 +00:00
def type_verse_text_tests(self):
"""
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
2013-03-14 22:22:18 +00:00
self.assertEqual(text, self.form.verse_text_edit.toPlainText(),
2013-08-31 18:17:38 +00:00
'The verse text edit should have the typed out verse')
2013-03-11 21:47:55 +00:00
def insert_verse_test(self):
"""
2013-03-11 21:24:55 +00:00
Test that clicking the insert button inserts the correct verse marker
"""
# 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
2013-08-31 18:17:38 +00:00
self.assertIn('---[Verse:1]---', self.form.verse_text_edit.toPlainText(),
'The verse text edit should have a verse marker')
2013-03-11 21:24:55 +00:00
def insert_verse_2_test(self):
"""
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
2013-08-31 18:17:38 +00:00
self.assertIn('---[Verse:2]---', self.form.verse_text_edit.toPlainText(),
'The verse text edit should have a "Verse 2" marker')
2013-03-11 21:47:55 +00:00
def insert_chorus_test(self):
"""
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
2013-08-31 18:17:38 +00:00
self.assertIn('---[Chorus:1]---', self.form.verse_text_edit.toPlainText(),
'The verse text edit should have a "Chorus 1" marker')
2013-03-11 21:47:55 +00:00