summaryrefslogtreecommitdiffstats
path: root/tests/systemtests/sys_contacts/sys_contacts.qtt
blob: 6e5fed21c56916734b0b5d21a4d2d8117832f6bf (plain)
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

//TESTED_COMPONENT=src/contacts

function selectContactList()
{
    if (!runAsManualTest()){
        var contactList = findWidget( { className: "QListWidget" } );
        mouseClick(contactList[0]);
    }else{
        prompt("Select the contact list");
    }
}

function createFilter(contactName)
{

    if (!runAsManualTest()){
         if (checkOS("maemo")){
             skip("Maemo menus not supported yet", SkipAll);
             /* mouseClick(400,10); // raise menu manually
                 var maemoMenuBar = findByProperty({ className : "QMaemo5ApplicationMenu" });
                 print("Maemo menu = " + maemoMenuBar);
                 print("filterCheck:" + activeWidgetInfo());
                 */
         }
    }

    if (!runAsManualTest()){
      //print("Labels are" + getLabels());
      //print("filterCheck widgetInfo:" + activeWidgetInfo());
      var menuItemName = "Apply &Filter...";
      var menuItem = contactsMenuItem(menuItemName);
      verify(menuItem != undefined, "No such \"" + menuItemName + "\" menu");
      select(menuItem, menuBar());
    }else{
      prompt("Select menu entry \'Apply Filter\'");
    }

    enter(contactName, "Name");
    select("&Filter");
}


function clearFilter()
{
    if (!runAsManualTest()){
       if (checkOS("maemo")){
           skip("Maemo menus not supported yet", SkipAll);
       }else{
           select(contactsMenuItem("&Clear Filter"), menuBar());
       }
   }else {
       prompt('Select \'Clear Filter\' menu entry');
    }
}

// helper function re :contact actions may be in a separate "Contacts menu"
function contactsMenuItem(menuText)
{
    var menuEntries = getValue(menuBar()).toString().split("\n");
    var index = 0;
    var separateMenu = false; // optimize number of calls to indexOf

    for (index = 0; index < menuEntries.length; index++){
        if (!separateMenu && menuEntries[index].indexOf("&Contacts") >= 0){
            separateMenu = true;
            menuText = "&Contacts/" + menuText;
        }
        if (menuEntries[index] == menuText)
            return menuText;
    }

    return undefined;
}

// if were are adding a new contact the oldName is empty
// otherwise find the oldName then edit contact details
function updateContact(name, phone, email, address, avatar, oldName) {
    if ((oldName == undefined)  || (oldName == "")){
        select("Add");
    }else{
        if (!runAsManualTest()){
            var contactList = findWidget( { className: "QListWidget" } );
            select(oldName, contactList);
        }else{
            prompt("Select contact named:\'" + oldName + "\'");
        }
        select("Edit");
    }

    enter(name, "Name");
    // add/set all extra details if value for phone is specified
    if ((phone != undefined) && (phone != "")){
        enter(phone, "Phone");
        enter(email, "Email");
        enter(address, "Address");
        /* TODO support setting the avatar
        if (!runAsManualTest()){
            var selectPictureBtn = findByProperty( { className: "QPushButton", text : "Set picture" });
            select(selectPictureBtn[0]);
        }else {
            select("Set picture");
        }

        if (!runAsManualTest()){
            // try and find the "Name:" label
            var labels = getLabels();
            for (var index=0; index < labels.length; index++){
                if (labels[index].indexOf("ame")){
                    enter(avatar,labels[index]);
                    // need to accept entry due to autocompletion
                    keyClick(Qt.Key_Enter);
                    break;
                }
            }
            // try and find the "Open:" button
            for (var index=0; index < labels.length; index++){
                if (labels[index].indexOf("pen")){
                    select(labels[index]);
                    break;
                }
            }
        }else{
            enter(avatar, "File name:");
        }
        */
    }

    select("Save");
    if (!runAsManualTest())
        waitForSave();
}

function deleteContact(name)
{
    selectContactList();
    select(name);
    select("Delete");
}

function checkContactExists(name, exists)
{
    if (!runAsManualTest()){
        var contactWidget = findWidget( { className: "QListWidget" } );
        var contactList = getValue(contactWidget);
        if (exists)
            verify(contactList.indexOf(name) != -1, "Contact was missing:" + name);
        else
            verify(contactList.indexOf(name) == -1, "Contact was found expectedly:" + name);
    }else{
        if (exists)
            prompt("Verify that Contact exists:\'" + name + "\'");
        else
            prompt("Verify that Contact is missing:\'" + name + "\'");
    }
}

