Add some tests for NotebookTab (#5070)
* EmptyApplication: Add asserts to rest of getters (except for getSeventvAPI) * Theme: make getTheme call getIApp()->getThemes() instead this allows it to be used in tests realistically this should be deprecated & users of it should just call getIApp()->getThemes() directly * Use getIApp() instead of getApp() in a few places
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
#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)
|
||||
{
|
||||
// XXX: This only updates the state once, so it should only update once
|
||||
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::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);
|
||||
}
|
||||
Reference in New Issue
Block a user