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.
31 from unity8
import process_helpers
36 class MainWindowTestCase(tests.UnityTestCase):
38 scenarios = tests._get_device_emulation_scenarios()
42 unity_proxy = self.launch_unity()
43 process_helpers.unlock_unity(unity_proxy)
46 class DashEmulatorTestCase(tests.DashBaseTestCase):
48 def test_search(self):
49 self.dash.enter_search_query(
'Test')
50 text_field = self.dash._get_search_text_field()
51 self.assertEqual(text_field.text,
'Test')
53 def test_open_scope_to_the_right(self):
54 leftmost_scope = self._get_leftmost_scope_id()
55 self.dash.open_scope(leftmost_scope)
57 scope_id = self._get_rightmost_scope_id()
58 scope = self.dash.open_scope(scope_id)
59 self._assert_scope_is_opened(scope, scope_id)
61 def _assert_scope_is_opened(self, scope, scope_id):
62 self.assertTrue(scope.isCurrent)
63 scope_loader = scope.get_parent()
64 self.assertEqual(scope_loader.scopeId, scope_id)
66 def _get_leftmost_scope_id(self):
67 scope_loaders = self._get_scope_loaders()
68 leftmost_scope_loader = scope_loaders[0]
69 for loader
in scope_loaders[1:]:
70 if loader.globalRect.x < leftmost_scope_loader.globalRect.x:
71 leftmost_scope_loader = loader
72 return leftmost_scope_loader.scopeId
74 def _get_scope_loaders(self):
75 item = self.dash.dash_content_list.get_children_by_type(
77 return item.get_children_by_type(
'QQuickLoader')
79 def _get_rightmost_scope_id(self):
80 scope_loaders = self._get_scope_loaders()
81 rightmost_scope_loader = scope_loaders[0]
82 for loader
in scope_loaders[1:]:
83 if loader.globalRect.x > rightmost_scope_loader.globalRect.x:
84 rightmost_scope_loader = loader
85 return rightmost_scope_loader.scopeId
87 def test_open_scope_to_the_left(self):
88 rightmost_scope = self._get_rightmost_scope_id()
89 self.dash.open_scope(rightmost_scope)
91 scope_id = self._get_leftmost_scope_id()
92 scope = self.dash.open_scope(scope_id)
93 self._assert_scope_is_opened(scope, scope_id)
95 def test_open_generic_scope(self):
96 scope_id =
'musicaggregator'
97 scope = self.dash.open_scope(scope_id)
98 self._assert_scope_is_opened(scope, scope_id)
99 self.assertIsInstance(scope, dash_emulators.GenericScopeView)
101 def test_open_applications_scope(self):
102 scope_id =
'clickscope'
103 scope = self.dash.open_scope(scope_id)
104 self._assert_scope_is_opened(scope, scope_id)
105 self.assertIsInstance(scope, dash_emulators.GenericScopeView)
108 class GenericScopeViewEmulatorTestCase(tests.DashBaseTestCase):
112 self.useFixture(fixture_setup.FakeScopes())
114 self.generic_scope = self.dash.open_scope(
'MockScope1')
116 def test_open_preview(self):
117 preview = self.generic_scope.open_preview(
'0',
'Title.0.0')
118 self.assertIsInstance(preview, dash_emulators.Preview)
119 self.assertTrue(preview.isCurrent)
122 class DashAppsEmulatorTestCase(tests.DashBaseTestCase):
124 available_applications = [
125 'Title.2.0',
'Title.2.1',
'Title.2.2',
'Title.2.3',
'Title.2.4',
126 'Title.2.5',
'Title.2.6',
'Title.2.7',
'Title.2.8',
'Title.2.9',
127 'Title.2.10',
'Title.2.11',
'Title.2.12']
131 self.useFixture(fixture_setup.FakeScopes())
133 self.applications_scope = self.dash.open_scope(
'clickscope')
135 def test_get_applications_should_return_correct_applications(self):
137 category_element = self.applications_scope._get_category_element(
139 list_view = self.dash.get_scope(
'clickscope')\
140 .select_single(ListViewWithPageHeader)
141 expected_apps_count = self._get_number_of_application_slots(category)
142 expected_applications = self.available_applications[
143 :expected_apps_count]
144 x_center = list_view.globalRect.x + list_view.width / 2
145 y_center = list_view.globalRect.y + list_view.height / 2
147 category_element.y - list_view.height + category_element.height
149 list_view._slow_drag(x_center, x_center, y_center, y_center - y_diff)
150 applications = self.applications_scope.get_applications(category)
151 self.assertEqual(expected_applications, applications)
153 def _get_number_of_application_slots(self, category):
154 category_element = self.applications_scope._get_category_element(
156 cardgrid = category_element.select_single(
'CardGrid')
157 if (category_element.expanded):
158 return cardgrid.select_single(
'QQuickGridView').count
160 return cardgrid.collapsedRows \
161 * cardgrid.select_single(
'ResponsiveGridView').columns