@@ -17,23 +17,52 @@
1717# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818#
1919
20+"""Tests for the Dash autopilot emulators.
21+
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.
27+
28+"""
29+
30+import os
31+
2032import mock
2133
34+import fixtures
35+from testtools.matchers import Contains, HasLength
36+
2237from unity8 import process_helpers
2338from unity8.shell import emulators, tests
2439from unity8.shell.emulators import dash as dash_emulators
2540
2641
27−class DashEmulatorTestCase(tests.UnityTestCase):
42+class DashBaseTestCase(tests.UnityTestCase):
2843
2944 scenarios = tests._get_device_emulation_scenarios()
3045
3146 def setUp(self):
32− super(DashEmulatorTestCase, self).setUp()
47+ super(DashBaseTestCase, self).setUp()
48+ self._use_scope_fakes()
3349 unity_proxy = self.launch_unity()
3450 process_helpers.unlock_unity(unity_proxy)
3551 self.dash = self.main_window.get_dash()
3652
53+ def _use_scope_fakes(self):
54+ qml2_import_path = os.environ.get('QML2_IMPORT_PATH')
55+ mocks_path = os.path.join(
56+ os.getcwd(), '../..', 'builddir/tests/mocks')
57+ qml_import_path_with_scope_fakes = '{0}:{1}'.format(
58+ qml2_import_path, mocks_path)
59+ self.useFixture(fixtures.EnvironmentVariable(
60+ 'QML2_IMPORT_PATH',
61+ newvalue=qml_import_path_with_scope_fakes))
62+
63+
64+class DashEmulatorTestCase(DashBaseTestCase):
65+
3766 def test_open_unexisting_scope(self):
3867 scope_name = 'unexisting'
3968 with mock.patch.object(self.dash, 'pointing_device') as mock_pointer:
@@ -120,15 +149,15 @@ class DashEmulatorTestCase(tests.UnityTestCase):
120149 self.assertIsInstance(scope, dash_emulators.DashApps)
121150
122151
123−class DashAppsEmulatorTestCase(tests.UnityTestCase):
124−
125− scenarios = tests._get_device_emulation_scenarios()
152+class DashAppsEmulatorTestCase(DashBaseTestCase):
126153
154+ available_applications = [
155+ 'Title.1', 'Title.21', 'Title.41', 'Title.61', 'Title.81',
156+ 'Title.101', 'Title.121', 'Title.141', 'Title.161', 'Title.181',
157+ 'Title.201', 'Title.221', 'Title.241', 'Title.261', 'Title.281',]
158+
127159 def setUp(self):
128160 super(DashAppsEmulatorTestCase, self).setUp()
129− unity_proxy = self.launch_unity()
130− process_helpers.unlock_unity(unity_proxy)
131− self.dash = self.main_window.get_dash()
132161 self.applications_scope = self.dash.open_scope('applications')
133162
134163 def test_get_applications_with_unexisting_category(self):
@@ -141,11 +170,19 @@ class DashAppsEmulatorTestCase(tests.UnityTestCase):
141170 'No category found with name unexisting category', str(exception))
142171
143172 def test_get_applications_should_return_list_with_names(self):
144− # FIXME The installed category comes from the scope click. This is the
145− # wrong way to test this emulator, because it shouldn't depend on the
146− # current implementation of the click scope. There can be many other
147− # scopes using DashApps as a base. In addition to this, we can't
148− # actually check the values returned, as they depend on the server that
149− # the click scope uses. What we need is to open a scope with hardcoded
150− # categories and values.
151− applications = self.applications_scope.get_applications('installed')
173+ category = 'installed'
174+ expected_apps_count = self._get_number_of_application_slots(category)
175+ expected_applications = self.available_applications[
176+ :expected_apps_count]
177+
178+ applications = self.applications_scope.get_applications(category)
179+
180+ self.assertThat(applications, HasLength(expected_apps_count))
181+ for expected in expected_applications:
182+ self.assertThat(applications, Contains(expected))
183+
184+ def _get_number_of_application_slots(self, category):
185+ category_element = self.applications_scope._get_category_element(
186+ category)
187+ grid = category_element.select_single('GenericFilterGrid')
188+ return grid.columns * grid.rows