// Returns true if contact named,name, can be found in contact list
function checkContactDetails(name, phone, email, address, avatar){
    if (!runAsManualTest()){
        var contactList = findWidget( { className: "QListWidget" } );
        select(name, contactList);
    }else{
        prompt("Select in list Contact named:\'" + name + "\'");
    }
    select("Edit");
    // check all values if a phone value is provided
    if ((phone != undefined) && (phone != "")){
        // make verify and prompt messages as clear as possible
        var phonePrompt = "";
        var emailPrompt = "";
        var addressPrompt = "";
        if (!runAsManualTest()){
            phonePrompt = " instead has Phone of:" + getText("Phone");
            emailPrompt = " instead has Email of:" + getText("Email");
            addressPrompt = " instead has Address of:" + getText("Phone");
        }

        verify(getText("Phone") == phone, "Contact " + name + " is expected to have Phone of:\'" + phone + "\'" + phonePrompt);
        verify(getText("Email") == email, "Contact " + name + " is expected to have Email of:\'" + email + "\'" +emailPrompt);
        verify(getText("Address")== address, "Contact " + name + " is expected to have Address of:\'" + address + "\'" + addressPrompt);
    }

    select("Cancel");
}


// not ideal, there is need to programaticly check that
//  the contact details dialog is not longer showing, ie no "Save" button
function waitForSave(){
    for (var loop=0; loop < 5; loop++){
        if (getLabels().contains("&Save"))
            wait(1000); // wait to try again
        else
            break;
    }

    // should not happen
    verify(!getLabels().contains("&Save"));
}

