on xenial help sign in
Test should not depend on ApplicationManager directly to mock it. Fixing tst_RunningApplicationsGrid.qml test which was failing
commit2bdbff7303b2df9cdebcbaec6a4dd3bc12d9ecf8 authorGerry Boland <gerry.boland@canonical.com> dateThu 5 Sep 2013, 19:06 (13 years ago) parent808e099
1 file changed+55−37
tests/qmltests/Dash/Apps/tst_RunningApplicationsGrid.qml+55−37
tests/qmltests/Dash/Apps/tst_RunningApplicationsGrid.qml+55−37
@@ -16,7 +16,6 @@
1616
1717import QtQuick 2.0
1818import QtTest 1.0
19−import Unity.Application 0.1
2019import "../../../../Dash/Apps"
2120import Unity.Test 0.1 as UT
2221
@@ -29,8 +28,12 @@ Item {
2928
3029 property bool sideStageEnabled: false
3130
32− function stopApplication(application) {
33− fakeRunningAppsModel.remove(application)
31+ function stopApplication(appId) {
32+ for (var i=0, len=fakeRunningAppsModel.count; i<len; i++) {
33+ if (appId == fakeRunningAppsModel.get(i).appId) {
34+ fakeRunningAppsModel.remove(i)
35+ }
36+ }
3437 }
3538 }
3639
@@ -40,47 +43,62 @@ Item {
4043 property bool stageScreenshotsReady: false
4144 property var applicationManager: fakeApplicationManager
4245
43− function activateApplication(desktopFile) {
46+ function activateApplication(appId) {
4447 }
4548 }
4649
47− ApplicationListModel { id: fakeRunningAppsModel }
48−
49− ApplicationInfo {
50− id: phoneApp
51− name: "Phone"
52− icon: "phone-app"
53− exec: "/usr/bin/phone-app"
54− stage: ApplicationInfo.MainStage
55− desktopFile: "phone.desktop"
56− imageQml: "import QtQuick 2.0\n" +
57− "Rectangle { \n" +
58− " anchors.fill:parent \n" +
59− " color:'darkgreen' \n" +
60− " Text { anchors.centerIn: parent; text: 'PHONE' } \n" +
61− "}"
50+ ListModel {
51+ id: fakeRunningAppsModel
52+
53+ function contains(appId) {
54+ for (var i=0, len=fakeRunningAppsModel.count; i<len; i++) {
55+ if (appId == fakeRunningAppsModel.get(i).appId) {
56+ return true;
57+ }
58+ }
59+ return false;
60+ }
61+
62+ function rePopulate() {
63+ for (var i=0, len=availableAppsModel.count; i<len; i++) {
64+ fakeRunningAppsModel.append(availableAppsModel.get(i));
65+ }
66+ }
6267 }
6368
64− ApplicationInfo {
65− id: calendarApp
66− name: "Calendar"
67− icon: "calendar-app"
68− exec: "/usr/bin/calendar-app"
69− stage: ApplicationInfo.MainStage
70− desktopFile: "calendar.desktop"
71− imageQml: "import QtQuick 2.0\n" +
72− "Rectangle { \n" +
73− " anchors.fill:parent \n" +
74− " color:'darkblue' \n" +
75− " Text { anchors.centerIn: parent; text: 'CALENDAR'\n" +
76− " color:'white'} \n" +
77− "}"
69+ ListModel {
70+ id: availableAppsModel
71+ ListElement {
72+ name: "Phone"
73+ icon: "phone-app"
74+ exec: "/usr/bin/phone-app"
75+ appId: "phone"
76+ imageQml: "import QtQuick 2.0\n \
77+ Rectangle { \n \
78+ anchors.fill:parent \n \
79+ color:'darkgreen' \n \
80+ Text { anchors.centerIn: parent; text: 'PHONE' } \n \
81+ }"
82+ }
83+
84+ ListElement {
85+ name: "Calendar"
86+ icon: "calendar-app"
87+ exec: "/usr/bin/calendar-app"
88+ appId: "calendar"
89+ imageQml: "import QtQuick 2.0\n \
90+ Rectangle { \n \
91+ anchors.fill:parent \n \
92+ color:'darkblue' \n \
93+ Text { anchors.centerIn: parent; text: 'CALENDAR'\n \
94+ color:'white'} \n \
95+ }"
96+ }
7897 }
7998
8099 function resetRunningApplications() {
81100 fakeRunningAppsModel.clear()
82− fakeRunningAppsModel.add(phoneApp)
83− fakeRunningAppsModel.add(calendarApp)
101+ fakeRunningAppsModel.rePopulate()
84102 }
85103
86104 Component.onCompleted: {
@@ -185,11 +203,11 @@ Item {
185203 var calendarTile = findChild(runningApplicationsGrid, "runningAppTile Calendar")
186204 verify(calendarTile != undefined)
187205
188− verify(fakeRunningAppsModel.contains(calendarApp))
206+ verify(fakeRunningAppsModel.contains("calendar"))
189207
190208 mouseClick(calendarTile, calendarTile.width/2, calendarTile.height/2)
191209
192− verify(!fakeRunningAppsModel.contains(calendarApp))
210+ verify(!fakeRunningAppsModel.contains("calendar"))
193211
194212 // The tile for the Calendar app should eventually vanish since the
195213 // application has been terminated