openlp/tests/functional/openlp_plugins/songs/test_editverseform.py

115 lines
5.0 KiB
Python
Raw Normal View History

2015-03-02 19:21:41 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# 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/>. #
##########################################################################
2015-02-23 18:30:45 +00:00
"""
This module contains tests for the editverseform of the Songs plugin.
"""
from unittest import TestCase
from unittest.mock import MagicMock
2015-02-23 18:30:45 +00:00
from PyQt5 import QtCore
2015-02-23 18:30:45 +00:00
from openlp.core.common.registry import Registry
2015-02-23 18:30:45 +00:00
from openlp.plugins.songs.forms.editverseform import EditVerseForm
from tests.helpers.testmixin import TestMixin
2018-10-02 04:39:42 +00:00
2015-02-23 18:30:45 +00:00
class TestEditVerseForm(TestCase, TestMixin):
"""
Test the functions in the :mod:`lib` module.
"""
def setUp(self):
"""
Set up the components need for all tests.
"""
self.setup_application()
self.build_settings()
self.setting.setValue('songs/enable chords', True)
Registry.create()
Registry().register('settings', self.setting)
self.edit_verse_form = EditVerseForm(None)
2015-02-23 18:30:45 +00:00
QtCore.QLocale.setDefault(QtCore.QLocale('en_GB'))
def tearDown(self):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
self.destroy_settings()
2019-09-26 20:49:05 +00:00
def test_update_suggested_verse_number_has_no_effect(self):
2015-02-23 18:30:45 +00:00
"""
2015-02-27 19:33:49 +00:00
Test that update_suggested_verse_number() has no effect when editing a single verse
2015-02-23 18:30:45 +00:00
"""
# GIVEN some input values
self.edit_verse_form.has_single_verse = True
2015-03-02 19:21:41 +00:00
self.edit_verse_form.verse_type_combo_box.currentIndex = MagicMock(return_value=0)
self.edit_verse_form.verse_text_edit.toPlainText = MagicMock(return_value='Text')
2015-02-23 18:30:45 +00:00
self.edit_verse_form.verse_number_box.setValue(3)
2015-03-02 19:21:41 +00:00
2015-02-23 18:30:45 +00:00
# WHEN the method is called
self.edit_verse_form.update_suggested_verse_number()
2015-03-02 19:21:41 +00:00
2015-02-23 18:30:45 +00:00
# THEN the verse number must not be changed
2017-12-22 17:51:59 +00:00
assert 3 == self.edit_verse_form.verse_number_box.value(), 'The verse number should be 3'
2017-08-09 05:15:10 +00:00
2019-09-26 20:49:05 +00:00
def test_update_suggested_verse_number_different_type(self):
"""
Test that update_suggested_verse_number() returns 0 when editing a second verse of a different type
"""
# GIVEN some input values
self.edit_verse_form.has_single_verse = False
self.edit_verse_form.verse_type_combo_box.currentIndex = MagicMock(return_value=2)
self.edit_verse_form.verse_text_edit.toPlainText = MagicMock(return_value='Text')
self.edit_verse_form.verse_number_box.setValue(3)
# WHEN the method is called
self.edit_verse_form.update_suggested_verse_number()
# THEN the verse number must be changed to 1
assert 1 == self.edit_verse_form.verse_number_box.value(), 'The verse number should be 1'
2017-08-09 05:15:10 +00:00
def test_on_divide_split_button_clicked(self):
"""
Test that divide adds text at the correct position
"""
# GIVEN some input values
2017-08-11 16:09:14 +00:00
self.edit_verse_form.verse_type_combo_box.currentIndex = MagicMock(return_value=4)
self.edit_verse_form.verse_text_edit.setPlainText('Text\n')
2017-08-09 05:15:10 +00:00
# WHEN the method is called
2017-08-27 17:13:14 +00:00
self.edit_verse_form.on_forced_split_button_clicked()
2017-08-09 05:15:10 +00:00
# THEN the verse number must not be changed
2017-12-22 17:51:59 +00:00
assert '[--}{--]\nText\n' == self.edit_verse_form.verse_text_edit.toPlainText(), \
'The verse number should be [--}{--]\nText\n'
2017-08-11 16:09:14 +00:00
def test_on_split_button_clicked(self):
"""
Test that divide adds text at the correct position
"""
# GIVEN some input values
self.edit_verse_form.verse_type_combo_box.currentIndex = MagicMock(return_value=4)
self.edit_verse_form.verse_text_edit.setPlainText('Text\n')
# WHEN the method is called
2017-08-27 17:13:14 +00:00
self.edit_verse_form.on_overflow_split_button_clicked()
2017-08-11 16:09:14 +00:00
# THEN the verse number must not be changed
2017-12-22 17:51:59 +00:00
assert '[---]\nText\n' == self.edit_verse_form.verse_text_edit.toPlainText(), \
'The verse number should be [---]\nText\n'