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 unity8
import process_helpers
40 class MainWindowTestCase(tests.UnityTestCase):
42 scenarios = tests._get_device_emulation_scenarios()
45 super(MainWindowTestCase, self).setUp()
46 unity_proxy = self.launch_unity()
47 process_helpers.unlock_unity(unity_proxy)
49 def test_search(self):
50 self.main_window.search(
'Test')
51 text_field = self.main_window.get_dash()._get_search_text_field()
52 self.assertEqual(text_field.text,
'Test')
55 class DashBaseTestCase(tests.UnityTestCase):
57 scenarios = tests._get_device_emulation_scenarios()
60 super(DashBaseTestCase, self).setUp()
61 unity_proxy = self.launch_unity()
62 process_helpers.unlock_unity(unity_proxy)
63 self.dash = self.main_window.get_dash()
66 class DashEmulatorTestCase(DashBaseTestCase):
68 def test_open_unexisting_scope(self):
69 scope_name =
'unexisting'
70 with mock.patch.object(self.dash,
'pointing_device')
as mock_pointer:
71 exception = self.assertRaises(
72 emulators.UnityEmulatorException,
73 self.dash.open_scope, scope_name)
76 'No scope found with id unexisting', str(exception))
77 self.assertFalse(mock_pointer.called)
79 def test_open_already_opened_scope(self):
80 scope_id = self._get_current_scope_id()
81 with mock.patch.object(self.dash,
'pointing_device')
as mock_pointer:
82 scope = self.dash.open_scope(scope_id)
84 self.assertFalse(mock_pointer.called)
85 self._assert_scope_is_opened(scope, scope_id)
87 def _assert_scope_is_opened(self, scope, scope_id):
88 self.assertTrue(scope.isCurrent)
89 scope_loader = scope.get_parent()
90 self.assertEqual(scope_loader.scopeId, scope_id)
92 def _get_current_scope_id(self):
93 scope = self.dash.dash_content_list.select_single(
94 'QQuickLoader', isCurrent=
True)
97 def test_open_scope_to_the_right(self):
98 leftmost_scope = self._get_leftmost_scope_id()
99 self.dash.open_scope(leftmost_scope)
101 scope_id = self._get_rightmost_scope_id()
102 scope = self.dash.open_scope(scope_id)
103 self._assert_scope_is_opened(scope, scope_id)
105 def _get_leftmost_scope_id(self):
106 scope_loaders = self._get_scope_loaders()
107 leftmost_scope_loader = scope_loaders[0]
108 for loader
in scope_loaders[1:]:
109 if loader.globalRect.x < leftmost_scope_loader.globalRect.x:
110 leftmost_scope_loader = loader
111 return leftmost_scope_loader.scopeId
113 def _get_scope_loaders(self):
114 item = self.dash.dash_content_list.get_children_by_type(
116 return item.get_children_by_type(
'QQuickLoader')
118 def _get_rightmost_scope_id(self):
119 scope_loaders = self._get_scope_loaders()
120 rightmost_scope_loader = scope_loaders[0]
121 for loader
in scope_loaders[1:]:
122 if loader.globalRect.x > rightmost_scope_loader.globalRect.x:
123 rightmost_scope_loader = loader
124 return rightmost_scope_loader.scopeId
126 def test_open_scope_to_the_left(self):
127 rightmost_scope = self._get_rightmost_scope_id()
128 self.dash.open_scope(rightmost_scope)
130 scope_id = self._get_leftmost_scope_id()
131 scope = self.dash.open_scope(scope_id)
132 self._assert_scope_is_opened(scope, scope_id)
134 def test_open_generic_scope(self):
136 scope = self.dash.open_scope(scope_id)
137 self._assert_scope_is_opened(scope, scope_id)
138 self.assertIsInstance(scope, dash_emulators.GenericScopeView)
140 def test_open_applications_scope(self):
141 scope_id =
'clickscope'
142 scope = self.dash.open_scope(scope_id)
143 self._assert_scope_is_opened(scope, scope_id)
144 self.assertIsInstance(scope, dash_emulators.DashApps)
147 class GenericScopeViewEmulatorTestCase(DashBaseTestCase):
151 self.useFixture(fixture_setup.FakeScopes())
152 super(GenericScopeViewEmulatorTestCase, self).setUp()
153 self.generic_scope = self.dash.open_scope(
'MockScope1')
155 def test_open_preview(self):
156 preview = self.generic_scope.open_preview(
'0',
'Title.0.0')
157 self.assertIsInstance(preview, dash_emulators.Preview)
158 self.assertTrue(preview.isCurrent)
161 class DashAppsEmulatorTestCase(DashBaseTestCase):
163 available_applications = [
164 'Title.2.0',
'Title.2.1',
'Title.2.2',
'Title.2.3',
'Title.2.4',
165 'Title.2.5',
'Title.2.6',
'Title.2.7',
'Title.2.8',
'Title.2.9',
166 'Title.2.10',
'Title.2.11',
'Title.2.12']
170 self.useFixture(fixture_setup.FakeScopes())
171 super(DashAppsEmulatorTestCase, self).setUp()
172 self.applications_scope = self.dash.open_scope(
'clickscope')
174 def test_get_applications_with_unexisting_category(self):
175 exception = self.assertRaises(
176 emulators.UnityEmulatorException,
177 self.applications_scope.get_applications,
178 'unexisting category')
181 'No category found with name unexisting category', str(exception))
183 def test_get_applications_should_return_correct_applications(self):
185 expected_apps_count = self._get_number_of_application_slots(category)
186 expected_applications = self.available_applications[
187 :expected_apps_count]
188 applications = self.applications_scope.get_applications(category)
189 self.assertEqual(expected_applications, applications)
191 def _get_number_of_application_slots(self, category):
192 category_element = self.applications_scope._get_category_element(
194 grid = category_element.select_single(
'CardFilterGrid')
195 filtergrid = grid.select_single(
'FilterGrid')
197 return filtergrid.collapsedRowCount * filtergrid.columns
199 return filtergrid.uncollapsedRowCount * filtergrid.columns