~chris.gagnon/ubuntu-calendar-app/fix_1293489

« back to all changes in this revision

Viewing changes to dataServiceTests.js

  • Committer: Kunal Parmar
  • Date: 2013-09-28 03:48:02 UTC
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: pkunal.parmar@gmail.com-20130928034802-pt5pg5p33mc3jnjr
EDS integration done

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
.pragma library
2
 
.import "dateExt.js" as DateExt
3
 
.import "dataService.js" as DataService
4
 
 
5
 
function clearData(tx) {
6
 
    var deletes = '\
7
 
delete from Event;\
8
 
delete from Place;\
9
 
delete from Contact;\
10
 
delete from Attendance;\
11
 
delete from Venue\
12
 
'.split(';')
13
 
    for (var i = 0; i < deletes.length; ++i)
14
 
        tx.executeSql(deletes[i])
15
 
}
16
 
 
17
 
function loadTestDataSimple(tx)
18
 
{
19
 
    clearData(tx)
20
 
 
21
 
    var inserts = '\
22
 
insert into Contact(id, name, surname) values (1, "John", "Smith");\
23
 
insert into Contact(id, name, surname) values (2, "Jane", "Smith");\
24
 
insert into Contact(id, name, surname, avatar) values (3, "Frank", "Mertens", "http://www.gravatar.com/avatar/6d96fd4a98bba7b8779661d5db391ab6");\
25
 
insert into Contact(id, name, surname) values (4, "Kunal", "Parmar");\
26
 
insert into Contact(id, name, surname) values (5, "Mario", "Boikov");\
27
 
insert into Place(id, name, address) values (1, "Quan Sen", "Pasing Arcaden, München");\
28
 
insert into Place(id, name, address) values (2, "Jashan", "Landsberger Straße 84, 82110 Germering");\
29
 
insert into Place(id, name, latitude, longitude) values (3, "Café Moskau", 52.521339, 13.42279);\
30
 
insert into Place(id, name, address) values (4, "Santa Clara Marriott", "2700 Mission College Boulevard, Santa Clara, California");\
31
 
insert into Place(id, name, address) values (5, "embeddedworld", "Messezentrum, 90471 Nürnberg");\
32
 
insert into Event(id, title, message, startTime, endTime) values (1, "Team Meeting", "Bring your gear...", 1364648400000, 1364650200000);\
33
 
insert into Event(id, title, message, startTime, endTime) values (2, "Jane\'s Birthday Party", "this year: southern wine", 1364061600000, 1364068800000);\
34
 
insert into Event(id, title, startTime, endTime) values (3, "embeddedworld 2013", 1361836800000, 1362009600000);\
35
 
insert into Attendance(eventId, contactId, placeId) values (1, 1, 1);\
36
 
insert into Attendance(eventId, contactId, placeId) values (1, 2, 1);\
37
 
insert into Attendance(eventId, contactId, placeId) values (1, 3, 1);\
38
 
insert into Attendance(eventId, contactId, placeId) values (1, 4, 3);\
39
 
insert into Attendance(eventId, contactId, placeId) values (1, 5, 3);\
40
 
insert into Attendance(eventId, contactId) values (2, 1);\
41
 
insert into Attendance(eventId, contactId) values (2, 2);\
42
 
insert into Attendance(eventId, contactId) values (2, 3);\
43
 
insert into Venue(eventId, placeId) values (2, 3);\
44
 
insert into Venue(eventId, placeId) values (3, 5)\
45
 
'.split(';')
46
 
 
47
 
    for (var i = 0; i < inserts.length; ++i) {
48
 
        var sql = inserts[i]
49
 
        if (sql != "") {
50
 
            console.log(sql)
51
 
            tx.executeSql(sql)
52
 
        }
53
 
    }
54
 
}
55
 
 
56
 
function loadTestDataComplex(tx)
57
 
