2
* Copyright 2016 Canonical Ltd.
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.
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.
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/>.
16
* Authored by Marco Trevisan <marco.trevisan@canonical.com>
21
import Ubuntu.Test 0.1
22
import Ubuntu.Settings.Menus 0.1
47
property bool clicked: false
48
function onClickedCallback() { clicked = true }
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)
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)
83
function test_showDivider() {
84
compare(baseMenu.showDivider, false)
85
compare(baseMenu.divider.visible, false)
87
baseMenu.showDivider = true
88
compare(baseMenu.showDivider, true)
89
compare(baseMenu.divider.visible, true)
91
baseMenu.showDivider = false
92
compare(baseMenu.divider.visible, false)
93
compare(baseMenu.showDivider, false)
96
function test_hideDivider() {
97
compare(dividerMenu.showDivider, true)
98
compare(dividerMenu.divider.visible, true)
100
dividerMenu.showDivider = false
101
compare(dividerMenu.showDivider, false)
102
compare(dividerMenu.divider.visible, false)
104
dividerMenu.showDivider = true
105
compare(dividerMenu.divider.visible, true)
106
compare(dividerMenu.showDivider, true)
109
function test_hideDividerLegacy() {
110
legacyDividerMenu.showDivider = false
111
compare(legacyDividerMenu.showDivider, false)
112
compare(legacyDividerMenu.divider.visible, false)
114
legacyDividerMenu.showDivider = true
115
compare(legacyDividerMenu.divider.visible, true)
116
compare(legacyDividerMenu.showDivider, true)
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)
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
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)
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)
152
function test_notRemovable() {
153
compare(baseMenu.removable, false)
154
compare(baseMenu.leadingActions, null)
155
verify(findChild(baseMenu, "removeAction") === undefined)
158
function test_removable() {
159
compare(removableMenu.removable, true)
160
compare(removableMenu.leadingActions !== null, true)
161
verify(findChild(baseMenu, "removeAction") === undefined)
164
function test_removal() {
166
signalSpy.target = removableMenu
167
signalSpy.signalName = "itemRemoved"
168
mouseFlick(removableMenu,
169
removableMenu.width / 2,
170
removableMenu.height / 2,
172
removableMenu.height / 2,
173
true, true, units.gu(1), 10);
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)