mirror-chatterino2/tests/src/NotebookTab.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

123 lines
3.6 KiB
C++
Raw Normal View History

#include "widgets/helper/NotebookTab.hpp"
#include "common/Literals.hpp"
#include "controllers/hotkeys/HotkeyController.hpp"
#include "gmock/gmock.h"
#include "mocks/EmptyApplication.hpp"
#include "singletons/Fonts.hpp"
#include "singletons/Theme.hpp"
#include "widgets/Notebook.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:
Theme *getThemes() override
{
return &this->theme;
}
HotkeyController *getHotkeys() override
{
return &this->hotkeys;
}
Fonts *getFonts() override
{
return &this->fonts;
}
Theme theme;
HotkeyController hotkeys;
Fonts fonts;
};
class MockNotebookTab : public NotebookTab
{
public:
explicit MockNotebookTab(Notebook *notebook)
: NotebookTab(notebook)
{
}
MOCK_METHOD(void, update, (), (override));
};
class NotebookTabFixture : public ::testing::Test
{
protected:
NotebookTabFixture()
: notebook(nullptr)
, tab(&this->notebook)
{
}
MockApplication mockApplication;
Notebook notebook;
MockNotebookTab tab;
};
} // namespace
/// The highlight state must settable
TEST_F(NotebookTabFixture, SetHighlightState)
{
EXPECT_CALL(this->tab, update).Times(Exactly(1));
EXPECT_EQ(this->tab.highlightState(), HighlightState::None);
this->tab.setHighlightState(HighlightState::NewMessage);
EXPECT_EQ(this->tab.highlightState(), HighlightState::NewMessage);
}
/// The highlight state must be able to "upgrade" from NewMessage to Highlighted
TEST_F(NotebookTabFixture, UpgradeHighlightState)
{
EXPECT_CALL(this->tab, update).Times(Exactly(2));
EXPECT_EQ(this->tab.highlightState(), HighlightState::None);
this->tab.setHighlightState(HighlightState::NewMessage);
EXPECT_EQ(this->tab.highlightState(), HighlightState::NewMessage);
this->tab.setHighlightState(HighlightState::Highlighted);
EXPECT_EQ(this->tab.highlightState(), HighlightState::Highlighted);
}
/// The highlight state must stay as NewMessage when called twice
TEST_F(NotebookTabFixture, SameHighlightStateNewMessage)
{
EXPECT_CALL(this->tab, update).Times(Exactly(1));
EXPECT_EQ(this->tab.highlightState(), HighlightState::None);
this->tab.setHighlightState(HighlightState::NewMessage);
EXPECT_EQ(this->tab.highlightState(), HighlightState::NewMessage);
this->tab.setHighlightState(HighlightState::NewMessage);
EXPECT_EQ(this->tab.highlightState(), HighlightState::NewMessage);
}
/// The highlight state must stay as Highlighted when called twice, and must not call update more than once
TEST_F(NotebookTabFixture, SameHighlightStateHighlighted)
{
EXPECT_CALL(this->tab, update).Times(Exactly(1));
EXPECT_EQ(this->tab.highlightState(), HighlightState::None);
this->tab.setHighlightState(HighlightState::Highlighted);
EXPECT_EQ(this->tab.highlightState(), HighlightState::Highlighted);
this->tab.setHighlightState(HighlightState::Highlighted);
EXPECT_EQ(this->tab.highlightState(), HighlightState::Highlighted);
}
/// The highlight state must not downgrade from Highlighted to NewMessage
TEST_F(NotebookTabFixture, DontDowngradeHighlightState)
{
EXPECT_CALL(this->tab, update).Times(Exactly(1));
EXPECT_EQ(this->tab.highlightState(), HighlightState::None);
this->tab.setHighlightState(HighlightState::Highlighted);
EXPECT_EQ(this->tab.highlightState(), HighlightState::Highlighted);
this->tab.setHighlightState(HighlightState::NewMessage);
EXPECT_EQ(this->tab.highlightState(), HighlightState::Highlighted);
}