test: add snapshot tests for MessageBuilder (#5598)
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "providers/chatterino/ChatterinoBadges.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace chatterino::mock {
|
||||
|
||||
class ChatterinoBadges : public IChatterinoBadges
|
||||
@@ -9,9 +11,21 @@ class ChatterinoBadges : public IChatterinoBadges
|
||||
public:
|
||||
std::optional<EmotePtr> getBadge(const UserId &id) override
|
||||
{
|
||||
(void)id;
|
||||
auto it = this->users.find(id);
|
||||
if (it != this->users.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void setBadge(UserId id, EmotePtr emote)
|
||||
{
|
||||
this->users.emplace(std::move(id), std::move(emote));
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<UserId, EmotePtr> users;
|
||||
};
|
||||
|
||||
} // namespace chatterino::mock
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
#include "providers/seventv/eventapi/Dispatch.hpp"
|
||||
#include "providers/seventv/eventapi/Message.hpp"
|
||||
#include "providers/seventv/SeventvEmotes.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace chatterino::mock {
|
||||
|
||||
class MockTwitchIrcServer : public ITwitchIrcServer
|
||||
@@ -67,7 +70,30 @@ public:
|
||||
std::shared_ptr<Channel> getChannelOrEmptyByID(
|
||||
const QString &channelID) override
|
||||
{
|
||||
return {};
|
||||
// XXX: this is the same as in TwitchIrcServer::getChannelOrEmptyByID
|
||||
for (const auto &[name, weakChannel] : this->mockChannels)
|
||||
{
|
||||
auto channel = weakChannel.lock();
|
||||
if (!channel)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto twitchChannel =
|
||||
std::dynamic_pointer_cast<TwitchChannel>(channel);
|
||||
if (!twitchChannel)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (twitchChannel->roomId() == channelID &&
|
||||
twitchChannel->getName().count(':') < 2)
|
||||
{
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
|
||||
return Channel::getEmpty();
|
||||
}
|
||||
|
||||
void dropSeventvChannel(const QString &userID,
|
||||
@@ -123,6 +149,8 @@ public:
|
||||
ChannelPtr liveChannel;
|
||||
ChannelPtr automodChannel;
|
||||
QString lastUserThatWhisperedMe{"forsen"};
|
||||
|
||||
std::unordered_map<QString, std::weak_ptr<Channel>> mockChannels;
|
||||
};
|
||||
|
||||
} // namespace chatterino::mock
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "controllers/userdata/UserDataController.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace chatterino::mock {
|
||||
|
||||
class UserDataController : public IUserDataController
|
||||
@@ -13,6 +15,11 @@ public:
|
||||
// If the user does not have any extra data, return none
|
||||
std::optional<UserData> getUser(const QString &userID) const override
|
||||
{
|
||||
auto it = this->userMap.find(userID);
|
||||
if (it != this->userMap.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -20,8 +27,21 @@ public:
|
||||
void setUserColor(const QString &userID,
|
||||
const QString &colorString) override
|
||||
{
|
||||
// do nothing
|
||||
auto it = this->userMap.find(userID);
|
||||
if (it != this->userMap.end())
|
||||
{
|
||||
it->second.color = QColor(colorString);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->userMap.emplace(userID, UserData{
|
||||
.color = QColor(colorString),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<QString, UserData> userMap;
|
||||
};
|
||||
|
||||
} // namespace chatterino::mock
|
||||
|
||||
Reference in New Issue
Block a user