mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com> Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com>
171 lines
4.6 KiB
C++
171 lines
4.6 KiB
C++
#include "widgets/splits/SplitInput.hpp"
|
|
|
|
#include "common/Literals.hpp"
|
|
#include "controllers/accounts/AccountController.hpp"
|
|
#include "controllers/commands/Command.hpp"
|
|
#include "controllers/commands/CommandController.hpp"
|
|
#include "controllers/hotkeys/HotkeyController.hpp"
|
|
#include "mocks/EmptyApplication.hpp"
|
|
#include "singletons/Emotes.hpp"
|
|
#include "singletons/Fonts.hpp"
|
|
#include "singletons/Paths.hpp"
|
|
#include "singletons/Theme.hpp"
|
|
#include "singletons/WindowManager.hpp"
|
|
#include "widgets/Notebook.hpp"
|
|
#include "widgets/splits/Split.hpp"
|
|
|
|
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
#include <QDebug>
|
|
#include <QString>
|
|
|
|
using namespace chatterino;
|
|
using ::testing::Exactly;
|
|
|
|
namespace {
|
|
|
|
class MockApplication : mock::EmptyApplication
|
|
{
|
|
public:
|
|
MockApplication()
|
|
: windowManager(this->paths)
|
|
{
|
|
}
|
|
Theme *getThemes() override
|
|
{
|
|
return &this->theme;
|
|
}
|
|
|
|
HotkeyController *getHotkeys() override
|
|
{
|
|
return &this->hotkeys;
|
|
}
|
|
|
|
Fonts *getFonts() override
|
|
{
|
|
return &this->fonts;
|
|
}
|
|
|
|
WindowManager *getWindows() override
|
|
{
|
|
return &this->windowManager;
|
|
}
|
|
|
|
AccountController *getAccounts() override
|
|
{
|
|
return &this->accounts;
|
|
}
|
|
|
|
CommandController *getCommands() override
|
|
{
|
|
return &this->commands;
|
|
}
|
|
|
|
IEmotes *getEmotes() override
|
|
{
|
|
return &this->emotes;
|
|
}
|
|
|
|
Theme theme;
|
|
HotkeyController hotkeys;
|
|
Fonts fonts;
|
|
Paths paths;
|
|
WindowManager windowManager;
|
|
AccountController accounts;
|
|
CommandController commands;
|
|
Emotes emotes;
|
|
};
|
|
|
|
class SplitInputTest
|
|
: public ::testing::TestWithParam<std::tuple<QString, QString>>
|
|
{
|
|
public:
|
|
SplitInputTest()
|
|
: split(new Split(nullptr))
|
|
, input(this->split)
|
|
{
|
|
}
|
|
|
|
MockApplication mockApplication;
|
|
Split *split;
|
|
SplitInput input;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST_P(SplitInputTest, Reply)
|
|
{
|
|
std::tuple<QString, QString> params = this->GetParam();
|
|
auto [inputText, expected] = params;
|
|
ASSERT_EQ("", this->input.getInputText());
|
|
this->input.setInputText(inputText);
|
|
ASSERT_EQ(inputText, this->input.getInputText());
|
|
|
|
auto *message = new Message();
|
|
message->displayName = "forsen";
|
|
auto reply = MessagePtr(message);
|
|
this->input.setReply(reply);
|
|
QString actual = this->input.getInputText();
|
|
ASSERT_EQ(expected, actual)
|
|
<< "Input text after setReply should be '" << qUtf8Printable(expected)
|
|
<< "', but got '" << qUtf8Printable(actual) << "'";
|
|
}
|
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
|
SplitInput, SplitInputTest,
|
|
testing::Values(
|
|
// Ensure message is retained
|
|
std::make_tuple<QString, QString>(
|
|
// Pre-existing text in the input
|
|
"Test message",
|
|
// Expected text after replying to forsen
|
|
"@forsen Test message "),
|
|
|
|
// Ensure mention is stripped, no message
|
|
std::make_tuple<QString, QString>(
|
|
// Pre-existing text in the input
|
|
"@forsen",
|
|
// Expected text after replying to forsen
|
|
"@forsen "),
|
|
|
|
// Ensure mention with space is stripped, no message
|
|
std::make_tuple<QString, QString>(
|
|
// Pre-existing text in the input
|
|
"@forsen ",
|
|
// Expected text after replying to forsen
|
|
"@forsen "),
|
|
|
|
// Ensure mention is stripped, retain message
|
|
std::make_tuple<QString, QString>(
|
|
// Pre-existing text in the input
|
|
"@forsen Test message",
|
|
// Expected text after replying to forsen
|
|
"@forsen Test message "),
|
|
|
|
// Ensure mention with comma is stripped, no message
|
|
std::make_tuple<QString, QString>(
|
|
// Pre-existing text in the input
|
|
"@forsen,",
|
|
// Expected text after replying to forsen
|
|
"@forsen "),
|
|
|
|
// Ensure mention with comma is stripped, retain message
|
|
std::make_tuple<QString, QString>(
|
|
// Pre-existing text in the input
|
|
"@forsen Test message",
|
|
// Expected text after replying to forsen
|
|
"@forsen Test message "),
|
|
|
|
// Ensure mention with comma and space is stripped, no message
|
|
std::make_tuple<QString, QString>(
|
|
// Pre-existing text in the input
|
|
"@forsen, ",
|
|
// Expected text after replying to forsen
|
|
"@forsen "),
|
|
|
|
// Ensure it works with no message
|
|
std::make_tuple<QString, QString>(
|
|
// Pre-existing text in the input
|
|
"",
|
|
// Expected text after replying to forsen
|
|
"@forsen ")));
|