{
58
 
    clearData(tx)
59
 
 
60
 
    function t(d, h, m) {
61
 
        if (typeof t.today == "undefined") t.today = new Date().midnight()
62
 
        return t.today.addDays(d).setHours(h, m)
63
 
    }
64
 
 
65
 
    var places = [
66
 
        { id: 1, name: "Moskau A" },
67
 
        { id: 2, name: "Moskau B" },
68
 
        { id: 3, name: "Bischkek" },
69
 
        { id: 4, name: "Asgabat A" },
70
 
        { id: 5, name: "Asgabat B" },
71
 
        { id: 6, name: "Vilnius" },
72
 
        { id: 7, name: "Riga" }
73
 
    ]
74
 
 
75
 
    var speaker = [
76
 
        { id: 1, name: "Sean", surname: "Harmer" },
77
 
        { id: 2, name: "Marc", surname: "Lutz" },
78
 
        { id: 3, name: "David", surname: "Faure" },
79
 
        { id: 4, name: "Volker", surname: "Krause" },
80
 
        { id: 5, name: "Kevin", surname: "Krammer" },
81
 
        { id: 6, name: "Tobias", surname: "Nätterlund" },
82
 
        { id: 7, name: "Steffen", surname: "Hansen" },
83
 
        { id: 8, name: "Tommi", surname: "Laitinen" },
84
 
        { id: 9, name: "Lars", surname: "Knoll" },
85
 
        { id: 10, name: "Roland", surname: "Krause" },
86
 
        { id: 11, name: "Jens", surname: "Bache-Wiig" },
87
 
        { id: 12, name: "Michael", surname: "Wagner" },
88
 
        { id: 13, name: "Helmut", surname: "Sedding" },
89
 
        { id: 14, name: "Jeff", surname: "Tranter" },
90
 
        { id: 15, name: "Simon", surname: "Hausmann" },
91
 
        { id: 16, name: "Stephen", surname: "Kelly" },
92
 
        { id: 17, name: "Tam", surname: "Hanna" },
93
 
        { id: 18, name: "Mirko", surname: "Boehm" },
94
 
        { id: 19, name: "Till", surname: "Adam" },
95
 
        { id: 20, name: "Thomas", surname: "Senyk" }
96
 
    ]
97
 
 
98
 
    var events = [
99
 
        { id: 1, room: 1, speaker: [ 1 ], title: "Modern OpenGL with Qt5", message: "hands-on training", startTime: t(0, 10, 00), endTime: t(0, 12 ,00) },
100
 
        { id: 2, room: 2, speaker: [ 2 ], title: "What's new in C++11", message: "focus on Qt5", startTime: t(0, 13, 00), endTime: t(0, 14, 30) },
101
 
        { id: 3, room: 3, speaker: [ 3 ], title: "Model/view Programming using Qt", message: "hands-on training", startTime: t(0, 14, 45), endTime: t(0, 16, 15) },
102
 
        { id: 4, room: 4, speaker: [ 4 ], title: "Introduction to Qt Quick", message: "hands-on training", startTime: t(0, 16, 30), endTime: t(0, 17, 45) },
103
 
        { id: 5, room: 1, speaker: [ 8 ], title: "Keynote: Qt – Gearing up for the Future", message: "", startTime: t(1, 9, 15), endTime: t(1, 9, 30) },
104
 
        { id: 6, room: 1, speaker: [ 9 ], title: "Keynote: Qt 5 Roadmap", message: "", startTime: t(1, 9, 30), endTime: t(1, 10, 30) },
105
 
        { id: 7, room: 3, speaker: [ 10 ], title: "Qt and the Google APIs", message: "", startTime: t(1, 10, 45), endTime: t(1, 11, 45) },
106
 
        { id: 8, room: 7, speaker: [ 11 ], title: "Desktop Components for QtQuick", message: "", startTime: t(1, 10, 45), endTime: t(1, 11, 45) },
107
 
        { id: 9, room: 2, speaker: [ 9 ], title: "The Future of Qt on Embedded Linux", message: "", startTime: t(1, 12, 45), endTime: t(1, 13, 45) },
108
 
        { id: 10, room: 7, speaker: [ 12, 13 ], title: "QML for desktop apps", message: "", startTime: t(1, 12, 45), endTime: t(1, 13, 34) },
109
 
        { id: 11, room: 2, speaker: [ 14 ], title: "Qt on Raspberry Pi", message: "", startTime: t(1, 14, 00), endTime: t(1, 15, 00) },
110
 
        { id: 12, room: 3, speaker: [ 15 ], title: "What's new in QtWebKit in 5.0", message: "", startTime: t(1, 14, 00), endTime: t(1, 15, 00) },
111
 
        { id: 13, room: 1, speaker: [ 16 ], title: "In Depth – QMetaType and QMetaObject", message: "", startTime: t(1, 15, 30), endTime: t(1, 16, 30) },
112
 
        { id: 14, room: 2, speaker: [ 17 ], title: "Using Qt as mobile cross-platform system", message: "", startTime: t(1, 15, 30), endTime: t(1, 16, 30) },
113
 
        { id: 15, room: 1, speaker: [ 18, 19 ], title: "Intentions good, warranty void: Using Qt in unexpected ways", message: "", startTime: t(1, 16, 45), endTime: t(1, 17, 45) },
114
 
        { id: 16, room: 2, speaker: [ 20 ], title: "Porting Qt 5 to embedded hardware", message: "", startTime: t(1, 16, 45), endTime: t(1, 17, 45) }
115
 
    ]
116
 
 
117
 
    for (var i = 0; i < places.length; ++i) {
118
 
        var p = places[i]
119
 
        tx.executeSql(
120
 
            'insert into Place(id, name, address) values (?, ?, ?)',
121
 
            [ p.id, p.name, "Cafe Moskau, Berlin, Germany" ]
122
 
        )
123
 
    }
124
 
 
125
 
    for (var i = 0; i < speaker.length; ++i) {
126
 
        var s = speaker[i]
127
 
        tx.executeSql(
128
 
            'insert into Contact(id, name, surname) values (?, ?, ?)',
129
 
            [ s.id, s.name, s.surname ]
130
 
        )
131
 
    }
132
 
 
133
 
    for (var i = 0; i < events.length; ++i) {
134
 
        var e = events[i]
135
 
        tx.executeSql(
136
 
            'insert into Event(id, title, message, startTime, endTime) values (?, ?, ?, ?, ?)',
137
 
            [ e.id, e.title, e.message, e.startTime, e.endTime ]
138
 
        )
139
 
        tx.executeSql(
140
 
            'insert into Venue(eventId, placeId) values (?, ?)',
141
 
            [ e.id, e.room ]
142
 
        )
143
 
        for (var j = 0; j < e.speaker.length; ++j) {
144
 
            tx.executeSql(
145
 
                'insert into Attendance(eventId, contactId) values (?, ?)',
146
 
                [ e.id, e.speaker[j] ]
147
 
            )
148
 
        }
149
 
    }
150
 
}
151
 
 
152
 
