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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
/*
* Copyright 2013 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/>.
*
* Authored by Nick Dedekind <nick.dedekind@canonical.com>
*/
import QtQuick 2.0
import QtTest 1.0
import Ubuntu.Test 0.1
import Ubuntu.Components 0.1
import Ubuntu.Settings.Menus 0.1
import "../utils.js" as UtilsJS
Item {
width: units.gu(42)
height: units.gu(75)
Flickable {
id: flickable
anchors.fill: parent
contentWidth: column.width
contentHeight: column.height
Item {
id: column
width: flickable.width
height: childrenRect.height
TextMessageMenu {
id: messageMenu
removable: false
title: "Text Message"
time: "11:08am"
message: "I am a little teapot"
}
TextMessageMenu {
id: messageMenuRemovable
removable: true
anchors.top: messageMenu.bottom
}
TextMessageMenu {
id: messageMenuSelected
removable: true
anchors.top: messageMenuRemovable.bottom
onReplied: {
textMessageReply = value;
}
}
}
}
property string textMessageReply: ""
SignalSpy {
id: signalSpyActivateApp
signalName: "appActivated"
target: messageMenuSelected
}
SignalSpy {
id: signalSpyDismiss
signalName: "dismissed"
target: messageMenuRemovable
}
SignalSpy {
id: signalSpyReply
signalName: "replied"
target: messageMenuSelected
}
UbuntuTestCase {
name: "TextMessageMenu"
when: windowShown
function init() {
signalSpyActivateApp.clear();
signalSpyDismiss.clear();
signalSpyReply.clear();
textMessageReply = "";
messageMenu.replyEnabled = true;
messageMenuSelected.selected = false;
}
function test_title_data() {
return [
{ title: "title1" },
{ title: "title2" },
];
}
function test_title(data) {
messageMenu.title = data.title;
var title = UtilsJS.findChild(messageMenu, "title");
verify(title, "No title");
compare(title.text, data.title, "Title does not match set title.");
}
function test_time_data() {
return [
{ time: "11:09am" },
{ time: "4pm" },
];
}
function test_time(data) {
messageMenu.time = data.time;
var subtitle = UtilsJS.findChild(messageMenu, "subtitle");
verify(subtitle !== undefined, "No subtitle");
compare(subtitle.text, data.time, "Time does not match set time.");
}
function test_appIcon_data() {
return [
{ appIcon: Qt.resolvedUrl("../../artwork/avatar.png") },
{ appIcon: Qt.resolvedUrl("../../artwork/rhythmbox.png") },
];
}
function test_appIcon(data) {
messageMenu.appIcon = data.appIcon;
var appIcon = UtilsJS.findChild(messageMenu, "appIcon");
verify(appIcon !== undefined, "No app icon");
compare(appIcon.source, data.appIcon, "App Icon does not match set icon.");
}
function test_message_data() {
return [
{ message: "This is a test." },
{ message: "Test is also a test." },
];
}
function test_message(data) {
messageMenu.message = data.message;
var body = UtilsJS.findChild(messageMenu, "body");
verify(body !== undefined, "No body");
compare(body.text, data.message, "Message does not match set message.");
}
function test_replyButtonText_data() {
return [
{ buttonText: "Send" },
{ buttonText: "reply" },
];
}
function test_replyButtonText(data) {
messageMenu.replyButtonText = data.buttonText;
var button = UtilsJS.findChild(messageMenu, "sendButton");
verify(button !== undefined, "No send button");
compare(button.text, data.buttonText, "Button text does not match set text.");
}
function test_activateApp() {
var appIcon = UtilsJS.findChild(messageMenuSelected, "appIcon");
mouseClick(appIcon, appIcon.width * 2, appIcon.height / 2, Qt.LeftButton, Qt.NoModifier, 0);
compare(signalSpyActivateApp.count, 0, "activate app should not have been triggered");
messageMenuSelected.selected = false;
mouseClick(appIcon, appIcon.width / 2, appIcon.height / 2, Qt.LeftButton, Qt.NoModifier, 0);
compare(signalSpyActivateApp.count, 0, "activate app should not have been triggered when not selected");
messageMenuSelected.selected = true;
mouseClick(appIcon, appIcon.width / 2, appIcon.height / 2, Qt.LeftButton, Qt.NoModifier, 0);
compare(signalSpyActivateApp.count > 0, true, "activate app should have been triggered when selected");
}
function test_dismiss() {
mouseFlick(messageMenuRemovable,
messageMenuRemovable.width / 2,
messageMenuRemovable.height / 2,
messageMenuRemovable.width,
messageMenuRemovable.height / 2,
true, true, units.gu(1), 10);
tryCompare(function() { return signalSpyDismiss.count > 0; }, true);
}
function test_replyEnabled_data() {
return [
{ tag: 'disabledNoReply', enabled: false, reply: "", expected: false},
{ tag: 'enabledNoReply', enabled: true, reply: "", expected: false},
{ tag: 'disabledWithReply', enabled: false, reply: "test", expected: false},
{ tag: 'enabledWithReply', enabled: true, reply: "test", expected: true},
];
}
function test_replyEnabled(data) {
messageMenuSelected.selected = true;
messageMenuSelected.replyEnabled = data.enabled
var replyText = UtilsJS.findChild(messageMenuSelected, "replyText");
verify(replyText !== undefined, "Reply text not found");
var sendButton = UtilsJS.findChild(messageMenuSelected, "sendButton");
verify(sendButton !== undefined, "Send button not found");
replyText.text = data.reply;
compare(sendButton.enabled, data.expected, "Reply button is not in correct state");
}
function test_reply() {
messageMenuSelected.selected = true;
messageMenuSelected.replyEnabled = true;
var replyText = UtilsJS.findChild(messageMenuSelected, "replyText");
verify(replyText !== undefined, "Reply text not found");
replyText.text = "reply1";
var sendButton = UtilsJS.findChild(messageMenuSelected, "sendButton");
verify(sendButton !== undefined, "Send button not found");
mouseClick(sendButton, sendButton.width / 2, sendButton.height / 2, Qt.LeftButton, Qt.NoModifier, 0);
compare(signalSpyReply.count > 0, true);
compare(textMessageReply, "reply1", "Text message did not reply with correct text.");
}
}
}
|