Add test for invite action
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
#include <QSignalSpy>
|
||||||
|
#include <QVariantList>
|
||||||
|
|
||||||
#include "chatbarcache.h"
|
#include "chatbarcache.h"
|
||||||
#include "models/actionsmodel.h"
|
#include "models/actionsmodel.h"
|
||||||
@@ -11,6 +13,8 @@
|
|||||||
|
|
||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
|
|
||||||
|
//TODO: rainbow, rainbowme, plain, spoiler, me, join, knock, j, part, leave, nick, roomnick, myroomnick, ignore, unignore, react, ban, unban, kick
|
||||||
|
|
||||||
class ActionsTest : public QObject
|
class ActionsTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -19,10 +23,13 @@ private:
|
|||||||
Connection *connection = nullptr;
|
Connection *connection = nullptr;
|
||||||
TestUtils::TestRoom *room = nullptr;
|
TestUtils::TestRoom *room = nullptr;
|
||||||
|
|
||||||
|
void expectMessage(const QString &actionName, const QString &args, MessageType::Type type, const QString &message);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void testActions();
|
void testActions();
|
||||||
void testActions_data();
|
void testActions_data();
|
||||||
|
void testInvite();
|
||||||
};
|
};
|
||||||
|
|
||||||
void ActionsTest::initTestCase()
|
void ActionsTest::initTestCase()
|
||||||
@@ -51,6 +58,9 @@ void ActionsTest::testActions_data()
|
|||||||
QTest::newRow("me") << u"/me Hello"_s << std::make_optional(u"Hello"_s) << std::make_optional(Quotient::RoomMessageEvent::MsgType::Emote);
|
QTest::newRow("me") << u"/me Hello"_s << std::make_optional(u"Hello"_s) << std::make_optional(Quotient::RoomMessageEvent::MsgType::Emote);
|
||||||
QTest::newRow("notice") << u"/notice Hello"_s << std::make_optional(u"Hello"_s) << std::make_optional(Quotient::RoomMessageEvent::MsgType::Notice);
|
QTest::newRow("notice") << u"/notice Hello"_s << std::make_optional(u"Hello"_s) << std::make_optional(Quotient::RoomMessageEvent::MsgType::Notice);
|
||||||
QTest::newRow("message") << u"Hello"_s << std::make_optional(u"Hello"_s) << std::make_optional(Quotient::RoomMessageEvent::MsgType::Text);
|
QTest::newRow("message") << u"Hello"_s << std::make_optional(u"Hello"_s) << std::make_optional(Quotient::RoomMessageEvent::MsgType::Text);
|
||||||
|
QTest::newRow("invite") << u"/invite @foo:example.com"_s << std::optional<QString>() << std::optional<Quotient::RoomMessageEvent::MsgType>();
|
||||||
|
|
||||||
|
//TODO: join, knock, j, part, leave, nick, roomnick, myroomnick, ignore, unignore, react, ban, unban, kick
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionsTest::testActions()
|
void ActionsTest::testActions()
|
||||||
@@ -66,5 +76,45 @@ void ActionsTest::testActions()
|
|||||||
QCOMPARE(type, std::get<std::optional<Quotient::RoomMessageEvent::MsgType>>(result));
|
QCOMPARE(type, std::get<std::optional<Quotient::RoomMessageEvent::MsgType>>(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ActionsModel::Action findAction(const QString &name)
|
||||||
|
{
|
||||||
|
for (const auto &action : ActionsModel::allActions()) {
|
||||||
|
if (action.prefix == name) {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionsTest::expectMessage(const QString &actionName, const QString &args, MessageType::Type type, const QString &message)
|
||||||
|
{
|
||||||
|
auto action = findAction(actionName);
|
||||||
|
QSignalSpy spy(room, &TestUtils::TestRoom::showMessage);
|
||||||
|
auto result = action.handle(args, room, nullptr);
|
||||||
|
auto expected = QVariantList {type, message};
|
||||||
|
auto signal = spy.takeFirst();
|
||||||
|
QCOMPARE(signal, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionsTest::testInvite()
|
||||||
|
{
|
||||||
|
expectMessage(u"invite"_s, u"foo"_s, MessageType::Error, u"'foo' does not look like a matrix id."_s);
|
||||||
|
expectMessage(u"invite"_s, u"@invited:example.com"_s, MessageType::Information, u"@invited:example.com is already invited to this room."_s);
|
||||||
|
QCOMPARE(room->memberState(u"@invited:example.com"_s), Membership::Invite);
|
||||||
|
expectMessage(u"invite"_s, u"@banned:example.com"_s, MessageType::Information, u"@banned:example.com is banned from this room."_s);
|
||||||
|
QCOMPARE(room->memberState(u"@banned:example.com"_s), Membership::Ban);
|
||||||
|
expectMessage(u"invite"_s, connection->userId(), MessageType::Positive, u"You are already in this room."_s);
|
||||||
|
QCOMPARE(room->memberState(connection->userId()), Membership::Join);
|
||||||
|
expectMessage(u"invite"_s, u"@example:example.org"_s, MessageType::Information, u"@example:example.org is already in this room."_s);
|
||||||
|
QCOMPARE(room->memberState(u"@example:example.org"_s), Membership::Join);
|
||||||
|
|
||||||
|
QCOMPARE(room->memberState(u"@user:example.com"_s), Membership::Leave);
|
||||||
|
expectMessage(u"invite"_s, u"@user:example.com"_s, MessageType::Positive, u"@user:example.com was invited into this room."_s);
|
||||||
|
|
||||||
|
//TODO mock server, wait for invite state to change
|
||||||
|
//TODO QCOMPARE(room->memberState(u"@user:example.com"_s), Membership::Invite);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(ActionsTest)
|
QTEST_MAIN(ActionsTest)
|
||||||
#include "actionstest.moc"
|
#include "actionstest.moc"
|
||||||
|
|||||||
@@ -49,6 +49,51 @@
|
|||||||
"unsigned": {
|
"unsigned": {
|
||||||
"age": 1234
|
"age": 1234
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": {
|
||||||
|
"displayname": "Bob",
|
||||||
|
"membership": "join"
|
||||||
|
},
|
||||||
|
"event_id": "$143273blorb3PhrSn:example.org",
|
||||||
|
"origin_server_ts": 1432735824653,
|
||||||
|
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
|
||||||
|
"sender": "@bob:kde.org",
|
||||||
|
"state_key": "@bob:kde.org",
|
||||||
|
"type": "m.room.member",
|
||||||
|
"unsigned": {
|
||||||
|
"age": 1234
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": {
|
||||||
|
"displayname": "Invited",
|
||||||
|
"membership": "invite"
|
||||||
|
},
|
||||||
|
"event_id": "$asdfpj443PhrSn:example.org",
|
||||||
|
"origin_server_ts": 1432735824653,
|
||||||
|
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
|
||||||
|
"sender": "@example:example.org",
|
||||||
|
"state_key": "@invited:example.com",
|
||||||
|
"type": "m.room.member",
|
||||||
|
"unsigned": {
|
||||||
|
"age": 1234
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": {
|
||||||
|
"displayname": "Banned",
|
||||||
|
"membership": "ban"
|
||||||
|
},
|
||||||
|
"event_id": "$asdfpj443PhrSnasfd:example.org",
|
||||||
|
"origin_server_ts": 1432735824653,
|
||||||
|
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
|
||||||
|
"sender": "@banned:example.com",
|
||||||
|
"state_key": "@banned:example.com",
|
||||||
|
"type": "m.room.member",
|
||||||
|
"unsigned": {
|
||||||
|
"age": 1234
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -57,7 +102,7 @@
|
|||||||
"@alice:example.com",
|
"@alice:example.com",
|
||||||
"@bob:example.com"
|
"@bob:example.com"
|
||||||
],
|
],
|
||||||
"m.invited_member_count": 0,
|
"m.invited_member_count": 1,
|
||||||
"m.joined_member_count": 2
|
"m.joined_member_count": 2
|
||||||
},
|
},
|
||||||
"timeline": {
|
"timeline": {
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ QList<ActionsModel::Action> actions{
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
room->inviteToRoom(text);
|
room->inviteToRoom(text);
|
||||||
Q_EMIT room->showMessage(MessageType::Positive, i18nc("<username> was invited into this room", "%1 was invited into this room", text));
|
Q_EMIT room->showMessage(MessageType::Positive, i18nc("<username> was invited into this room.", "%1 was invited into this room.", text));
|
||||||
return QString();
|
return QString();
|
||||||
},
|
},
|
||||||
std::nullopt,
|
std::nullopt,
|
||||||
@@ -538,7 +538,7 @@ QHash<int, QByteArray> ActionsModel::roleNames() const
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Action> &ActionsModel::allActions() const
|
QList<Action> &ActionsModel::allActions()
|
||||||
{
|
{
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Return a vector with all supported actions.
|
* @brief Return a vector with all supported actions.
|
||||||
*/
|
*/
|
||||||
QList<Action> &allActions() const;
|
static QList<Action> &allActions();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Handle special sed style edit action.
|
* @brief Handle special sed style edit action.
|
||||||
|
|||||||
Reference in New Issue
Block a user