File: tst_pagestack.13.qml

package info (click to toggle)
lomiri-ui-toolkit 1.3.5010%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 25,900 kB
  • sloc: cpp: 85,772; python: 5,528; sh: 1,364; javascript: 919; ansic: 573; makefile: 204
file content (214 lines) | stat: -rw-r--r-- 7,822 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * Copyright 2016 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.4
import Lomiri.Components 1.3
import Lomiri.Test 1.3

Item {
    width: units.gu(50)
    height: units.gu(80)

    MainView {
        id: mainView
        anchors.fill: parent
        PageStack {
            id: pageStack
            Page {
                id: pageInStack
            }
        }

        Column {
            // for manual testing
            visible: pageStack.depth === 0
            anchors {
                left: parent.left
                right: parent.right
                top: parent.top
                margins: units.gu(1)
            }
            Button {
                text: "page1"
                onClicked: pageStack.push(page1)
            }
            Button {
                text: "page2"
                onClicked: pageStack.push(page2)
            }
            Button {
                text: "pageWithPage"
                onClicked: pageStack.push(pageWithPage)
            }
            Button {
                text: "pageComponent"
                onClicked: pageStack.push(pageComponent)
            }
        }
    }
    Page {
        id: page1
        header: PageHeader {
            title: "Title 1"
        }
    }
    Page {
        id: page2
        header: PageHeader {
            title: "Title 2"
        }
    }
    Page {
        id: pageWithPage
        header: PageHeader {
            title: "Outer"
        }
        Page {
            header: PageHeader {
                title: "Inner"
            }
        }
    }

    Component {
        id: pageComponent
        Page {
            header: PageHeader {
                title: "Page from component"
            }
        }
    }

    LomiriTestCase {
        name: "PageStackAPI"
        when: windowShown
        id: testCase

        function initTestCase() {
            waitForHeaderAnimation(mainView);
            compare(pageStack.currentPage, null, "is not set by default");
            compare(pageStack.__propagated, mainView.__propagated, "propagated property of pageStack equals mainView.__propagated")
            compare(mainView.__propagated.header.title, "", "empty title by default");
        }

        function cleanup() {
            pageStack.clear();
            waitForHeaderAnimation(mainView);
            compare(pageStack.depth, 0, "depth is not 0 after clearing.");
            compare(pageStack.currentPage, null, "currentPage is not null after clearing.");
        }

        function test_depth() {
            compare(pageStack.depth, 0, "depth is 0 by default");
            pageStack.push(page1);
            waitForHeaderAnimation(mainView);
            compare(pageStack.depth, 1, "depth is correctly increased when pushing a page");
            pageStack.push(page2);
            waitForHeaderAnimation(mainView);
            compare(pageStack.depth, 2, "depth is correctly updated when pushing a page");
            pageStack.pop();
            waitForHeaderAnimation(mainView);
            compare(pageStack.depth, 1, "depth is correctly decreased when popping a page");
        }

        function test_currentPage() {
            compare(pageStack.currentPage, null, "currentPage is null by default");
            pageStack.push(page1);
            waitForHeaderAnimation(mainView);
            compare(pageStack.currentPage, page1, "currentPage properly updated");
        }

        function test_page_order() {
            compare(pageStack.depth, 0, "depth is 0 initially");
            pageStack.push(page1);
            pageStack.push(page2);
            waitForHeaderAnimation(mainView);
            compare(pageStack.currentPage, page2, "last pushed page is on top");
            pageStack.pop();
            waitForHeaderAnimation(mainView);
            compare(pageStack.currentPage, page1, "popping puts previously pushed page on top");
        }

        function test_multipop_bug1461729() {
            for (var i=0; i < 10; i++) {
                pageStack.push(pageComponent);
            }
            waitForHeaderAnimation(mainView);
            compare(pageStack.depth, 10, "couldn't push 10 new pages");
            // When updating depth after animating out the header, depth
            // is not reliable to be used to guard a loop:
            while(pageStack.depth > 1) {
                pageStack.pop();
            }
            waitForHeaderAnimation(mainView);
            compare(pageStack.depth, 1, "popping until one page is left failed. " +
                    pageStack.depth + " pages left on stack");
        }

        function test_active_bug1260116() {
            pageStack.push(page1);
            waitForHeaderAnimation(mainView);

            compare(page1.active, true, "Page is active after pushing");
            pageStack.push(page2);
            waitForHeaderAnimation(mainView);

            compare(page1.active, false, "Page no longer active after pushing a new page");
            compare(page2.active, true, "New page is active after pushing");
            pageStack.pop();
            waitForHeaderAnimation(mainView);
            compare(page1.active, true, "Page re-activated when on top of the stack");
            compare(page2.active, false, "Page no longer active after being popped");
            pageStack.clear();
            waitForHeaderAnimation(mainView);

            compare(pageInStack.active, false, "Page defined inside PageStack is not active by default");
            pageStack.push(pageInStack);
            waitForHeaderAnimation(mainView);
            compare(pageInStack.active, true, "Pushing a page on PageStack makes it active");
            pageStack.pop();
            waitForHeaderAnimation(mainView);
            compare(pageInStack.active, false, "Popping a page from PageStack makes it inactive");
        }

        function test_push_return_values() {
            var pushedPage = pageStack.push(page1);
            compare(pushedPage, page1,
                    "PageStack.push() returns pushed Page");
            pushedPage = pageStack.push(pageComponent);
            compare(pushedPage.header.title, "Page from component",
                    "PageStack.push() returns Page created from Component");
            pushedPage = pageStack.push(Qt.resolvedUrl("MyExternalPageWithNewHeader.qml"));
            compare(pushedPage.header.title, "Page from QML file",
                    "PageStack.push() returns Page created from QML file");
        }

        function test_page_header_back_button_bug1565811() {
            pageStack.push(page2);
            var backButton = findChild(page2.header.leadingActionBar,
                                       "pagestack_back_action_button");
            compare(backButton, null,
                    "Page header shows back button with only one page on the stack.");
            pageStack.pop();
            pageStack.push(page1);
            pageStack.push(page2);
            waitForHeaderAnimation(mainView);
            backButton = findChild(page2.header, "pagestack_back_action_button");
            compare(backButton && backButton.visible, true,
                    "Page header has no back button with two pages on the stack.");
        }
    }
}