1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2013, 2014 Canonical Ltd.
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License as published by
7
# the Free Software Foundation; version 3.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
from unittest import mock
22
import ubuntuuitoolkit
23
from ubuntuuitoolkit import tests
26
class ToolbarTestCase(tests.QMLStringAppTestCase):
30
import Ubuntu.Components 0.1
36
// Make sure that for these tests the toolbar starts closed.
37
Component.onCompleted: {
38
__propagated.toolbar.close();
45
objectName: "clicked_label"
46
anchors.centerIn: parent
47
text: "Button not clicked."
52
objectName: "buttonName"
55
onTriggered: label.text = "Button clicked."
64
super(ToolbarTestCase, self).setUp()
65
self.toolbar = self.main_view.get_toolbar()
66
# toolbar may be opened or closed now, depending on whether
67
# the application has been deactivated and resumed already
69
def test_open_toolbar(self):
71
self.assertTrue(self.toolbar.opened)
72
self.assertFalse(self.toolbar.animating)
74
def test_opened_toolbar_is_not_opened_again(self):
76
with mock.patch.object(
77
self.main_view.pointing_device, 'drag') as mock_drag:
80
self.assertFalse(mock_drag.called)
81
self.assertTrue(self.toolbar.opened)
83
def test_close_toolbar(self):
86
self.assertFalse(self.toolbar.opened)
87
self.assertFalse(self.toolbar.animating)
89
def test_closed_toolbar_is_not_closed_again(self):
91
with mock.patch.object(
92
self.main_view.pointing_device, 'drag') as mock_drag:
95
self.assertFalse(mock_drag.called)
96
self.assertFalse(self.toolbar.opened)
98
def test_click_toolbar_button(self):
100
label = self.app.select_single('Label', objectName='clicked_label')
101
self.assertNotEqual(label.text, 'Button clicked.')
103
self.toolbar.click_button('buttonName')
104
self.assertEqual(label.text, 'Button clicked.')
106
def test_click_unexisting_button(self):
107
self.main_view.open_toolbar()
108
error = self.assertRaises(
109
ubuntuuitoolkit.ToolkitException, self.toolbar.click_button,
112
str(error), 'Button with objectName "unexisting" not found.')
114
def test_click_button_on_closed_toolbar(self):
116
error = self.assertRaises(
117
ubuntuuitoolkit.ToolkitException, self.toolbar.click_button,
121
'Toolbar must be opened before calling click_button().')