~unity-team/unity8/ota9.5

« back to all changes in this revision

Viewing changes to tests/qmltests/Dash/tst_PeoplePreview.qml

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU 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 General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import QtTest 1.0
 
19
import ".."
 
20
import "../../../Dash/People"
 
21
import Ubuntu.Components 0.1
 
22
import Unity.Test 0.1 as UT
 
23
 
 
24
Item {
 
25
    id: root
 
26
    width: units.gu(140)
 
27
    height: units.gu(100)
 
28
 
 
29
    property bool helper: false
 
30
 
 
31
    PeoplePreview {
 
32
        id: preview
 
33
        anchors.fill: parent
 
34
        anchors.rightMargin: units.gu(20)
 
35
    }
 
36
 
 
37
    Column {
 
38
        anchors {
 
39
            left: preview.right
 
40
            top: parent.top
 
41
            right: parent.right
 
42
            bottom: parent.bottom
 
43
            margins: units.gu(1)
 
44
        }
 
45
        spacing: units.gu(1)
 
46
 
 
47
        Button {
 
48
            text: "Clear all"
 
49
            anchors { left: parent.left; right: parent.right }
 
50
            onClicked: mockModel.clear();
 
51
        }
 
52
        Repeater {
 
53
            model: testCase.test_click_items_data()
 
54
            Button {
 
55
                text: testCase.test_click_items_data()[index].tag
 
56
                anchors { left: parent.left; right: parent.right }
 
57
                onClicked: testCase.fillModel(testCase.test_click_items_data()[index]);
 
58
            }
 
59
        }
 
60
    }
 
61
 
 
62
    ListModel {
 
63
        id: mockModel
 
64
    }
 
65
 
 
66
    SignalSpy {
 
67
        id: clickSpy
 
68
        signalName: "clicked"
 
69
    }
 
70
 
 
71
    UT.UnityTestCase {
 
72
        id: testCase
 
73
        name: "PeoplePreview"
 
74
        when: windowShown
 
75
 
 
76
        function fillModel(data) {
 
77
            mockModel.clear();
 
78
            mockModel.append(data);
 
79
            preview.model = mockModel.get(0);
 
80
            wait(0);
 
81
        }
 
82
 
 
83
        function test_click_items_data() {
 
84
            return [
 
85
                        {
 
86
                            tag: "All Data",
 
87
                            displayName: "Round Robin",
 
88
                            avatar: "../../graphics/clock.png",
 
89
                            status: "very busy",
 
90
                            statusTime: "1/6/2013 16:19:01",
 
91
                            statusServiceIcon: "../../../graphics/clock.png",
 
92
                            phoneNumbers: [{number:"123456", type: "voice", location: "Mars"}, {number: "654321"}],
 
93
                            emailAddresses: [{address:"robin@ntp.org"}, {address: "sirspamalot@foo.com"}],
 
94
                            imAccounts: [{address:"rr@jabber.org", protocol: "xmpp"}, {address: "sirspamalot@foo.com", protocol: "secret service messenger"}],
 
95
                            addresses: [
 
96
                                {street: "Middle of nowhere", poBox: 1, extension: "none", locality: "Mars", region: "all of it", postalCode: "٣٤٥٦", country: "There is only one on mars", addressFormat: "unreadable for you"},
 
97
                                {street: "Blue fin building"}
 
98
                            ]
 
99
                        },
 
100
                        {
 
101
                            tag: "Only Status",
 
102
                            status: "very busy",
 
103
                            statusTime: "1/6/2013 16:19:01",
 
104
                            statusServiceIcon: "../../../graphics/clock.png",
 
105
                        },
 
106
                        {
 
107
                            tag: "One Number",
 
108
                            phoneNumbers: [{number:"123456", type: "voice", location: "Mars"}],
 
109
                        },
 
110
                        {
 
111
                            tag: "Three Numbers",
 
112
                            phoneNumbers: [{number:"123456", type: "voice", location: "Mars"}, {number: "654321"}, {number: "666", type: "voice", location: "h3ll"}],
 
113
                        },
 
114
                        {
 
115
                            tag: "Only Mails",
 
116
                            emailAddresses: [{address:"robin@ntp.org"}, {address: "sirspamalot@foo.com"}],
 
117
                        },
 
118
                        {
 
119
                            tag: "Only IM",
 
120
                            imAccounts: [{address:"rr@jabber.org", protocol: "xmpp"}, {address: "sirspamalot@foo.com", protocol: "secret service messenger"}],
 
121
                        },
 
122
                        {
 
123
                            tag: "Only Address",
 
124
                            addresses: [
 
125
                                {street: "Middle of nowhere", poBox: 1, extension: "none", locality: "Mars", region: "all of it", postalCode: "٣٤٥٦", country: "There is only one on mars", addressFormat: "unreadable for you"},
 
126
                            ]
 
127
                        },
 
128
                        {
 
129
                            tag: "Std Contact",
 
130
                            displayName: "Round Robin",
 
131
                            avatar: "../../graphics/clock.png",
 
132
                            phoneNumbers: [{number:"123456", type: "voice", location: "Mars"}],
 
133
                            emailAddresses: [{address:"robin@ntp.org"}],
 
134
                            addresses: [
 
135
                                {street: "Middle of nowhere", poBox: 1, extension: "none", locality: "Mars", region: "all of it", postalCode: "٣٤٥٦", country: "There is only one on mars", addressFormat: "unreadable for you"},
 
136
                                {street: "Blue fin building"}
 
137
                            ]
 
138
                        },
 
139
                        {
 
140
                            tag: "Std + Status",
 
141
                            displayName: "Round Robin",
 
142
                            avatar: "../../graphics/clock.png",
 
143
                            status: "very busy",
 
144
                            statusTime: "1/6/2013 16:19:01",
 
145
                            statusServiceIcon: "../../../graphics/clock.png",
 
146
                            phoneNumbers: [{number:"123456", type: "voice", location: "Mars"}],
 
147
                            emailAddresses: [{address:"robin@ntp.org"}],
 
148
                            addresses: [
 
149
                                {street: "Middle of nowhere", poBox: 1, extension: "none", locality: "Mars", region: "all of it", postalCode: "٣٤٥٦", country: "There is only one on mars", addressFormat: "unreadable for you"},
 
150
                                {street: "Blue fin building"}
 
151
                            ]
 
152
                        },
 
153
                    ]
 
154
        }
 
155
 
 
156
        function test_click_items(data) {
 
157
            fillModel(data)
 
158
 
 
159
            // Check if status field is visible
 
160
            var field = findChild(preview, "statusField");
 
161
            if (data.status != undefined) {
 
162
                compare(field.visible, true, "status field is not visible");
 
163
                verifyClick(field);
 
164
            } else {
 
165
                compare(field.visible, false, "status field is visible while it should not");
 
166
            }
 
167
 
 
168
            // Check if there are phoneNumber.count phone fields
 
169
            var i = 0;
 
170
            if (data.phoneNumbers != undefined) {
 
171
                for (; i < data.phoneNumbers.length; ++i) {
 
172
                    var field = findChild(preview, "phoneField" + i);
 
173
                    verify(field != undefined);
 
174
                    verifyPhoneNumberClick(field);
 
175
                }
 
176
                i++;
 
177
            }
 
178
            // Check if there are no more phone fields
 
179
            var field = findChild(preview, "phoneField" + i);
 
180
            compare(field, undefined, "There is a phone number field too much!");
 
181
 
 
182
 
 
183
            // Check if email adresses are here
 
184
            var i = 0;
 
185
            if (data.emailAddresses != undefined) {
 
186
                for (; i < data.emailAddresses.length; ++i) {
 
187
                    var field = findChild(preview, "emailField" + i);
 
188
                    verify(field != undefined);
 
189
                    verifyClick(field);
 
190
                }
 
191
                i++;
 
192
            }
 
193
            // Check if there are no more email fields
 
194
            var field = findChild(preview, "emailField" + i);
 
195
            compare(field, undefined, "There is a email field too much!");
 
196
 
 
197
 
 
198
            // Check if IM accounts are here
 
199
            var i = 0;
 
200
            if (data.imAccounts != undefined) {
 
201
                for (; i < data.imAccounts.length; ++i) {
 
202
                    var field = findChild(preview, "imField" + i);
 
203
                    verify(field != undefined);
 
204
                    verifyClick(field);
 
205
                }
 
206
                i++;
 
207
            }
 
208
            // Check if there are no more IM fields
 
209
            var field = findChild(preview, "imField" + i);
 
210
            compare(field, undefined, "There is a IM field too much!");
 
211
 
 
212
            // Check if email adresses are here
 
213
            var i = 0;
 
214
            if (data.addresses != undefined) {
 
215
                for (; i < data.addresses.length; ++i) {
 
216
                    var field = findChild(preview, "addressField" + i);
 
217
                    verify(field != undefined);
 
218
                    verifyClick(field);
 
219
                }
 
220
                i++;
 
221
            }
 
222
            // Check if there are no more fields fields
 
223
            var field = findChild(preview, "addressField" + i);
 
224
            compare(field, undefined, "There is an address field too much!");
 
225
        }
 
226
 
 
227
        function verifyClick(field) {
 
228
            waitForRendering(field)
 
229
            clickSpy.signalName = "" // Get rid of a warning if new target doesn't support previous signal name
 
230
            clickSpy.target = field;
 
231
            clickSpy.clear();
 
232
            clickSpy.signalName = "clicked";
 
233
            compare(clickSpy.count, 0, "Could not reset signal spy");
 
234
            mouseClick(field, field.width / 2, field.height / 2);
 
235
            compare(clickSpy.count, 1, "Could not click on field " + field);
 
236
        }
 
237
 
 
238
        function verifyPhoneNumberClick(field) {
 
239
            waitForRendering(field)
 
240
            clickSpy.target = field;
 
241
            clickSpy.clear();
 
242
            clickSpy.signalName = "phoneClicked";
 
243
            compare(clickSpy.count, 0, "Could not reset signal spy");
 
244
            mouseClick(field, 1 , field.height / 2);
 
245
            compare(clickSpy.count, 1, "Could not click on phone field");
 
246
 
 
247
            clickSpy.clear();
 
248
            clickSpy.signalName = "textClicked";
 
249
            compare(clickSpy.count, 0, "Could not reset signal spy");
 
250
            mouseClick(field, field.width - 1 , field.height / 2);
 
251
            compare(clickSpy.count, 1, "Could not click on Message field");
 
252
        }
 
253
    }
 
254
}