21 """Tests for the Dash autopilot emulators.
23 The autopilot emulators are helpers for tests that check a user journey that
24 involves the dash. The code for some of those tests will not be inside this
25 branch, but in projects that depend on unity or that test the whole system
26 integration. So, we need to test the helpers in order to make sure that we
27 don't break them for those external projects.
32 from unittest
import mock
36 from unity8
import process_helpers
41 class MainWindowTestCase(tests.UnityTestCase):
43 scenarios = tests._get_device_emulation_scenarios()
46 super(MainWindowTestCase, self).setUp()
47 unity_proxy = self.launch_unity()
48 process_helpers.unlock_unity(unity_proxy)
51 class DashEmulatorTestCase(tests.DashBaseTestCase):
53 def test_search(self):
54 self.dash.enter_search_query(
'Test')
55 text_field = self.dash._get_search_text_field()
56 self.assertEqual(text_field.text,
'Test')
58 def test_open_unexisting_scope(self):
59 scope_name =
'unexisting'
60 with mock.patch.object(self.dash,
'pointing_device')
as mock_pointer:
61 exception = self.assertRaises(
62 emulators.UnityEmulatorException,
63 self.dash.open_scope, scope_name)
66 'No scope found with id unexisting', str(exception))
67 self.assertFalse(mock_pointer.called)
69 def test_open_already_opened_scope(self):
70 scope_id = self._get_current_scope_id()
71 with mock.patch.object(self.dash,
'pointing_device')
as mock_pointer:
72 scope = self.dash.open_scope(scope_id)
74 self.assertFalse(mock_pointer.called)
75 self._assert_scope_is_opened(scope, scope_id)
77 def _assert_scope_is_opened(self, scope, scope_id):
78 self.assertTrue(scope.isCurrent)
79 scope_loader = scope.get_parent()
80 self.assertEqual(scope_loader.scopeId, scope_id)
82 def _get_current_scope_id(self):
83 scope = self.dash.dash_content_list.select_single(
84 'QQuickLoader', isCurrent=
True)
87 def test_open_scope_to_the_right(self):
88 leftmost_scope = self._get_leftmost_scope_id()
89 self.dash.open_scope(leftmost_scope)
91 scope_id = self._get_rightmost_scope_id()
92 scope = self.dash.open_scope(scope_id)
93 self._assert_scope_is_opened(scope, scope_id)
95 def _get_leftmost_scope_id(self):
96 scope_loaders = self._get_scope_loaders()
97 leftmost_scope_loader = scope_loaders[0]
98 for loader
in scope_loaders[1:]:
99 if loader.globalRect.x < leftmost_scope_loader.globalRect.x:
100 leftmost_scope_loader = loader
101 return leftmost_scope_loader.scopeId
103 def _get_scope_loaders(self):
104 item = self.dash.dash_content_list.get_children_by_type(
106 return item.get_children_by_type(
'QQuickLoader')
108 def _get_rightmost_scope_id(self):
109 scope_loaders = self._get_scope_loaders()
110 rightmost_scope_loader = scope_loaders[0]
111 for loader
in scope_loaders[1:]:
112 if loader.globalRect.x > rightmost_scope_loader.globalRect.x:
113 rightmost_scope_loader = loader
114 return rightmost_scope_loader.scopeId
116 def test_open_scope_to_the_left(self):
117 rightmost_scope = self._get_rightmost_scope_id()
118 self.dash.open_scope(rightmost_scope)
120 scope_id = self._get_leftmost_scope_id()
121 scope = self.dash.open_scope(scope_id)
122 self._assert_scope_is_opened(scope, scope_id)
124 def test_open_generic_scope(self):
125 scope_id =
'musicaggregator'
126 scope = self.dash.open_scope(scope_id)
127 self._assert_scope_is_opened(scope, scope_id)
128 self.assertIsInstance(scope, dash_emulators.GenericScopeView)
130 def test_open_applications_scope(self):
131 scope_id =
'clickscope'
132 scope = self.dash.open_scope(scope_id)
133 self._assert_scope_is_opened(scope, scope_id)
134 self.assertIsInstance(scope, dash_emulators.GenericScopeView)
137 class GenericScopeViewEmulatorTestCase(tests.DashBaseTestCase):
141 self.useFixture(fixture_setup.FakeScopes())
142 super(GenericScopeViewEmulatorTestCase, self).setUp()
143 self.generic_scope = self.dash.open_scope(
'MockScope1')
145 def test_open_preview(self):
146 preview = self.generic_scope.open_preview(
'0',
'Title.0.0')
147 self.assertIsInstance(preview, dash_emulators.Preview)
148 self.assertTrue(preview.isCurrent)
151 class DashAppsEmulatorTestCase(tests.DashBaseTestCase):
153 available_applications = [
154 'Title.2.0',
'Title.2.1',
'Title.2.2',
'Title.2.3',
'Title.2.4',
155 'Title.2.5',
'Title.2.6',
'Title.2.7',
'Title.2.8',
'Title.2.9',
156 'Title.2.10',
'Title.2.11',
'Title.2.12']
160 self.useFixture(fixture_setup.FakeScopes())
161 super(DashAppsEmulatorTestCase, self).setUp()
162 self.applications_scope = self.dash.open_scope(
'clickscope')
164 def test_get_applications_with_unexisting_category(self):
165 exception = self.assertRaises(
166 emulators.UnityEmulatorException,
167 self.applications_scope.get_applications,
168 'unexisting category')
171 'No category found with name unexisting category', str(exception))
173 def test_get_applications_should_return_correct_applications(self):
175 category_element = self.applications_scope._get_category_element(
177 list_view = self.dash.get_scope(
'clickscope')\
178 .select_single(ListViewWithPageHeader)
179 expected_apps_count = self._get_number_of_application_slots(category)
180 expected_applications = self.available_applications[
181 :expected_apps_count]
182 x_center = list_view.globalRect.x + list_view.width / 2
183 y_center = list_view.globalRect.y + list_view.height / 2
184 y_diff = category_element.y - list_view.height + category_element.height
185 list_view._slow_drag(x_center, x_center,
186 y_center, y_center - y_diff)
187 applications = self.applications_scope.get_applications(category)
188 self.assertEqual(expected_applications, applications)
190 def _get_number_of_application_slots(self, category):
191 category_element = self.applications_scope._get_category_element(
193 cardgrid = category_element.select_single(
'CardGrid')
194 if (category_element.expanded):
195 return cardgrid.select_single(
'QQuickGridView').count
197 return cardgrid.collapsedRows \
198 * cardgrid.select_single(
'ResponsiveGridView').columns