~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to tests/auto/contacts/qmlcontacts/testcases/tst_contacts_e2e.qml

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the Qt Mobility Components.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
import QtQuick 2.0
 
43
import QtTest 1.0
 
44
import QtContacts 5.0
 
45
 
 
46
Rectangle {
 
47
 
 
48
property bool start: false
 
49
property SignalSpy contactsChangedSpy
 
50
property ContactModel contactModel
 
51
property Contact testContact
 
52
 
 
53
    TestCase {
 
54
        name: "ContactsTests"
 
55
 
 
56
        function waitForContactsChanged (expectedCount) {
 
57
            contactsChangedSpy.wait();
 
58
            compare (contactsChangedSpy.count, expectedCount)
 
59
        }
 
60
 
 
61
        function test_addAndRemoveDetails()
 
62
        {
 
63
            //TODO verify this test case when we remove dynamic properties from the Api
 
64
            //currently removing details from the contact is not updated in contact model
 
65
            //TODO add a test case to remove the same detail N times and remove a detail which doesnt exist etc...
 
66
            var model = Qt.createQmlObject(
 
67
                    "import QtContacts 5.0;" +
 
68
                    "ContactModel {id:model;autoUpdate:true;onContactsChanged:{console.log(\"CONTACTS CHANGED!\")}}", testHelper);
 
69
            var tmp = Qt.createQmlObject(
 
70
                    "import QtContacts 5.0;" +
 
71
                    "Contact {Name{}}", testHelper);
 
72
            var spy2 = Qt.createQmlObject("import QtTest 1.0;" +"SignalSpy {id: theSpy;signalName: \"contactsChanged\";}", testHelper);
 
73
            contactsChangedSpy = spy2;
 
74
            contactsChangedSpy.target = model;
 
75
            contactsChangedSpy.clear()
 
76
            testHelper.model = model;
 
77
            waitForContactsChanged (1)
 
78
            testHelper.emptyContactsDb();
 
79
            testContact = tmp;
 
80
            var phone = Qt.createQmlObject("import QtContacts 5.0;" +
 
81
                                              "PhoneNumber {number: '99999999'}", testContact);
 
82
            var nick = Qt.createQmlObject("import QtContacts 5.0;" +
 
83
                                             "Nickname {nickname: 'jack'}", testContact);
 
84
            var label = Qt.createQmlObject("import QtContacts 5.0;" +
 
85
                                             "DisplayLabel {label: 'Alice In Wonderland'}", testContact);
 
86
            var mail = Qt.createQmlObject("import QtContacts 5.0;" +
 
87
                                             "EmailAddress {emailAddress: 'joe.john@ovi.com'}", testContact);
 
88
            testContact.name.firstName = "Joe"
 
89
            testContact.name.lastName = "John"
 
90
            testContact.addDetail(phone)
 
91
            testContact.addDetail(nick)
 
92
            testContact.addDetail(label)
 
93
            testContact.addDetail(mail)
 
94
            contactsChangedSpy.clear()
 
95
            model.saveContact(testContact)
 
96
            waitForContactsChanged (1)
 
97
            testContact = model.contacts[0]
 
98
            compare(testContact.phoneNumber.number,"99999999")
 
99
            compare(testContact.nickname.nickname,"jack")
 
100
            compare(testContact.displayLabel.label,"Alice In Wonderland")
 
101
            compare(testContact.email.emailAddress,"joe.john@ovi.com")
 
102
            testContact.removeDetail(testContact.detail(ContactDetail.NickName));
 
103
            testContact.removeDetail(testContact.detail(ContactDetail.DisplayLabel));
 
104
            testContact.removeDetail(testContact.detail(ContactDetail.PhoneNumber));
 
105
            testContact.removeDetail(testContact.detail(ContactDetail.Email));
 
106
            contactsChangedSpy.clear()
 
107
            model.saveContact(testContact)
 
108
            waitForContactsChanged (1)
 
109
            testContact = model.contacts[0]
 
110
            verify(!testContact.detail(ContactDetail.NickName))
 
111
            verify(!testContact.detail(ContactDetail.DisplayLabel))
 
112
            verify(!testContact.detail(ContactDetail.PhoneNumber))
 
113
            verify(!testContact.detail(ContactDetail.Email))
 
114
            compare(model.contacts.length, 1)
 
115
            testHelper.emptyContactsDb();
 
116
            model.autoUpdate = false;
 
117
        }
 
118
 
 
119
        property Component component
 
120
        property ContactsTestHelper testHelper
 
121
 
 
122
        function init() {
 
123
            component = Qt.createComponent("ContactsTestHelper.qml");
 
124
            testHelper = component.createObject(top);
 
125
            if (testHelper == undefined)
 
126
                console.log("Unable to load component from " + name +  " error is ", component.errorString())
 
127
            verify(testHelper != undefined, 'Unable to load component ' + name);
 
128
        }
 
129
 
 
130
        function cleanup() {
 
131
            testHelper.destroy();
 
132
            component.destroy();
 
133
          }
 
134
 
 
135
 
 
136
        Contact {
 
137
            id: contact
 
138
        }
 
139
 
 
140
        function test_contact() {
 
141
            // empty Contact
 
142
            compare(contact.modified, false)
 
143
 
 
144
            // access Type
 
145
            console.log("type is: " + contact.type)
 
146
            compare(contact.type, Type.Contact)  // Type is Contact and not Group
 
147
 
 
148
            // access contactId
 
149
            console.log("contactId is: " + JSON.stringify(contact.contactId) )
 
150
            compare(contact.contactId, "qtcontacts:::")
 
151
 
 
152
            // access manager
 
153
            console.log("manager is: " + JSON.stringify(contact.manager))
 
154
            compare(contact.manager, "")
 
155
        }
 
156
 
 
157
        Contact {
 
158
            id: contact2
 
159
        }
 
160
 
 
161
        PhoneNumber {
 
162
            id: phoneNumber
 
163
            number: "99999999"
 
164
        }
 
165
 
 
166
        function test_contactAddDetail() {
 
167
            // add new Detail
 
168
            contact2.addDetail(phoneNumber)
 
169
            compare(contact2.phoneNumber.number, "99999999")
 
170
        }
 
171
 
 
172
        Contact {
 
173
            id: contact3
 
174
            PhoneNumber {
 
175
                id: phoneNumber3
 
176
                number: "99999999"
 
177
            }
 
178
        }
 
179
 
 
180
        function test_contactUpdateDetail() {
 
181
            // update existing Detail
 
182
            contact3.phoneNumber.number = "88888"
 
183
            compare(contact3.phoneNumber.number, "88888")
 
184
        }
 
185
 
 
186
        Contact {
 
187
            id: contact4
 
188
            PhoneNumber {
 
189
                id: phoneNumber4
 
190
                number: "99999999"
 
191
            }
 
192
        }
 
193
        function test_contactRemoveDetail() {
 
194
            // delete one existing Detail
 
195
            contact4.removeDetail(phoneNumber4);
 
196
            verify(!contact4.phoneNumber.number)
 
197
        }
 
198
    }
 
199
}