~zsombi/ubuntu-ui-toolkit/listitemSelectModeBugs

« back to all changes in this revision

Viewing changes to tests/unit_x11/tst_components/tst_page_with_header.qml

  • Committer: Zsombor Egri
  • Date: 2015-11-16 06:35:05 UTC
  • mfrom: (1664.1.1 listitemSelectModeBugs)
  • Revision ID: zsombor.egri@canonical.com-20151116063505-cwn2qfks7qzk10g9
re-sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2015 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.4
 
18
import Ubuntu.Components 1.3
 
19
import Ubuntu.Test 1.0
 
20
 
 
21
MainView {
 
22
    width: units.gu(50)
 
23
    height: units.gu(70)
 
24
    id: root
 
25
 
 
26
    Item {
 
27
        id: invisible
 
28
        visible: false
 
29
 
 
30
        Rectangle {
 
31
            objectName: "my_rectangle"
 
32
            id: myRectangle
 
33
            anchors {
 
34
                left: parent.left
 
35
                right: parent.right
 
36
            }
 
37
            height: units.gu(6)
 
38
            color: UbuntuColors.red
 
39
        }
 
40
 
 
41
        PageHeader {
 
42
            id: myPageHeader
 
43
            objectName: "my_page_header"
 
44
            title: "Page header"
 
45
            trailingActionBar.actions: [
 
46
                Action {
 
47
                    iconName: "settings"
 
48
                    text: "First"
 
49
                },
 
50
                Action {
 
51
                    iconName: "info"
 
52
                    text: "Second"
 
53
                }
 
54
            ]
 
55
        }
 
56
    }
 
57
 
 
58
    Page {
 
59
        id: page
 
60
        title: "Page with header"
 
61
        header: myPageHeader
 
62
 
 
63
        Column {
 
64
            anchors {
 
65
                left: parent.left
 
66
                right: parent.right
 
67
                top: parent.top
 
68
                topMargin: units.gu(10)
 
69
                leftMargin: units.gu(10)
 
70
                rightMargin: units.gu(10)
 
71
            }
 
72
            height: childrenRect.height
 
73
 
 
74
            Button {
 
75
                anchors {
 
76
                    left: parent.left
 
77
                    right: parent.right
 
78
                }
 
79
                text: "Page header"
 
80
                onClicked: page.header = myPageHeader
 
81
            }
 
82
            Button {
 
83
                anchors {
 
84
                    left: parent.left
 
85
                    right: parent.right
 
86
                }
 
87
                text: "Rectangle"
 
88
                onClicked: page.header = myRectangle
 
89
            }
 
90
            Button {
 
91
                anchors {
 
92
                    left: parent.left
 
93
                    right: parent.right
 
94
                }
 
95
                text: "Null"
 
96
                onClicked: page.header = null
 
97
            }
 
98
        }
 
99
    }
 
100
 
 
101
    UbuntuTestCase {
 
102
        name: "PageWithHeader"
 
103
        when: windowShown
 
104
        id: testCase
 
105
 
 
106
        property var appHeader;
 
107
        function initTestCase() {
 
108
            var pageHeader = findChild(page, "my_page_header");
 
109
            compare(pageHeader, myPageHeader,
 
110
                    "My PageHeader not initialized with Page as its parent.");
 
111
            appHeader = findChild(root, "MainView_Header");
 
112
            compare(appHeader.visible, false,
 
113
                    "AppHeader is not hidden initially when Page.header is set.");
 
114
        }
 
115
 
 
116
        function cleanup() {
 
117
            page.header = myPageHeader;
 
118
            var pageHeader = findChild(page, "my_page_header");
 
119
            compare(pageHeader, myPageHeader,
 
120
                    "PageHeader is not correctly re-parented to the Page when setting Page.header.");
 
121
            compare(myPageHeader.visible, true,
 
122
                    "PageHeader is not visible after being re-parented to the Page.");
 
123
            compare(appHeader.visible, false,
 
124
                    "AppHeader is not hidden when Page.header is set.");
 
125
        }
 
126
 
 
127
        function test_page_with_no_header() {
 
128
            page.header = null;
 
129
            compare(myPageHeader.parent, invisible,
 
130
                    "Header parent is not correctly reverted when unsetting Page.header.");
 
131
            compare(myPageHeader.visible, false,
 
132
                    "My PageHeader is still visible after re-parenting it to an invisible Item.");
 
133
            compare(appHeader.visible, true,
 
134
                    "AppHeader does not become visible when Page.header is null.");
 
135
        }
 
136
 
 
137
        function test_page_with_alternative_header() {
 
138
            page.header = myRectangle;
 
139
            compare(myPageHeader.parent, invisible,
 
140
                    "Header parent not correctly reverted when setting a different Page.header.");
 
141
            compare(myRectangle.parent, page,
 
142
                    "Rectangle parent is not correctly set to page after setting it as Page.header.");
 
143
            compare(appHeader.visible, false,
 
144
                    "Setting a different Page.header Item shows the AppHeader.");
 
145
 
 
146
            page.header = myPageHeader;
 
147
            compare(myRectangle.parent, invisible,
 
148
                    "Rectangle parent is not correctly reverted after unsetting it as Page.header.");
 
149
            // myPageHeader parent is checked in cleanup().
 
150
        }
 
151
    }
 
152
}