testcase = {


    initTestCase: function()
    {
/*
        startApplication("samplephonebook");

        if (!runAsManualTest()){
            var contactList = findWidget( { className: "QListWidget" } );
            verify(getValue(contactList).length == 0, "There must be zero contacts prior to running test, there are the following contacts:" + getValue(contactList));
        }else{
            prompt("Verify that no contacts are present");
        }
*/
    },

    cleanup: function()
    {
        // While there are names, delete the names from the list
        if (!runAsManualTest()){
            /* TODO delete contact added by test cases
            // make use we remove all contacts that has been added
            startApplication("samplephonebook");

            var contactWidget = findWidget( { className: "QListWidget" } );
            var contactList = getValue(contactWidget);
            // delete all contact that contain "Name"
            for (var index = 0; index < contactList.length; index){
                if (contactList[index].indexOf("Name") != -1)
                    deleteContact(contactList[index]);
            }
            */
        }else{
            prompt("Delete all Contacts whos name contains: \'Name\'");
        }
    },

    addContact_data :  {
        ContactSet1: [ [
                {name:"Name1", phone:"111111", email:"Email1@com", address:"Address1", avatar:"testdata/avatar1.png"},
                {name:"Name2", phone:"222222", email:"Email2@com", address:"Address2", avatar:"testdata/avatar2.png"},
                {name:"Name3", phone:"333333", email:"Email3@com", address:"Address3", avatar:"testdata/avatar3.png"}
        ] ]
    },

    addContact: function(contactSet)
    {
        // Test meta data
        testTitle = "Contacts - Add Contact";
        testBinary = "samplephonebook";
        testSource = "$MOBILITYDIR/examples/samplephonebook";
        testGoal = "Verify that contacts can be added";
        testPreconditions = "None";
        testGroups = "BAT_MOBILITY";
        testRequirements = "";

        // Test steps
        startApplication(testBinary);

        for (var index = 0; index < contactSet.length; index++){
            var contact = contactSet[index];
            // create new contact
            updateContact(contact.name, contact.phone,contact.email, contact.avatar, "");
            checkContactDetails(contact.name, contact.phone,contact.email, contact.avatar);
        }
    },

    updateContactDetails_data :  {
        ContactSet1: [ [
                {name:"Name1", phone:"111111", email:"Email1@com", address:"Address1", avatar:"testdata/avatar1.png"},
                {name:"Name2", phone:"222222", email:"Email2@com", address:"Address2", avatar:"testdata/avatar2.png"},
                {name:"Name3", phone:"333333", email:"Email3@com", address:"Address3", avatar:"testdata/avatar3.png"}
        ] ]
    },

    updateContactDetails : function(contactSet)
    {
        // Test meta data
        testTitle = "Contacts - Update Contact Details";
        testBinary = "samplephonebook";
        testSource = "$MOBILITYDIR/examples/samplephonebook";
        testGoal = "Verify that contact details can be updated";
        testPreconditions = "None";
        testGroups = "BAT_MOBILITY";
        testRequirements = "";

        // Test steps
        startApplication(testBinary);

        for (var index = 0; index < contactSet.length; index++){
            var contact = contactSet[index];
            var newname = contact.name + '9';
            var newphone = contact.phone + '9';
            var newaddress = contact.address + '9';
            var newemail = contact.email + '9';
            // create new contact
            updateContact(contact.name, contact.phone, contact.email, contact.address, contact.avatar, "");
            // edit its values and verify correctness
            updateContact(newname, newphone, newemail, newaddress, contact.avatar, contact.name);
            checkContactDetails(newname, newphone, newemail, newaddress, contact.avatar);
        }
    },

    filterCheck_data : {
        Name1 : ["NameA", true, "Full contact name match"],
        Name2 : ["NonExistant", false, "Non-existant contact name"]

    },

    filterCheck_extraData: {
        Names: ["NameA", "NameB"]
    },

    filterCheck : function(name, exists, message) {
        // Test meta data
        testTitle = "Contacts - Apply Filter";
        testBinary = "samplephonebook";
        testSource = "$MOBILITYDIR/examples/samplephonebook";
        testGoal = "Verify the correct match of contacts against a simple filter";
        testPreconditions = "None";
        testGroups = " ";
        testRequirements = "";

        // Test steps
        startApplication(testBinary);

        // add some contacts for this tests use
        var extraNames = testcase.filterCheck_extraData['Names'];
        updateContact(extraNames[0]);
        updateContact(extraNames[1]);
        createFilter(name);
        checkContactExists(name, exists);
    },


    clearFilterCheck_data : {
        Name1: ["NameA"]
    },

    clearFilterCheck_extraData: {
        Names: ["NameC", "NameD"]
    },

    clearFilterCheck : function(nameFilter){
       // Test meta data
       testTitle = "Contacts - Clear Filter";
       testBinary = "samplephonebook";
       testSource = "$MOBILITYDIR/examples/samplephonebook";
       testGoal = "Verify that when the filter is cleared all contacts are visible";
       testPreconditions = "None";
       testGroups = " ";
       testRequirements = "";

       // Test steps
       startApplication(testBinary);

        // add some contacts for this tests use
        var extraNames = testcase.clearFilterCheck_extraData['Names'];
        updateContact(extraNames[0]);
        updateContact(extraNames[1]);
        // Note that the filter will not match any of these contacts
        createFilter(nameFilter);
        checkContactExists(extraNames[0], false);
        checkContactExists(extraNames[1], false);
        // Remove filter and now the contacts should be seen
        clearFilter();
        checkContactExists(extraNames[0], true);
        checkContactExists(extraNames[1], true);
    },


    deleteContact_data: {
        Name1 : ["NameE", "NameG", "NameH"]
    },

    deleteContact : function(name1, name2, name3){
        // Test meta data
        testTitle = "Contacts - Delete Contact";
        testBinary = "samplephonebook";
        testSource = "$MOBILITYDIR/examples/samplephonebook";
        testGoal = "Verify that a contact can be deleted";
        testPreconditions = "None";
        testGroups = "BAT_MOBILITY";
        testRequirements = "";

        // Test steps
        startApplication(testBinary);

        // add some contacts for this tests use
        updateContact(name1);
        updateContact(name2);
        updateContact(name3);

        // delete contacts in different order to creation
        deleteContact(name2);
        deleteContact(name1);
        deleteContact(name3);

        if (!runAsManualTest()){
            wait(5000); // wait long enough for contact to be deleted
            checkContactExists(name1, false);
            checkContactExists(name2, false);
            checkContactExists(name3, false);
        }else{
            prompt("Verify that Contacts have been deleted");
            /*
            prompt(twiki("---+++ " + testTitle + "<br><br>
                *Goal:* " + testGoal + "<br>
                *Pre-Requisites:* " + testPreconditions + "<br>
                *Tested Binary:* " + testBinary + "<br>

                | *Step* | *Verification* |
                | | Verify that Contacts have been deleted:" + name1 + ", " + name2 + ", " + name3 + "|" ));
            */
        }
    }

}