on xenial help sign in
Some simplification in DashContent

* Kill the ScopeDelegateMapper in favour of a simple if (that will eventually go away) * Removal of all the fake scopes in the tests that added nothing of value to the tests * Removal of movementEnded signal that was unused * Removal of movementStarted and positionedAtBeginning signals that were being used as function calls * Rework DashContent tests so they what the function does what it is supposed to do instead of just making sure QML signals work

commit518e3e1b8c46fe4c01a3e655454d0ee4bc6bee22 authorAlbert Astals <albert.astals@canonical.com> dateMon 14 Apr 2014, 15:21 (13 years ago) parent9c61eb8
11 files changed+39−272
qml/Dash/DashContent.qml+5−10 qml/Dash/GenericScopeView.qml+8−7 qml/Dash/ScopeDelegateMapper.qml−30 tests/qmltests/Dash/qml/FakeScopeView.qml−45 tests/qmltests/Dash/qml/fake_generic_scopeView.qml−24 tests/qmltests/Dash/qml/fake_scopeView1.qml−24 tests/qmltests/Dash/qml/fake_scopeView2.qml−24 tests/qmltests/Dash/qml/fake_scopeView3.qml−24 tests/qmltests/Dash/qml/fake_scopeView4.qml−24 tests/qmltests/Dash/tst_Dash.qml−11 tests/qmltests/Dash/tst_DashContent.qml+26−49
qml/Dash/DashContent.qml+5−10
@@ -27,13 +27,9 @@ Item {
2727 readonly property alias currentIndex: dashContentList.currentIndex
2828 property alias previewOpen: previewListView.open
2929
30− property ScopeDelegateMapper scopeMapper : ScopeDelegateMapper {}
3130 property ListModel searchHistory
3231
33− signal movementStarted()
34− signal movementEnded()
3532 signal scopeLoaded(string scopeId)
36− signal positionedAtBeginning()
3733 signal gotoScope(string scopeId)
3834 signal openScope(var scope)
3935
@@ -71,7 +67,7 @@ Item {
7167 dashContentList.currentIndex = index
7268
7369 if (reset) {
74− dashContent.positionedAtBeginning()
70+ dashContentList.currentItem.item.positionAtBeginning()
7571 }
7672 }
7773
@@ -114,8 +110,7 @@ Item {
114110 highlightRangeMode: ListView.StrictlyEnforceRange
115111 // TODO Investigate if we can switch to a smaller cache buffer when/if UbuntuShape gets more performant
116112 cacheBuffer: 1073741823
117− onMovementStarted: dashContent.movementStarted()
118− onMovementEnded: dashContent.movementEnded()
113+ onMovementStarted: currentItem.item.showHeader();
119114 clip: parent.x != 0
120115
121116 // If the number of items is less than the current index, then need to reset to another item.
@@ -135,7 +130,9 @@ Item {
135130 width: ListView.view.width
136131 height: ListView.view.height
137132 asynchronous: true
138− source: scopeMapper.map(scope.id)
133+ // TODO This if will eventually go away since we're killing DashApps.qml
134+ // once we move app closing to the spread
135+ source: (scope.id == "clickscope") ? "DashApps.qml" : "GenericScopeView.qml"
139136 objectName: scope.id + " loader"
140137
141138 readonly property bool moving: item ? item.moving : false
@@ -154,8 +151,6 @@ Item {
154151 item.scope = Qt.binding(function() { return scope })
155152 item.isCurrent = Qt.binding(function() { return visible && ListView.isCurrentItem })
156153 item.tabBarHeight = dashPageHeader.implicitHeight;
157− dashContentList.movementStarted.connect(item.movementStarted)
158− dashContent.positionedAtBeginning.connect(item.positionedAtBeginning)
159154 dashContent.scopeLoaded(item.scope.id)
160155 }
161156 Connections {
qml/Dash/GenericScopeView.qml+8−7
@@ -33,9 +33,6 @@ FocusScope {
3333 property PageHeader pageHeader: null
3434 property Item previewListView: null
3535
36− signal movementStarted
37− signal positionedAtBeginning
38−
3936 property bool enableHeightBehaviorOnNextCreation: false
4037 property var categoryView: categoryView
4138
@@ -49,6 +46,14 @@ FocusScope {
4946 shell.activateApplication(appId);
5047 }
5148
49+ function positionAtBeginning() {
50+ categoryView.positionAtBeginning()
51+ }
52+
53+ function showHeader() {
54+ categoryView.showHeader()
55+ }
56+
5257 Binding {
5358 target: scope
5459 property: "isActive"
@@ -69,10 +74,6 @@ FocusScope {
6974 previewListView.open = false;
7075 }
7176
72− onMovementStarted: categoryView.showHeader()
73−
74− onPositionedAtBeginning: categoryView.positionAtBeginning()
75−
7677 Binding {
7778 target: scopeView.scope
7879 property: "searchQuery"
qml/Dash/ScopeDelegateMapper.qmldeleted−30
@@ -1,30 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−
19−QtObject {
20− property var scopeDelegateMapping: {"clickscope": "DashApps.qml"}
21− property string genericScope: "GenericScopeView.qml"
22−
23− function map(scopeId) {
24− var customScope = scopeDelegateMapping[scopeId]
25− if (customScope != undefined) {
26− return customScope
27− }
28− return genericScope
29− }
30−}
tests/qmltests/Dash/qml/FakeScopeView.qmldeleted−45
@@ -1,45 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−import Unity 0.2
19−
20−import "../../../../qml/Dash"
21−
22−GenericScopeView {
23− id: fakeScopeView
24−
25− property alias backColor : back.color
26− property var categoryView: null
27−
28− onMovementStarted: {
29− if (shell != undefined && shell.scopeStatus != undefined) {
30− shell.scopeStatus[scope.id].movementStarted++;
31− }
32− }
33− onPositionedAtBeginning: {
34− if (shell != undefined && shell.scopeStatus != undefined) {
35− shell.scopeStatus[scope.id].positionedAtBeginning++;
36− }
37− }
38−
39− Rectangle {
40− id: back
41− anchors.fill: parent
42− color: "grey"
43− z: -1
44− }
45−}
tests/qmltests/Dash/qml/fake_generic_scopeView.qmldeleted−24
@@ -1,24 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−
19−FakeScopeView {
20− id: fake_generic_scopeView
21− objectName: "fake_generic_scopeView"
22−
23− backColor: "#D0D0D0"
24−}
tests/qmltests/Dash/qml/fake_scopeView1.qmldeleted−24
@@ -1,24 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−
19−FakeScopeView {
20− id: fake_scopeView1
21− objectName: "fake_scopeView1"
22−
23− backColor: "#90E090"
24−}
tests/qmltests/Dash/qml/fake_scopeView2.qmldeleted−24
@@ -1,24 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−
19−FakeScopeView {
20− id: fake_scopeView2
21− objectName: "fake_scopeView2"
22−
23− backColor: "#A0D0A0"
24−}
tests/qmltests/Dash/qml/fake_scopeView3.qmldeleted−24
@@ -1,24 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−
19−FakeScopeView {
20− id: fake_scopeView3
21− objectName: "fake_scopeView3"
22−
23− backColor: "#B0C0B0"
24−}
tests/qmltests/Dash/qml/fake_scopeView4.qmldeleted−24
@@ -1,24 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−
19−FakeScopeView {
20− id: fake_scopeView4
21− objectName: "fake_scopeView4"
22−
23− backColor: "#C0C0C0"
24−}
tests/qmltests/Dash/tst_Dash.qml−11
@@ -41,16 +41,6 @@ Item {
4141 showScopeOnLoaded: "MockScope2"
4242 }
4343
44− ScopeDelegateMapper {
45− id: scopeDelegateMapper
46− scopeDelegateMapping: {
47− "MockScope1": Qt.resolvedUrl("qml/fake_scopeView1.qml"),
48− "MockScope2": Qt.resolvedUrl("qml/fake_scopeView2.qml"),
49− "clickscope": Qt.resolvedUrl("qml/fake_scopeView3.qml")
50− }
51− genericScope: Qt.resolvedUrl("qml/fake_generic_scopeView.qml")
52− }
53−
5444 UT.UnityTestCase {
5545 name: "Dash"
5646 when: windowShown
@@ -59,7 +49,6 @@ Item {
5949
6050 Component.onCompleted: {
6151 var dashContent = findChild(dash, "dashContent");
62− dashContent.scopeMapper = scopeDelegateMapper;
6352 scopes = dashContent.scopes;
6453 }
6554
tests/qmltests/Dash/tst_DashContent.qml+26−49
@@ -35,13 +35,6 @@ Item {
3535 property var panel: null
3636 // BEGIN To reduce warnings
3737
38− property var scopeStatus: {
39− 'MockScope1': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
40− 'MockScope2': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
41− 'clickscope': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
42− 'MockScope5': { 'movementStarted': 0, 'positionedAtBeginning': 0 }
43− }
44−
4538 Scopes {
4639 id: scopesModel
4740 }
@@ -55,34 +48,9 @@ Item {
5548 }
5649 scopes : scopesModel
5750
58− scopeMapper : scopeDelegateMapper
5951 searchHistory: SearchHistoryModel {}
6052 }
6153
62− ScopeDelegateMapper {
63− id: scopeDelegateMapper
64− scopeDelegateMapping: {
65− "MockScope1": Qt.resolvedUrl("qml/fake_scopeView1.qml"),
66− "MockScope2": Qt.resolvedUrl("qml/fake_scopeView2.qml"),
67− "clickscope": Qt.resolvedUrl("qml/fake_scopeView3.qml"),
68− }
69− genericScope: Qt.resolvedUrl("qml/fake_generic_scopeView.qml")
70− }
71−
72− function clear_scope_status() {
73− scopeStatus["MockScope1"].movementStarted = 0;
74− scopeStatus["MockScope1"].positionedAtBeginning = 0;
75−
76− scopeStatus["MockScope2"].movementStarted = 0;
77− scopeStatus["MockScope2"].positionedAtBeginning = 0;
78−
79− scopeStatus["clickscope"].movementStarted = 0;
80− scopeStatus["clickscope"].positionedAtBeginning = 0;
81−
82− scopeStatus["MockScope5"].movementStarted = 0;
83− scopeStatus["MockScope5"].positionedAtBeginning = 0;
84− }
85−
8654 SignalSpy {
8755 id: scopeLoadedSpy
8856 target: dashContent
@@ -96,6 +64,7 @@ Item {
9664 }
9765
9866 UT.UnityTestCase {
67+ id: testCase
9968 name: "DashContent"
10069 when: scopesModel.loaded
10170
@@ -108,7 +77,6 @@ Item {
10877
10978 function cleanup() {
11079 movementStartedSpy.clear();
111− clear_scope_status();
11280 dashContent.visible = true;
11381
11482 var dashContentList = findChild(dashContent, "dashContentList");
@@ -149,29 +117,38 @@ Item {
149117 verify(dashContentList.currentIndex >= 0 && dashContentList.currentIndex < 5);
150118 }
151119
152− function test_movement_started_signal() {
153− dashContent.setCurrentScopeAtIndex(3, true, false);
154−
120+ function test_show_header_on_list_movement() {
155121 var dashContentList = findChild(dashContent, "dashContentList");
156122 verify(dashContentList != undefined)
123+ var categoryListView = findChild(dashContentList, "categoryListView");
124+ verify(categoryListView != undefined)
125+
126+ waitForRendering(categoryListView);
157127
158− dashContentList.movementStarted();
128+ categoryListView.contentY = units.gu(11);
129+ console.log("contentY", categoryListView.contentY);
159130
160− compare(movementStartedSpy.count, 1, "DashContent should have emitted movementStarted signal when content list did.");
161− compare(scopeStatus["MockScope1"].movementStarted, 1, "MockScope1 should have emitted movementStarted signal when content list did.");
162− compare(scopeStatus["MockScope2"].movementStarted, 1, "MockScope2 should have emitted movementStarted signal when content list did.");
163− compare(scopeStatus["clickscope"].movementStarted, 1, "clickscope should have emitted movementStarted signal when content list did.");
164− compare(scopeStatus["MockScope5"].movementStarted, 1, "MockScope5 should have emitted movementStarted signal when content list did.");
131+ var startX = dashContentList.width/2;
132+ var startY = dashContentList.height/2;
133+ touchFlick(dashContentList, startX - units.gu(2), startY, startX, startY);
134+ tryCompare(categoryListView, "contentY", units.gu(11) - categoryListView.pageHeader.height)
165135 }
166136
167− function test_positioned_at_beginning_signal() {
168− dashContent.setCurrentScopeAtIndex(3, true, false);
137+ function test_set_current_scope_reset() {
138+ var dashContentList = findChild(dashContent, "dashContentList");
139+ verify(dashContentList != undefined)
140+ var categoryListView = findChild(dashContentList, "categoryListView");
141+ verify(categoryListView != undefined)
142+
143+ categoryListView.contentY = units.gu(10);
144+
145+ compare(dashContentList.currentItem.item.objectName, "MockScope1")
146+ compare(categoryListView.contentY, units.gu(10))
147+
148+ dashContent.setCurrentScopeAtIndex(0, false, true);
169149
170− dashContent.positionedAtBeginning();
171− compare(scopeStatus["MockScope1"].positionedAtBeginning, 1, "MockScope1 should have emitted positionedAtBeginning signal when DashContent did.");
172− compare(scopeStatus["MockScope2"].positionedAtBeginning, 1, "MockScope2 should have emitted positionedAtBeginning signal when DashContent did.");
173− compare(scopeStatus["clickscope"].positionedAtBeginning, 1, "clickscope should have emitted positionedAtBeginning signal when DashContent did.");
174− compare(scopeStatus["MockScope5"].positionedAtBeginning, 1, "MockScope5 should have emitted positionedAtBeginning signal when DashContent did.");
150+ compare(dashContentList.currentItem.item.objectName, "MockScope1")
151+ compare(categoryListView.contentY, 0)
175152 }
176153
177154 // This tests that setting the current scope index will end up at the correct index even if