Skip to content

Commit

Permalink
refactor: move MessageBuilder snapshot test to IrcMessageHandler (#5654)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz authored Oct 18, 2024
1 parent 800f6df commit a8d60b0
Show file tree
Hide file tree
Showing 69 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
- Dev: Added more tests for input completion. (#5604)
- Dev: Refactored legacy Unicode zero-width-joiner replacement. (#5594)
- Dev: The JSON output when copying a message (<kbd>SHIFT</kbd> + right-click) is now more extensive. (#5600)
- Dev: Added more tests for message building. (#5598)
- Dev: Added more tests for message building. (#5598, #5654)
- Dev: Twitch messages are now sent using Twitch's Helix API instead of IRC by default. (#5607)
- Dev: `GIFTimer` is no longer initialized in tests. (#5608)
- Dev: Emojis now use flags instead of a set of strings for capabilities. (#5616)
Expand Down
4 changes: 2 additions & 2 deletions src/providers/twitch/TwitchChannel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <optional>
#include <unordered_map>

class TestMessageBuilderP;
class TestIrcMessageHandlerP;

namespace chatterino {

Expand Down Expand Up @@ -464,7 +464,7 @@ class TwitchChannel final : public Channel, public ChannelChatters
friend class MessageBuilder;
friend class IrcMessageHandler;
friend class Commands_E2E_Test;
friend class ::TestMessageBuilderP;
friend class ::TestIrcMessageHandlerP;
};

} // namespace chatterino
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set(test_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/UtilTwitch.cpp
${CMAKE_CURRENT_LIST_DIR}/src/IrcHelpers.cpp
${CMAKE_CURRENT_LIST_DIR}/src/TwitchPubSubClient.cpp
${CMAKE_CURRENT_LIST_DIR}/src/MessageBuilder.cpp
${CMAKE_CURRENT_LIST_DIR}/src/IrcMessageHandler.cpp
${CMAKE_CURRENT_LIST_DIR}/src/HighlightController.cpp
${CMAKE_CURRENT_LIST_DIR}/src/FormatTime.cpp
${CMAKE_CURRENT_LIST_DIR}/src/LimitedQueue.cpp
Expand Down
File renamed without changes.
File renamed without changes.
17 changes: 8 additions & 9 deletions tests/src/MessageBuilder.cpp → tests/src/IrcMessageHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/IrcMessageHandler.hpp"

#include "common/Literals.hpp"
#include "controllers/accounts/AccountController.hpp"
Expand All @@ -20,7 +20,6 @@
#include "providers/seventv/SeventvBadges.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/ChannelPointReward.hpp"
#include "providers/twitch/IrcMessageHandler.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchBadge.hpp"
#include "providers/twitch/TwitchBadges.hpp"
Expand Down Expand Up @@ -56,7 +55,7 @@ namespace {
/// to generate an initial snapshot. Make sure to verify the output!
constexpr bool UPDATE_SNAPSHOTS = false;

const QString IRC_CATEGORY = u"MessageBuilder/IRC"_s;
const QString IRC_CATEGORY = u"IrcMessageHandler"_s;

class MockApplication : public mock::BaseApplication
{
Expand Down Expand Up @@ -447,12 +446,12 @@ QT_WARNING_POP

} // namespace

class TestMessageBuilderP : public ::testing::TestWithParam<QString>
class TestIrcMessageHandlerP : public ::testing::TestWithParam<QString>
{
public:
void SetUp() override
{
auto param = TestMessageBuilderP::GetParam();
auto param = TestIrcMessageHandlerP::GetParam();
this->snapshot = testlib::Snapshot::read(IRC_CATEGORY, param);

this->mockApplication =
Expand Down Expand Up @@ -558,7 +557,7 @@ class TestMessageBuilderP : public ::testing::TestWithParam<QString>
/// `IrcMesssageHandler` to ensure the correct (or: "real") arguments to build
/// messages.
///
/// Tests are contained in `tests/snapshots/MessageBuilder/IRC`. Fixtures
/// Tests are contained in `tests/snapshots/IrcMessageHandler`. Fixtures
/// consist of an object with the keys `input`, `output`, `settings` (optional),
/// and `params` (optional).
///
Expand All @@ -569,7 +568,7 @@ class TestMessageBuilderP : public ::testing::TestWithParam<QString>
/// - `prevMessages`: An array of past messages (used for replies)
/// - `findAllUsernames`: A boolean controlling the equally named setting
/// (default: false)
TEST_P(TestMessageBuilderP, Run)
TEST_P(TestIrcMessageHandlerP, Run)
{
auto channel = makeMockTwitchChannel(u"pajlada"_s, *snapshot);

Expand Down Expand Up @@ -608,10 +607,10 @@ TEST_P(TestMessageBuilderP, Run)
}

INSTANTIATE_TEST_SUITE_P(
IrcMessage, TestMessageBuilderP,
IrcMessage, TestIrcMessageHandlerP,
testing::ValuesIn(testlib::Snapshot::discover(IRC_CATEGORY)));

TEST(TestMessageBuilderP, Integrity)
TEST(TestIrcMessageHandlerP, Integrity)
{
ASSERT_FALSE(UPDATE_SNAPSHOTS); // make sure fixtures are actually tested
}

0 comments on commit a8d60b0

Please sign in to comment.