fix: Fixed account switch not being saved if no other settings were changed (#5558)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "controllers/filters/lang/Types.hpp"
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "mocks/BaseApplication.hpp"
|
||||
#include "mocks/Channel.hpp"
|
||||
#include "mocks/ChatterinoBadges.hpp"
|
||||
#include "mocks/EmptyApplication.hpp"
|
||||
@@ -26,12 +27,11 @@ TypingContext typingContext = MESSAGE_TYPING_CONTEXT;
|
||||
|
||||
namespace {
|
||||
|
||||
class MockApplication : mock::EmptyApplication
|
||||
class MockApplication : public mock::BaseApplication
|
||||
{
|
||||
public:
|
||||
MockApplication()
|
||||
: settings(this->settingsDir.filePath("settings.json"))
|
||||
, highlights(this->settings, &this->accounts)
|
||||
: highlights(this->settings, &this->accounts)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -75,7 +75,6 @@ public:
|
||||
return &this->highlights;
|
||||
}
|
||||
|
||||
Settings settings;
|
||||
AccountController accounts;
|
||||
Emotes emotes;
|
||||
mock::UserDataController userData;
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/highlights/HighlightPhrase.hpp"
|
||||
#include "messages/MessageBuilder.hpp" // for MessageParseArgs
|
||||
#include "mocks/EmptyApplication.hpp"
|
||||
#include "mocks/BaseApplication.hpp"
|
||||
#include "mocks/Helix.hpp"
|
||||
#include "mocks/UserData.hpp"
|
||||
#include "providers/twitch/api/Helix.hpp"
|
||||
#include "providers/twitch/TwitchBadge.hpp" // for Badge
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "Test.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
@@ -22,12 +21,11 @@ using ::testing::Exactly;
|
||||
|
||||
namespace {
|
||||
|
||||
class MockApplication : public mock::EmptyApplication
|
||||
class MockApplication : public mock::BaseApplication
|
||||
{
|
||||
public:
|
||||
MockApplication(const QString &settingsBody)
|
||||
: mock::EmptyApplication(settingsBody)
|
||||
, settings(this->settingsDir.path())
|
||||
: mock::BaseApplication(settingsBody)
|
||||
, highlights(this->settings, &this->accounts)
|
||||
{
|
||||
}
|
||||
@@ -47,7 +45,6 @@ public:
|
||||
return &this->userData;
|
||||
}
|
||||
|
||||
Settings settings;
|
||||
AccountController accounts;
|
||||
HighlightController highlights;
|
||||
mock::UserDataController userData;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include "controllers/completion/strategies/ClassicUserStrategy.hpp"
|
||||
#include "controllers/completion/strategies/Strategy.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "mocks/BaseApplication.hpp"
|
||||
#include "mocks/Channel.hpp"
|
||||
#include "mocks/EmptyApplication.hpp"
|
||||
#include "mocks/Helix.hpp"
|
||||
#include "mocks/TwitchIrcServer.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
@@ -31,9 +31,14 @@ namespace {
|
||||
using namespace chatterino::completion;
|
||||
using ::testing::Exactly;
|
||||
|
||||
class MockApplication : mock::EmptyApplication
|
||||
class MockApplication : public mock::BaseApplication
|
||||
{
|
||||
public:
|
||||
explicit MockApplication(const QString &settingsData)
|
||||
: BaseApplication(settingsData)
|
||||
{
|
||||
}
|
||||
|
||||
AccountController *getAccounts() override
|
||||
{
|
||||
return &this->accounts;
|
||||
@@ -110,24 +115,14 @@ class InputCompletionTest : public ::testing::Test
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
// Write default settings to the mock settings json file
|
||||
this->settingsDir_ = std::make_unique<QTemporaryDir>();
|
||||
|
||||
QFile settingsFile(this->settingsDir_->filePath("settings.json"));
|
||||
ASSERT_TRUE(settingsFile.open(QIODevice::WriteOnly | QIODevice::Text));
|
||||
ASSERT_GT(settingsFile.write(DEFAULT_SETTINGS.toUtf8()), 0);
|
||||
ASSERT_TRUE(settingsFile.flush());
|
||||
settingsFile.close();
|
||||
|
||||
// Initialize helix client
|
||||
this->mockHelix = std::make_unique<mock::Helix>();
|
||||
initializeHelix(this->mockHelix.get());
|
||||
EXPECT_CALL(*this->mockHelix, loadBlocks).Times(Exactly(1));
|
||||
EXPECT_CALL(*this->mockHelix, update).Times(Exactly(1));
|
||||
|
||||
this->mockApplication = std::make_unique<MockApplication>();
|
||||
this->settings = std::make_unique<Settings>(this->settingsDir_->path());
|
||||
this->paths = std::make_unique<Paths>();
|
||||
this->mockApplication =
|
||||
std::make_unique<MockApplication>(DEFAULT_SETTINGS);
|
||||
|
||||
this->mockApplication->accounts.load();
|
||||
|
||||
@@ -139,19 +134,11 @@ protected:
|
||||
void TearDown() override
|
||||
{
|
||||
this->mockApplication.reset();
|
||||
this->settings.reset();
|
||||
this->paths.reset();
|
||||
this->mockHelix.reset();
|
||||
this->channelPtr.reset();
|
||||
|
||||
this->settingsDir_.reset();
|
||||
}
|
||||
|
||||
std::unique_ptr<QTemporaryDir> settingsDir_;
|
||||
|
||||
std::unique_ptr<MockApplication> mockApplication;
|
||||
std::unique_ptr<Settings> settings;
|
||||
std::unique_ptr<Paths> paths;
|
||||
std::unique_ptr<mock::Helix> mockHelix;
|
||||
|
||||
ChannelPtr channelPtr;
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "controllers/ignores/IgnorePhrase.hpp"
|
||||
#include "mocks/BaseApplication.hpp"
|
||||
#include "mocks/Channel.hpp"
|
||||
#include "mocks/ChatterinoBadges.hpp"
|
||||
#include "mocks/DisabledStreamerMode.hpp"
|
||||
#include "mocks/EmptyApplication.hpp"
|
||||
#include "mocks/TwitchIrcServer.hpp"
|
||||
#include "mocks/UserData.hpp"
|
||||
#include "providers/ffz/FfzBadges.hpp"
|
||||
@@ -28,12 +28,11 @@ using chatterino::mock::MockChannel;
|
||||
|
||||
namespace {
|
||||
|
||||
class MockApplication : mock::EmptyApplication
|
||||
class MockApplication : public mock::BaseApplication
|
||||
{
|
||||
public:
|
||||
MockApplication()
|
||||
: settings(this->settingsDir.filePath("settings.json"))
|
||||
, highlights(this->settings, &this->accounts)
|
||||
: highlights(this->settings, &this->accounts)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -92,12 +91,6 @@ public:
|
||||
return &this->seventvEmotes;
|
||||
}
|
||||
|
||||
IStreamerMode *getStreamerMode() override
|
||||
{
|
||||
return &this->streamerMode;
|
||||
}
|
||||
|
||||
Settings settings;
|
||||
AccountController accounts;
|
||||
Emotes emotes;
|
||||
mock::UserDataController userData;
|
||||
@@ -109,7 +102,6 @@ public:
|
||||
BttvEmotes bttvEmotes;
|
||||
FfzEmotes ffzEmotes;
|
||||
SeventvEmotes seventvEmotes;
|
||||
DisabledStreamerMode streamerMode;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#include "controllers/moderationactions/ModerationAction.hpp"
|
||||
|
||||
#include "messages/Image.hpp"
|
||||
#include "mocks/EmptyApplication.hpp"
|
||||
#include "mocks/BaseApplication.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "Test.hpp"
|
||||
|
||||
#include <QString>
|
||||
@@ -15,20 +14,16 @@ using namespace std::chrono_literals;
|
||||
|
||||
namespace {
|
||||
|
||||
class MockApplication : mock::EmptyApplication
|
||||
class MockApplication : public mock::BaseApplication
|
||||
{
|
||||
public:
|
||||
MockApplication()
|
||||
: settings(this->settingsDir.filePath("settings.json"))
|
||||
{
|
||||
}
|
||||
MockApplication() = default;
|
||||
|
||||
IEmotes *getEmotes() override
|
||||
{
|
||||
return &this->emotes;
|
||||
}
|
||||
|
||||
Settings settings;
|
||||
Emotes emotes;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
#include "common/Literals.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
#include "gmock/gmock.h"
|
||||
#include "mocks/EmptyApplication.hpp"
|
||||
#include "mocks/BaseApplication.hpp"
|
||||
#include "singletons/Fonts.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "Test.hpp"
|
||||
#include "widgets/Notebook.hpp"
|
||||
@@ -18,12 +17,11 @@ using ::testing::Exactly;
|
||||
|
||||
namespace {
|
||||
|
||||
class MockApplication : mock::EmptyApplication
|
||||
class MockApplication : public mock::BaseApplication
|
||||
{
|
||||
public:
|
||||
MockApplication()
|
||||
: settings(this->settingsDir.filePath("settings.json"))
|
||||
, theme(this->paths_)
|
||||
: theme(this->paths_)
|
||||
, fonts(this->settings)
|
||||
{
|
||||
}
|
||||
@@ -42,7 +40,6 @@ public:
|
||||
return &this->fonts;
|
||||
}
|
||||
|
||||
Settings settings;
|
||||
Theme theme;
|
||||
HotkeyController hotkeys;
|
||||
Fonts fonts;
|
||||
|
||||
+4
-1
@@ -1,3 +1,4 @@
|
||||
#include "common/Args.hpp"
|
||||
#include "common/network/NetworkManager.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
@@ -29,10 +30,12 @@ int main(int argc, char **argv)
|
||||
|
||||
chatterino::NetworkManager::init();
|
||||
|
||||
Args args;
|
||||
|
||||
// Ensure settings are initialized before any tests are run
|
||||
QTemporaryDir settingsDir;
|
||||
settingsDir.setAutoRemove(false); // we'll remove it manually
|
||||
chatterino::Settings settings(settingsDir.path());
|
||||
chatterino::Settings settings(args, settingsDir.path());
|
||||
|
||||
QTimer::singleShot(0, [&]() {
|
||||
auto res = RUN_ALL_TESTS();
|
||||
|
||||
Reference in New Issue
Block a user