@@ -17,23 +17,43 @@
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+import sysconfig
32+
2033import mock
2134
35+import fixtures
36+from testtools.matchers import Contains, HasLength
37+
38+import unity8
2239from unity8 import process_helpers
2340from unity8.shell import emulators, tests
2441from unity8.shell.emulators import dash as dash_emulators
2542
2643
27−class DashEmulatorTestCase(tests.UnityTestCase):
44+class DashBaseTestCase(tests.UnityTestCase):
2845
2946 scenarios = tests._get_device_emulation_scenarios()
3047
3148 def setUp(self):
32− super(DashEmulatorTestCase, self).setUp()
49+ super(DashBaseTestCase, self).setUp()
3350 unity_proxy = self.launch_unity()
3451 process_helpers.unlock_unity(unity_proxy)
3552 self.dash = self.main_window.get_dash()
3653
54+
55+class DashEmulatorTestCase(DashBaseTestCase):
56+
3757 def test_open_unexisting_scope(self):
3858 scope_name = 'unexisting'
3959 with mock.patch.object(self.dash, 'pointing_device') as mock_pointer:
@@ -118,3 +138,70 @@ class DashEmulatorTestCase(tests.UnityTestCase):
118138 scope = self.dash.open_scope(self._get_scope_name_from_id(scope_id))
119139 self._assert_scope_is_opened(scope, scope_id)
120140 self.assertIsInstance(scope, dash_emulators.DashApps)
141+
142+
143+class DashAppsEmulatorTestCase(DashBaseTestCase):
144+
145+ available_applications = [
146+ 'Title.1', 'Title.21', 'Title.41', 'Title.61', 'Title.81',
147+ 'Title.101', 'Title.121', 'Title.141', 'Title.161', 'Title.181',
148+ 'Title.201', 'Title.221', 'Title.241', 'Title.261', 'Title.281']
149+
150+ def setUp(self):
151+ self._use_scope_fakes()
152+ super(DashAppsEmulatorTestCase, self).setUp()
153+ self.applications_scope = self.dash.open_scope('applications')
154+
155+ def _use_scope_fakes(self):
156+ self.useFixture(
157+ fixtures.EnvironmentVariable(
158+ 'QML2_IMPORT_PATH',
159+ newvalue=self._get_fake_scopes_library_path()))
160+
161+ def _get_fake_scopes_library_path(self):
162+ if unity8.running_installed_tests():
163+ mock_path = 'qml/scopefakes/'
164+ else:
165+ mock_path = os.path.join(
166+ '../lib/', sysconfig.get_config_var('MULTIARCH'),
167+ 'unity8/qml/scopefakes/')
168+ lib_path = unity8.get_lib_path()
169+ ld_library_path = os.path.abspath(os.path.join(lib_path, mock_path))
170+
171+ if not os.path.exists(ld_library_path):
172+ raise RuntimeError(
173+ 'Expected library path does not exists: %s.' % (
174+ ld_library_path))
175+ return ld_library_path
176+
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')
182+
183+ self.assertEqual(
184+ 'No category found with name unexisting category', str(exception))
185+
186+ def test_get_applications_should_return_list_with_names(self):
187+ category = 'installed'
188+ expected_apps_count = self._get_number_of_application_slots(category)
189+ expected_applications = self.available_applications[
190+ :expected_apps_count]
191+
192+ applications = self.applications_scope.get_applications(category)
193+
194+ self.assertThat(applications, HasLength(expected_apps_count))
195+ for expected in expected_applications:
196+ self.assertThat(applications, Contains(expected))
197+
198+ def _get_number_of_application_slots(self, category):
199+ category_element = self.applications_scope._get_category_element(
200+ category)
201+ grid = category_element.select_single('GenericFilterGrid')
202+ return grid.columns * grid.rows
203+
204+ def test_open_preview(self):
205+ preview = self.applications_scope.open_preview('installed', 'Title.1')
206+ self.assertIsInstance(preview, dash_emulators.AppPreview)
207+ self.assertTrue(preview.isCurrent)