function runTestSimple(tx)
153
 
{
154
 
    loadTestDataSimple(tx)
155
 
 
156
 
    var contacts = []
157
 
    DataService.getContacts(contacts)
158
 
    for (var i = 0; i < contacts.length; ++i)
159
 
        DataService.printContact(contacts[i])
160
 
    console.log('')
161
 
 
162
 
    var testEvent = DataService.addEvent({
163
 
        title: 'Critical Review',
164
 
        message: '',
165
 
        startTime: new Date(2013, 2, 30, 10, 00).getTime(),
166
 
        endTime: new Date(2013, 2, 30, 10, 30).getTime()
167
 
    })
168
 
    DataService.addAttendee(testEvent, contacts[1])
169
 
    DataService.addAttendee(testEvent, contacts[2])
170
 
    DataService.addAttendee(testEvent, contacts[0])
171
 
    DataService.removeAttendee(testEvent, contacts[0])
172
 
    var testPlace = DataService.addPlace({ name: 'Jane\'s bar' })
173
 
    DataService.addVenue(testEvent, testPlace)
174
 
    console.log('Added new event with id', testEvent.id)
175
 
    console.log('')
176
 
 
177
 
    var events = []
178
 
    var dayStart = new Date(2013, 2, 30)
179
 
    DataService.getEvents(dayStart.getTime(), dayStart.addDays(1).getTime(), events)
180
 
    for (var i = 0; i < events.length; ++i)
181
 
        DataService.printEvent(events[i])
182
 
 
183
 
    DataService.removeEvent(testEvent)
184
 
    DataService.removePlace(testPlace)
185
 
}
186
 
 
187
 
DataService.db().transaction(
188
 
    function (tx) {
189
 
        runTestSimple(tx)
190
 
        loadTestDataComplex(tx)
191
 
    }
192
 
)