~nick-dedekind/ubuntu-ui-toolkit/lp1378821.time-translation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Copyright (C) 2013-2015 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; version 3.
#
# 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from unittest import mock

import ubuntuuitoolkit
from ubuntuuitoolkit import tests


class MainView10TestCase(tests.QMLStringAppTestCase):

    test_qml = ("""
import QtQuick 2.0
import Ubuntu.Components 1.0

MainView {
    width: units.gu(48)
    height: units.gu(60)
    objectName: "mainView"
}
""")

    def test_main_view_custom_proxy_object(self):
        self.assertIsInstance(self.main_view, ubuntuuitoolkit.MainView)

    def test_get_header_without_header(self):
        header = self.main_view.get_header()
        self.assertFalse(header.visible)

    def test_toolbar_custom_proxy_object(self):
        toolbar = self.main_view.get_toolbar()
        self.assertIsInstance(toolbar, ubuntuuitoolkit.Toolbar)

    def test_open_toolbar(self):
        with mock.patch.object(ubuntuuitoolkit.Toolbar, 'open') as mock_open:
            self.main_view.open_toolbar()

        mock_open.assert_called_once_with()

    def test_close_toolbar(self):
        with mock.patch.object(ubuntuuitoolkit.Toolbar, 'close') as mock_close:
            self.main_view.close_toolbar()

        mock_close.assert_called_once_with()

    def test_open_toolbar_returns_the_toolbar(self):
        toolbar = self.main_view.open_toolbar()
        self.assertIsInstance(toolbar, ubuntuuitoolkit.Toolbar)

    def test_get_tabs_without_tabs(self):
        error = self.assertRaises(
            ubuntuuitoolkit.ToolkitException, self.main_view.get_tabs)
        self.assertEqual(
            str(error), 'The MainView has no Tabs.')

    def test_switch_to_next_tab_without_tabs(self):
        header = self.main_view.get_header()
        error = self.assertRaises(
            ubuntuuitoolkit.ToolkitException,
            header.switch_to_next_tab)
        self.assertEqual(
            str(error), 'The MainView has no Tabs.')


class MainView12TestCase(tests.QMLStringAppTestCase):

    test_qml = ("""
import QtQuick 2.3
import Ubuntu.Components 1.2

MainView {
    width: units.gu(48)
    height: units.gu(60)
    objectName: "mainView"
}
""")

    def test_main_view_custom_proxy_object(self):
        self.assertIsInstance(self.main_view, ubuntuuitoolkit.MainView)

    def test_get_header_without_header(self):
        header = self.main_view.get_header()
        self.assertFalse(header.visible)

    def test_get_tabs_without_tabs(self):
        error = self.assertRaises(
            ubuntuuitoolkit.ToolkitException, self.main_view.get_tabs)
        self.assertEqual(
            str(error), 'The MainView has no Tabs.')

    def test_switch_to_next_tab_without_tabs(self):
        header = self.main_view.get_header()
        error = self.assertRaises(
            ubuntuuitoolkit.ToolkitException,
            header.switch_to_next_tab)
        self.assertEqual(
            str(error), 'The MainView has no Tabs.')

    def test_get_toolbar_without_toolbar(self):
        error = self.assertRaises(
            ubuntuuitoolkit.ToolkitException, self.main_view.get_toolbar)
        self.assertEqual(
            str(error), 'The MainView has no Toolbar.')

    def test_open_toolbar_without_toolbar(self):
        error = self.assertRaises(
            ubuntuuitoolkit.ToolkitException, self.main_view.open_toolbar)
        self.assertEqual(
            str(error), 'The MainView has no Toolbar.')

    def test_close_toolbar_without_toolbar(self):
        error = self.assertRaises(
            ubuntuuitoolkit.ToolkitException, self.main_view.close_toolbar)
        self.assertEqual(
            str(error), 'The MainView has no Toolbar.')


TEST_GO_BACK_QML_FORMAT = ("""
import QtQuick 2.0
import Ubuntu.Components 1.0

MainView {{
    width: units.gu(48)
    height: units.gu(60)
    objectName: "mainView"
    useDeprecatedToolbar: {use_deprecated_toolbar}

    PageStack {{
        id: pageStack
        Component.onCompleted: push(page0)

        Page {{
            id: page0
            title: "Page 0"
            visible: false

            Button {{
                objectName: "go_to_page1"
                text: "Go to page 1"
                onClicked: pageStack.push(page1)
            }}
        }}

        Page {{
            id: page1
            title: "Page 1"
            visible: false
        }}
    }}
}}
""")


class GoBackTestCase(tests.QMLStringAppTestCase):

    scenarios = [
        ('back in toolbar', dict(
            test_qml=TEST_GO_BACK_QML_FORMAT.format(
                use_deprecated_toolbar='true'))),
        ('back in header', dict(
            test_qml=TEST_GO_BACK_QML_FORMAT.format(
                use_deprecated_toolbar='false')))
    ]

    def setUp(self):
        super().setUp()
        self.header = self.main_view.get_header()
        self.assertEqual(self.header.title, 'Page 0')

    def test_open_page(self):
        self._go_to_page1()
        self.assertEqual(self.header.title, 'Page 1')

    def _go_to_page1(self):
        button = self.main_view.select_single(
            'Button',
            objectName='go_to_page1')
        self.pointing_device.click_object(button)
        self.header.wait_for_animation()

    def test_go_back(self):
        self._go_to_page1()
        self.main_view.go_back()
        self.assertEqual(self.header.title, 'Page 0')