Exercise valid and stale channel menu actions
This commit is contained in:
1 parent
1e3633ee56
commit
842083cdeb
1 file changed
+31
-6
@@ -54,6 +54,7 @@ private slots:
|
||||
ChannelList list(&core.db); list.loadChannels();
|
||||
auto* view = list.findChild<QListView*>(); QVERIFY(view);
|
||||
list.setChannelPeersOnline(core.channel, 3);
|
||||
list.setChannelPeersOnline(core.channel, -1);
|
||||
list.setAutoConnectActive(true);
|
||||
list.loadChannels();
|
||||
QCOMPARE(view->currentIndex().data(ChannelPeersOnlineRole).toInt(), 3);
|
||||
@@ -74,6 +75,9 @@ private slots:
|
||||
QCOMPARE(changes.count(), 1);
|
||||
list.setChannelUnreadCount(core.channel, 7);
|
||||
QCOMPARE(changes.count(), 1);
|
||||
list.setChannelUnreadCount(core.channel, -1);
|
||||
QCOMPARE(list.getChannelUnreadCount(core.channel), 7);
|
||||
QCOMPARE(changes.count(), 1);
|
||||
}
|
||||
|
||||
void presenceRequestsAreCancelledWithoutLeaks() {
|
||||
@@ -95,21 +99,42 @@ private slots:
|
||||
QCOMPARE(u_get_allocated_count(), allocations);
|
||||
}
|
||||
|
||||
void menuRejectsChangedDmGeneration() {
|
||||
void menuAction_data() {
|
||||
QTest::addColumn<bool>("dm"); QTest::addColumn<int>("change");
|
||||
QTest::newRow("group-current") << false << 0;
|
||||
QTest::newRow("group-removed") << false << 1;
|
||||
QTest::newRow("pm-current") << true << 0;
|
||||
QTest::newRow("pm-removed") << true << 1;
|
||||
QTest::newRow("pm-generation-changed") << true << 2;
|
||||
QTest::newRow("pm-deletion-started") << true << 3;
|
||||
}
|
||||
|
||||
void menuAction() {
|
||||
QFETCH(bool, dm); QFETCH(int, change);
|
||||
ListCore core; QVERIFY(core.start());
|
||||
ChannelList list(&core.db); list.loadChannels(); list.resize(300, 400); list.show();
|
||||
const auto dm = core.db.getDmConversations()[0];
|
||||
list.selectChannel("dm:" + dm.convId);
|
||||
const auto conversation = core.db.getDmConversations()[0];
|
||||
const QString target = dm ? "dm:" + conversation.convId : core.channel;
|
||||
list.selectChannel(target);
|
||||
auto* view = list.findChild<QListView*>(); QVERIFY(view);
|
||||
QSignalSpy removed(&list, &ChannelList::dmDeleteRequested);
|
||||
QSignalSpy files(&list, &ChannelList::filesRequested);
|
||||
QTimer::singleShot(0, &list, [&] {
|
||||
auto* menu = qobject_cast<QMenu*>(QApplication::activePopupWidget()); QVERIFY(menu);
|
||||
auto* action = menu->findChild<QAction*>("deleteDmAction"); QVERIFY(action && action->isEnabled());
|
||||
view->model()->setData(view->currentIndex(), QVariant::fromValue(dm.generation + 1), ChannelDmGenerationRole);
|
||||
QCOMPARE(menu->actions().size(), 1); QVERIFY(menu->actions()[0]->isEnabled());
|
||||
if (change == 1) view->model()->removeRow(view->currentIndex().row());
|
||||
if (change == 2)
|
||||
view->model()->setData(view->currentIndex(), QVariant::fromValue(conversation.generation + 1), ChannelDmGenerationRole);
|
||||
if (change == 3) list.setDmDeleting(conversation.convId, conversation.generation, true);
|
||||
QTest::keyClick(menu, Qt::Key_Down); QTest::keyClick(menu, Qt::Key_Return);
|
||||
});
|
||||
view->customContextMenuRequested(view->visualRect(view->currentIndex()).center());
|
||||
QVERIFY(removed.isEmpty());
|
||||
QCOMPARE(removed.count(), int(dm && !change));
|
||||
QCOMPARE(files.count(), int(!dm && !change));
|
||||
if (dm && !change) {
|
||||
QCOMPARE(removed[0][0].toString(), conversation.convId);
|
||||
QCOMPARE(removed[0][1].toULongLong(), conversation.generation);
|
||||
} else if (!dm && !change) QCOMPARE(files[0][0].toString(), target);
|
||||
}
|
||||
|
||||
void menuSurvivesOwnerDeletion() {
|
||||
|
||||
Reference in new issue
Block a user