on a46efde help sign in
unity8/tests/plugins/Dash/tst_ListViewWithPageHeaderQML.qml
140 lines 4.1 kB history raw
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 */
17import QtQuick 2.4
18import QtTest 1.0
19import Dash 0.1
21Rectangle {
22 width: 300
23 height: 542
24 color: "lightblue"
26 ListModel {
27 id: model
29 function insertItem(index, size, type) {
30 insert(index, { size: size, type: type });
31 }
33 function removeItems(index, count) {
34 remove(index, count);
35 }
37 function moveItems(indexFrom, indexTo, count) {
38 move(indexFrom, indexTo, count);
39 }
41 ListElement { type: "Agressive"; size: 150 }
42 ListElement { type: "Regular"; size: 200 }
43 ListElement { type: "Mild"; size: 350 }
44 ListElement { type: "Bold"; size: 350 }
45 ListElement { type: "Bold"; size: 350 }
46 ListElement { type: "Lazy"; size: 350 }
47 }
49 ListViewWithPageHeader {
50 id: listView
51 width: parent.width
52 anchors.top: parent.top
53 anchors.bottom: parent.bottom
54 model: model
55 delegate: Rectangle {
56 property bool timerDone: false
57 width: parent.width - 20
58 x: 10
59 color: index % 2 == 0 ? "red" : "blue"
60 height: size
61 Text {
62 text: index
63 }
64 }
66 pageHeader: Rectangle {
67 color: "transparent"
68 width: parent.width
69 height: 50
70 implicitHeight: 50
71 Text {
72 anchors.fill: parent
73 text: "APPS"
74 font.pixelSize: 40
75 }
76 }
78 sectionProperty: "type"
80 property int sectionHeaderHeight: 40
81 sectionDelegate: Component {
82 id: sectionHeaderComponent
83 Rectangle {
84 property alias text: theText.text
85 color: "green"
86 height: listView.sectionHeaderHeight
87 Text { id: theText; font.pixelSize: 34 }
88 anchors { left: parent.left; right: parent.right }
89 }
90 }
91 }
93 Component {
94 id: otherSectionHeaderComponent
95 Rectangle {
96 property alias text: theText.text
97 color: "green"
98 height: 50
99 Text { id: theText; font.pixelSize: 34 }
100 anchors { left: parent.left; right: parent.right }
101 }
102 }
104 SignalSpy {
105 id: stickyHeaderHeigthSpy
106 target: listView
107 signalName: "stickyHeaderHeightChanged"
108 }
110 TestCase {
111 name: "ListViewWithPageHeaderTest"
112 when: windowShown
114 function test_stickyHeaderHeightNewHeader() {
115 stickyHeaderHeigthSpy.clear();
116 compare(listView.stickyHeaderHeight, 40);
118 listView.sectionDelegate = otherSectionHeaderComponent;
119 compare(listView.stickyHeaderHeight, 50);
120 compare(stickyHeaderHeigthSpy.count, 1);
122 listView.sectionDelegate = sectionHeaderComponent;
123 compare(listView.stickyHeaderHeight, 40);
124 compare(stickyHeaderHeigthSpy.count, 2);
125 }
127 function test_stickyHeaderHeightGrowingHeader() {
128 stickyHeaderHeigthSpy.clear();
130 compare(listView.stickyHeaderHeight, 40);
132 listView.sectionHeaderHeight = 60;
133 compare(listView.stickyHeaderHeight, 60);
134 compare(stickyHeaderHeigthSpy.count, 1);
136 // Restore height for other tests
137 listView.sectionHeaderHeight = 40;
138 }
139 }