1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2013 Canonical
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
"""Terminal app autopilot tests."""
10
from __future__ import absolute_import
12
from autopilot.matchers import Eventually
13
from testtools.matchers import Equals
15
from ubuntu_terminal_app.tests import TerminalTestCase
16
from ubuntu_terminal_app import DbMan
17
from ubuntuuitoolkit import ToolkitException
18
from testscenarios import TestWithScenarios
20
from time import sleep
24
class TestMainWindow(TerminalTestCase):
26
def test_circle_menu_shows(self):
27
"""Make sure that Circle Menu is visible
29
self.app.main_view.long_tap_terminal_center()
30
menu = self.app.main_view.get_circle_menu()
31
self.assertThat(menu.visible, Eventually(Equals(True)))
33
def test_header(self):
34
"""Make sure that Header is visible
35
in Portrait Mode and not visible in landscape mode"""
36
kterm = self.app.main_view.get_terminal_page()
37
header = self.app.main_view.get_header()
38
if kterm.width > kterm.height:
39
self.assertThat(header.visible, Equals(False))
41
self.assertThat(header.visible, Equals(True))
44
class TestPanel(TerminalTestCase, TestWithScenarios):
48
{'button': 'controlkeysaction',
49
'helper_method': 'get_control_panel'
53
{'button': 'functionkeysaction',
54
'helper_method': 'get_function_panel'
58
{'button': 'textkeysaction',
59
'helper_method': 'get_text_panel'
63
def open_panel(self, button, helper_method):
64
"""Open named panel"""
65
header = self.app.main_view.get_header()
66
header.click_action_button(button)
67
get_panel = getattr(self.app.main_view, helper_method)
71
"""Close any open panel"""
72
header = self.app.main_view.get_header()
74
# the overflow panel can be left open, so we need to try again
75
# https://bugs.launchpad.net/ubuntu-terminal-app/+bug/1363233
77
header.click_action_button('hidepanelaction')
80
header.click_action_button('hidepanelaction')
81
except ToolkitException:
83
except ToolkitException:
86
def test_panels(self):
87
"""Make sure that Panel is visible
88
when clicking the toolbar popup items and hides properly."""
89
panel = self.open_panel(self.button, self.helper_method)
90
self.assertThat(panel.visible, Eventually(Equals(True)))
92
self.assertThat(panel.visible, Eventually(Equals(False)))
95
class TestSettings(TerminalTestCase, DbMan):
97
def click_item_selector_item(self, selector, value):
98
"""Clicks item from item selector"""
99
# This needs a toolkit helper
100
# https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1272345
101
select = self.app.main_view.wait_select_single('ItemSelector',
103
container = select.wait_select_single('Standard',
104
objectName='listContainer')
105
self.app.pointing_device.click_object(container)
106
select.currentlyExpanded.wait_for(True)
107
# waiting for currentlyExpanded is not enough
108
# some animation is not accounted for and thus we sleep
110
item = container.wait_select_single('Label', text=value)
111
self.app.pointing_device.click_object(item)
112
select.currentlyExpanded.wait_for(False)
113
# waiting for currentlyExpanded is not enough
114
# some animation is not accounted for and thus we sleep
117
def test_color_scheme_changes(self):
118
"""Make sure that color scheme is set correctly"""
120
# are these string translatable?
121
# if so, we need to do this another way
122
schemeList = ("BlackOnRandomLight",
124
"BlackOnLightYellow",
130
colorScheme = self.get_color_scheme_from_storage
131
for scheme in schemeList:
132
header = self.app.main_view.get_header()
133
header.click_action_button('SettingsButton')
134
self.click_item_selector_item("liSchemes", scheme)
135
self.app.main_view.go_back()
136
self.assertThat(colorScheme, Eventually(Equals(scheme)))
138
def test_font_size_changes(self):
139
"""Make sure that font size is set correctly"""
140
header = self.app.main_view.get_header()
141
header.click_action_button('SettingsButton')
143
font_size = self.get_font_size_from_storage
145
# change font size to min
146
self.app.main_view.drag_horizontal_slider("slFont", 8)
147
self.assertThat(font_size, Eventually(Equals(8)))
149
# change font size to max
150
self.app.main_view.drag_horizontal_slider("slFont", 32)
151
self.assertThat(font_size, Eventually(Equals(32)))
153
# change font size to random sizes
154
for loop in range(1, 3):
155
randSize = random.randrange(9, 31, 1)
156
self.app.main_view.drag_horizontal_slider("slFont", randSize)
157
self.assertThat(font_size, Eventually(Equals(randSize)))