2024-03-17 14:43:55 +01:00
|
|
|
#include "messages/layouts/MessageLayout.hpp"
|
|
|
|
|
|
|
|
#include "Application.hpp"
|
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
|
|
|
#include "messages/MessageBuilder.hpp"
|
|
|
|
#include "messages/MessageElement.hpp"
|
2024-07-21 15:09:59 +02:00
|
|
|
#include "mocks/BaseApplication.hpp"
|
2024-03-17 14:43:55 +01:00
|
|
|
#include "singletons/Emotes.hpp"
|
|
|
|
#include "singletons/Fonts.hpp"
|
|
|
|
#include "singletons/Settings.hpp"
|
|
|
|
#include "singletons/Theme.hpp"
|
|
|
|
#include "singletons/WindowManager.hpp"
|
2024-05-05 15:01:07 +02:00
|
|
|
#include "Test.hpp"
|
2024-03-17 14:43:55 +01:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
using namespace chatterino;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
class MockApplication : mock::BaseApplication
|
2024-03-17 14:43:55 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
MockApplication()
|
2024-07-21 15:09:59 +02:00
|
|
|
: theme(this->paths_)
|
2024-03-17 14:43:55 +01:00
|
|
|
, fonts(this->settings)
|
|
|
|
, windowManager(this->paths_)
|
|
|
|
{
|
|
|
|
}
|
2024-07-21 15:09:59 +02:00
|
|
|
|
2024-03-17 14:43:55 +01:00
|
|
|
Theme *getThemes() override
|
|
|
|
{
|
|
|
|
return &this->theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
Fonts *getFonts() override
|
|
|
|
{
|
|
|
|
return &this->fonts;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowManager *getWindows() override
|
|
|
|
{
|
|
|
|
return &this->windowManager;
|
|
|
|
}
|
|
|
|
|
2024-07-21 15:09:59 +02:00
|
|
|
AccountController *getAccounts() override
|
|
|
|
{
|
|
|
|
return &this->accounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountController accounts;
|
2024-03-17 14:43:55 +01:00
|
|
|
Theme theme;
|
|
|
|
Fonts fonts;
|
|
|
|
WindowManager windowManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr int WIDTH = 300;
|
|
|
|
|
|
|
|
class MessageLayoutTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// "aaaaaaaa bbbbbbbb cccccccc"
|
|
|
|
MessageLayoutTest(const QString &text)
|
|
|
|
{
|
|
|
|
MessageBuilder builder;
|
|
|
|
builder.append(
|
|
|
|
std::make_unique<TextElement>(text, MessageElementFlag::Text));
|
|
|
|
this->layout = std::make_unique<MessageLayout>(builder.release());
|
2024-05-12 13:59:14 +02:00
|
|
|
this->layout->layout(WIDTH, 1, 1, MessageElementFlag::Text, false);
|
2024-03-17 14:43:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MockApplication mockApplication;
|
|
|
|
std::unique_ptr<MessageLayout> layout;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(TextElement, BasicCase)
|
|
|
|
{
|
|
|
|
auto test = MessageLayoutTest("abc");
|
|
|
|
|
|
|
|
// Simulate we are clicking on the first word
|
|
|
|
auto point = QPoint(WIDTH / 20, test.layout->getHeight() / 2);
|
|
|
|
|
|
|
|
const auto *hoveredElement = test.layout->getElementAt(point);
|
|
|
|
ASSERT_NE(hoveredElement, nullptr);
|
|
|
|
|
|
|
|
const auto [wordStart, wordEnd] =
|
|
|
|
test.layout->getWordBounds(hoveredElement, point);
|
|
|
|
|
|
|
|
EXPECT_EQ(wordStart, 0);
|
|
|
|
EXPECT_EQ(wordEnd, 3);
|
|
|
|
}
|