1
# -*- coding: utf-8 -*-
3
# Copyright 2012 Canonical Ltd.
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 3, as published
7
# by the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12
# PURPOSE. See the GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License along
15
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
# In addition, as a special exception, the copyright holders give
18
# permission to link the code of portions of this program with the
19
# OpenSSL library under certain conditions as described in each
20
# individual source file, and distribute linked combinations
22
# You must obey the GNU General Public License in all respects
23
# for all of the code used other than OpenSSL. If you modify
24
# file(s) with this exception, you may extend this exception to your
25
# version of the file(s), but you are not obligated to do so. If you
26
# do not wish to do so, delete this exception statement from your
27
# version. If you delete this exception statement from all source
28
# files in the program, then also delete it here.
29
"""Tests for the expander widget."""
31
from PyQt4.QtGui import QLabel
32
from twisted.internet import defer
33
from twisted.trial.unittest import TestCase
35
from ubuntu_sso.qt.arrow import QArrow
36
from ubuntu_sso.qt.expander import QExpanderLabel, QExpander
38
# pylint: disable=C0103, W0201, W0212
41
class QExpanderLabelTestCase(TestCase):
42
"""Test the expander labe."""
44
@defer.inlineCallbacks
47
yield super(QExpanderLabelTestCase, self).setUp()
48
self.label_content = 'test'
49
self.label = QExpanderLabel(self.label_content)
51
def test_mouse_press_event_arrow_right(self):
52
"""Test the actions taken when we press the mouse."""
53
self.label.arrow.direction = QArrow.RIGHT
54
self.label.mousePressEvent(None)
55
self.assertEqual(QArrow.DOWN, self.label.arrow.direction)
57
def test_mouse_press_event_arrow_down(self):
58
"""Test the actions taken when we press the mouse."""
59
self.label.arrow.direction = QArrow.DOWN
60
self.label.mousePressEvent(None)
61
self.assertEqual(QArrow.RIGHT, self.label.arrow.direction)
64
"""Test getting the text."""
65
self.assertEqual(self.label.label.text(), self.label.text())
67
def test_set_text(self):
68
"""Test setting the text."""
70
self.label.setText(new_label)
71
self.assertEqual(self.label.label.text(), new_label)
74
class QExpanderTestCase(TestCase):
75
"""Test the QExpander widget."""
77
@defer.inlineCallbacks
80
yield super(QExpanderTestCase, self).setUp()
81
self.label_content = 'test'
82
self.expander = QExpander(self.label_content)
85
"""Test the constructor."""
87
def test_add_widget(self):
88
"""Test adding a widget."""
89
widget = QLabel('test')
90
widget.setObjectName('test')
91
self.expander.addWidget(widget)
92
self.assertEqual(widget, self.expander.content)
93
self.assertEqual(1, self.expander.layout.indexOf(widget))
95
def test_add_widget_present(self):
96
"""Test adding a widge when one is already present."""
97
old_widget = QLabel('old')
98
widget = QLabel('test')
99
self.expander.addWidget(old_widget)
100
self.expander.addWidget(widget)
101
self.assertEqual(-1, self.expander.layout.indexOf(old_widget))
102
self.assertEqual(1, self.expander.layout.indexOf(widget))
104
def test_add_widget_expanded(self):
105
"""Test adding a widget when we are expanded."""
106
widget = QLabel('test')
107
self.expander._expanded = True
108
self.expander.addWidget(widget)
109
self.assertEqual(1, self.expander.layout.indexOf(widget))
111
def test_add_widget_collapsed(self):
112
"""Test adding a widget when we are collapsed."""
113
widget = QLabel('test')
114
self.expander._expanded = False
115
self.expander.addWidget(widget)
116
self.assertEqual(1, self.expander.layout.indexOf(widget))
117
self.assertFalse(widget.isVisible())
120
"""Test getting the text."""
121
self.assertEqual(self.expander.text(), self.expander.label.text())
123
def test_set_text(self):
124
"""Test setting the text."""
125
label_content = 'content'
126
self.expander.setText(label_content)
127
self.assertEqual(label_content, self.expander.label.text())
129
def test_expanded(self):
130
"""Test getting expanded."""
131
self.expander._expanded = True
132
self.assertEqual(self.expander.expanded(), self.expander._expanded)