~ci-train-bot/ubuntu-settings-components/ubuntu-settings-components-ubuntu-zesty-2022

« back to all changes in this revision

Viewing changes to tests/qmltests/Menus/tst_BaseMenu.qml

  • Committer: Bileto Bot
  • Date: 2016-10-24 11:32:00 UTC
  • mfrom: (146.3.110 slots-layout)
  • Revision ID: ci-train-bot@canonical.com-20161024113200-85dvkl9m1o0msi5i
* Menus: rewrite components using ListItemLayout's and SlotsLayout's
* Bump revision to 0.10, as per Components removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2016 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
 * Authored by Marco Trevisan <marco.trevisan@canonical.com>
 
17
 */
 
18
 
 
19
import QtQuick 2.4
 
20
import QtTest 1.0
 
21
import Ubuntu.Test 0.1
 
22
import Ubuntu.Settings.Menus 0.1
 
23
 
 
24
Item {
 
25
    width: units.gu(42)
 
26
    height: units.gu(75)
 
27
 
 
28
    Column {
 
29
        anchors.fill: parent
 
30
 
 
31
        BaseMenu {
 
32
            id: baseMenu
 
33
        }
 
34
 
 
35
        BaseMenu {
 
36
            id: dividerMenu
 
37
            divider.visible: true
 
38
        }
 
39
 
 
40
        BaseMenu {
 
41
            id: legacyDividerMenu
 
42
            showDivider: true
 
43
        }
 
44
 
 
45
        BaseMenu {
 
46
            id: clickOverride
 
47
            property bool clicked: false
 
48
            function onClickedCallback() { clicked = true }
 
49
        }
 
50
 
 
51
        BaseMenu {
 
52
            id: removableMenu
 
53
            removable: true
 
54
        }
 
55
    }
 
56
 
 
57
    SignalSpy {
 
58
        id: signalSpy
 
59
    }
 
60
 
 
61
    UbuntuTestCase {
 
62
        name: "BaseMenu"
 
63
        when: windowShown
 
64
 
 
65
        function cleanup() {
 
66
            signalSpy.clear()
 
67
        }
 
68
 
 
69
        function test_dontHighlightWhenPressed() {
 
70
            baseMenu.highlightWhenPressed = false;
 
71
            mousePress(baseMenu, baseMenu.width/2, baseMenu.height/2)
 
72
            compare(Qt.colorEqual(baseMenu.highlightColor, baseMenu.backColor), true)
 
73
            mouseRelease(baseMenu)
 
74
        }
 
75
 
 
76
        function test_doHighlightWhenPressed() {
 
77
            baseMenu.highlightWhenPressed = true;
 
78
            mousePress(baseMenu, baseMenu.width/2, baseMenu.height/2)
 
79
            compare(Qt.colorEqual(baseMenu.highlightColor, theme.palette.highlighted.background), true)
 
80
            mouseRelease(baseMenu)
 
81
        }
 
82
 
 
83
        function test_showDivider() {
 
84
            compare(baseMenu.showDivider, false)
 
85
            compare(baseMenu.divider.visible, false)
 
86
 
 
87
            baseMenu.showDivider = true
 
88
            compare(baseMenu.showDivider, true)
 
89
            compare(baseMenu.divider.visible, true)
 
90
 
 
91
            baseMenu.showDivider = false
 
92
            compare(baseMenu.divider.visible, false)
 
93
            compare(baseMenu.showDivider, false)
 
94
        }
 
95
 
 
96
        function test_hideDivider() {
 
97
            compare(dividerMenu.showDivider, true)
 
98
            compare(dividerMenu.divider.visible, true)
 
99
 
 
100
            dividerMenu.showDivider = false
 
101
            compare(dividerMenu.showDivider, false)
 
102
            compare(dividerMenu.divider.visible, false)
 
103
 
 
104
            dividerMenu.showDivider = true
 
105
            compare(dividerMenu.divider.visible, true)
 
106
            compare(dividerMenu.showDivider, true)
 
107
        }
 
108
 
 
109
        function test_hideDividerLegacy() {
 
110
            legacyDividerMenu.showDivider = false
 
111
            compare(legacyDividerMenu.showDivider, false)
 
112
            compare(legacyDividerMenu.divider.visible, false)
 
113
 
 
114
            legacyDividerMenu.showDivider = true
 
115
            compare(legacyDividerMenu.divider.visible, true)
 
116
            compare(legacyDividerMenu.showDivider, true)
 
117
        }
 
118
 
 
119
        function test_clickEvent() {
 
120
            signalSpy.target = baseMenu
 
121
            signalSpy.signalName = "onClicked"
 
122
            mouseClick(baseMenu, baseMenu.width/2, baseMenu.height/2)
 
123
            compare(signalSpy.count, 1)
 
124
        }
 
125
 
 
126
        function test_disabledClickEvent() {
 
127
            signalSpy.target = baseMenu
 
128
            signalSpy.signalName = "onClicked"
 
129
            baseMenu.enabled = false
 
130
            mouseClick(baseMenu, baseMenu.width/2, baseMenu.height/2)
 
131
            compare(signalSpy.count, 0)
 
132
            baseMenu.enabled = true
 
133
        }
 
134
 
 
135
        function test_triggeredEvent() {
 
136
            signalSpy.target = baseMenu
 
137
            signalSpy.signalName = "onTriggered"
 
138
            mouseClick(baseMenu, baseMenu.width/2, baseMenu.height/2)
 
139
            compare(signalSpy.count, 1)
 
140
            compare(signalSpy.signalArguments[0][0], null)
 
141
        }
 
142
 
 
143
        function test_clickedSignalOverriding() {
 
144
            signalSpy.target = clickOverride
 
145
            signalSpy.signalName = "onTriggered"
 
146
            clickOverride.clicked = false
 
147
            mouseClick(clickOverride, clickOverride.width/2, baseMenu.height/2)
 
148
            compare(clickOverride.clicked, true)
 
149
            compare(signalSpy.count, 0)
 
150
        }
 
151
 
 
152
        function test_notRemovable() {
 
153
            compare(baseMenu.removable, false)
 
154
            compare(baseMenu.leadingActions, null)
 
155
            verify(findChild(baseMenu, "removeAction") === undefined)
 
156
        }
 
157
 
 
158
        function test_removable() {
 
159
            compare(removableMenu.removable, true)
 
160
            compare(removableMenu.leadingActions !== null, true)
 
161
            verify(findChild(baseMenu, "removeAction") === undefined)
 
162
        }
 
163
 
 
164
        function test_removal() {
 
165
            // test_removable()
 
166
            signalSpy.target = removableMenu
 
167
            signalSpy.signalName = "itemRemoved"
 
168
            mouseFlick(removableMenu,
 
169
                       removableMenu.width / 2,
 
170
                       removableMenu.height / 2,
 
171
                       removableMenu.width,
 
172
                       removableMenu.height / 2,
 
173
                       true, true, units.gu(1), 10);
 
174
 
 
175
            var removeAction = findChild(removableMenu, "removeAction");
 
176
            verify(removeAction !== undefined);
 
177
            tryCompare(removeAction, "visible", true)
 
178
            mouseClick(removeAction, removeAction.width/2, removeAction.height/2)
 
179
            tryCompare(signalSpy, "count", 1)
 
180
        }
 
181
    }
 
182
}