20 """Tests for the Dash autopilot emulators.
22 The autopilot emulators are helpers for tests that check a user journey that
23 involves the dash. The code for some of those tests will not be inside this
24 branch, but in projects that depend on unity or that test the whole system
25 integration. So, we need to test the helpers in order to make sure that we
26 don't break them for those external projects.
31 from unittest
import mock
35 from testtools.matchers
import Contains, HasLength
37 from unity8
import process_helpers
42 class MainWindowTestCase(tests.UnityTestCase):
44 scenarios = tests._get_device_emulation_scenarios()
47 super(MainWindowTestCase, self).setUp()
48 unity_proxy = self.launch_unity()
49 process_helpers.unlock_unity(unity_proxy)
51 def test_search(self):
52 self.main_window.search(
'Test')
53 text_field = self.main_window.get_dash()._get_search_text_field()
54 self.assertEqual(text_field.text,
'Test')
55 self.assertEqual(text_field.state,
'idle')
58 class DashBaseTestCase(tests.UnityTestCase):
60 scenarios = tests._get_device_emulation_scenarios()
63 super(DashBaseTestCase, self).setUp()
64 unity_proxy = self.launch_unity()
65 process_helpers.unlock_unity(unity_proxy)
66 self.dash = self.main_window.get_dash()
69 class DashEmulatorTestCase(DashBaseTestCase):
71 def test_open_unexisting_scope(self):
72 scope_name =
'unexisting'
73 with mock.patch.object(self.dash,
'pointing_device')
as mock_pointer:
74 exception = self.assertRaises(
75 emulators.UnityEmulatorException,
76 self.dash.open_scope, scope_name)
79 'No scope found with id unexisting', str(exception))
80 self.assertFalse(mock_pointer.called)
82 def test_open_already_opened_scope(self):
83 scope_id = self._get_current_scope_id()
84 with mock.patch.object(self.dash,
'pointing_device')
as mock_pointer:
85 scope = self.dash.open_scope(scope_id)
87 self.assertFalse(mock_pointer.called)
88 self._assert_scope_is_opened(scope, scope_id)
90 def _assert_scope_is_opened(self, scope, scope_id):
91 self.assertTrue(scope.isCurrent)
92 scope_loader = scope.get_parent()
93 self.assertEqual(scope_loader.scopeId, scope_id)
95 def _get_current_scope_id(self):
96 scope = self.dash.dash_content_list.select_single(
97 'QQuickLoader', isCurrent=
True)
100 def test_open_scope_to_the_right(self):
101 leftmost_scope = self._get_leftmost_scope_id()
102 self.dash.open_scope(leftmost_scope)
104 scope_id = self._get_rightmost_scope_id()
105 scope = self.dash.open_scope(scope_id)
106 self._assert_scope_is_opened(scope, scope_id)
108 def _get_leftmost_scope_id(self):
109 scope_loaders = self._get_scope_loaders()
110 leftmost_scope_loader = scope_loaders[0]
111 for loader
in scope_loaders[1:]:
112 if loader.globalRect.x < leftmost_scope_loader.globalRect.x:
113 leftmost_scope_loader = loader
114 return leftmost_scope_loader.scopeId
116 def _get_scope_loaders(self):
117 item = self.dash.dash_content_list.get_children_by_type(
119 return item.get_children_by_type(
'QQuickLoader')
121 def _get_rightmost_scope_id(self):
122 scope_loaders = self._get_scope_loaders()
123 rightmost_scope_loader = scope_loaders[0]
124 for loader
in scope_loaders[1:]:
125 if loader.globalRect.x > rightmost_scope_loader.globalRect.x:
126 rightmost_scope_loader = loader
127 return rightmost_scope_loader.scopeId
129 def test_open_scope_to_the_left(self):
130 rightmost_scope = self._get_rightmost_scope_id()
131 self.dash.open_scope(rightmost_scope)
133 scope_id = self._get_leftmost_scope_id()
134 scope = self.dash.open_scope(scope_id)
135 self._assert_scope_is_opened(scope, scope_id)
137 def test_open_generic_scope(self):
139 scope = self.dash.open_scope(scope_id)
140 self._assert_scope_is_opened(scope, scope_id)
141 self.assertIsInstance(scope, dash_emulators.GenericScopeView)
143 def test_open_applications_scope(self):
144 scope_id =
'clickscope'
145 scope = self.dash.open_scope(scope_id)
146 self._assert_scope_is_opened(scope, scope_id)
147 self.assertIsInstance(scope, dash_emulators.DashApps)
150 class GenericScopeViewEmulatorTestCase(DashBaseTestCase):
154 self.useFixture(fixture_setup.FakeScopes())
155 super(GenericScopeViewEmulatorTestCase, self).setUp()
156 self.generic_scope = self.dash.open_scope(
'MockScope1')
158 def test_open_preview(self):
159 preview = self.generic_scope.open_preview(
'0',
'Title.0.0')
160 self.assertIsInstance(preview, dash_emulators.Preview)
161 self.assertTrue(preview.isCurrent)
164 class DashAppsEmulatorTestCase(DashBaseTestCase):
166 available_applications = [
167 'Title.2.0',
'Title.2.1',
'Title.2.2',
'Title.2.3',
'Title.2.4',
168 'Title.2.5',
'Title.2.6',
'Title.2.7',
'Title.2.8',
'Title.2.9',
169 'Title.2.10',
'Title.2.11',
'Title.2.12']
173 self.useFixture(fixture_setup.FakeScopes())
174 super(DashAppsEmulatorTestCase, self).setUp()
175 self.applications_scope = self.dash.open_scope(
'clickscope')
177 def test_get_applications_with_unexisting_category(self):
178 exception = self.assertRaises(
179 emulators.UnityEmulatorException,
180 self.applications_scope.get_applications,
181 'unexisting category')
184 'No category found with name unexisting category', str(exception))
186 def test_get_applications_should_return_correct_applications(self):
188 expected_apps_count = self._get_number_of_application_slots(category)
189 expected_applications = self.available_applications[
190 :expected_apps_count]
191 applications = self.applications_scope.get_applications(category)
192 self.assertEqual(expected_applications, applications)
194 def _get_number_of_application_slots(self, category):
195 category_element = self.applications_scope._get_category_element(
197 grid = category_element.select_single(
'CardFilterGrid')
198 filtergrid = grid.select_single(
'FilterGrid')
200 return filtergrid.collapsedRowCount * filtergrid.columns
202 return filtergrid.uncollapsedRowCount * filtergrid.columns