64
69
QTRY_VERIFY(fetchMoreChanged.count() >= 1);
65
70
QVERIFY(!model.canFetchMore());
72
QTRY_COMPARE(model.rowCount(), 1);
73
mManager->removeThreads(History::Threads() << textThread);
74
QTRY_COMPARE(model.rowCount(), 0);
77
void HistoryGroupedThreadsModelTest::testThreadsUpdated()
79
HistoryGroupedThreadsModel model;
80
QSignalSpy dataChanged(&model, SIGNAL(dataChanged(QModelIndex, QModelIndex)));
81
QSignalSpy rowsRemoved(&model, SIGNAL(rowsRemoved(QModelIndex, int, int)));
83
HistoryQmlFilter *filter = new HistoryQmlFilter(this);
84
model.setFilter(filter);
85
model.setGroupingProperty(History::FieldParticipants);
87
HistoryQmlSort *sort = new HistoryQmlSort(this);
88
sort->setSortOrder(HistoryQmlSort::DescendingOrder);
89
sort->setSortField("lastEventTimestamp");
92
// force updateQuery() to be called
93
model.componentComplete();
95
// create first thread
96
History::Thread textThread = mManager->threadForParticipants("ofono/ofono/account0",
97
History::EventTypeText,
98
QStringList() << QString("1234567"),
99
History::MatchPhoneNumber, true);
102
History::TextEvent firstEvent = History::TextEvent(textThread.accountId(), textThread.threadId(), QString("eventId1%1").arg(QString::number(qrand() % 1024)),
103
QString("1234567"), QDateTime::currentDateTime(), false, "Random Message",
104
History::MessageTypeText);
105
mManager->writeEvents(History::Events() << firstEvent);
106
QTRY_COMPARE(dataChanged.count(), 1);
108
QModelIndex firstIndex = dataChanged.first().first().value<QModelIndex>();
109
QString lastEventMessage = model.data(firstIndex, HistoryThreadModel::LastEventTextMessageRole).toString();
110
QCOMPARE(QString("Random Message"), lastEventMessage);
113
// create another thread to be grouped, but using another kind of account
114
textThread = mManager->threadForParticipants("multimedia/multimedia/account1",
115
History::EventTypeText,
116
QStringList() << QString("1234567"),
117
History::MatchPhoneNumber, true);
119
QTRY_COMPARE(dataChanged.count(), 1);
120
QModelIndex index = dataChanged.first().first().value<QModelIndex>();
121
QCOMPARE(firstIndex, index);
124
// insert another event in second thread
125
History::TextEvent secondEvent = History::TextEvent(textThread.accountId(), textThread.threadId(), QString("eventId2%1").arg(QString::number(qrand() % 1024)),
126
QString("1234567"), QDateTime::currentDateTime(), false, "Random Message2",
127
History::MessageTypeText);
128
mManager->writeEvents(History::Events() << secondEvent);
129
QTRY_COMPARE(dataChanged.count(), 1);
131
// make sure the index is the same, meaning both threads are grouped
132
index = dataChanged.first().first().value<QModelIndex>();
133
QCOMPARE(firstIndex, index);
135
// check if latest message is from the second event
136
lastEventMessage = model.data(index, HistoryThreadModel::LastEventTextMessageRole).toString();
138
// check if count is correct given that we have two threads grouped with one message in each
139
QCOMPARE(model.data(index, HistoryThreadModel::CountRole).toInt(), 2);
140
QCOMPARE(QString("Random Message2"), lastEventMessage);
143
// delete latest event and make sure the text displayed is from the first thread again
144
mManager->removeEvents(History::Events() << secondEvent);
145
QTRY_COMPARE(dataChanged.count(), 1);
146
index = dataChanged.first().first().value<QModelIndex>();
147
QCOMPARE(firstIndex, index);
148
lastEventMessage = model.data(index, HistoryThreadModel::LastEventTextMessageRole).toString();
149
QCOMPARE(QString("Random Message"), lastEventMessage);
150
// check if count is correct given that we have only one thread now
151
QCOMPARE(model.data(index, HistoryThreadModel::CountRole).toInt(), 1);
153
// delete first event and make sure the model is cleared
154
mManager->removeEvents(History::Events() << firstEvent);
155
QTRY_COMPARE(rowsRemoved.count(), 1);
156
QTRY_COMPARE(model.rowCount(), 0);
68
159
QTEST_MAIN(HistoryGroupedThreadsModelTest)