This repository has been archived by the owner on May 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a2667a
commit 1f3dd38
Showing
6 changed files
with
142 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
lib/MellowPlayer/Presentation/ViewModels/UserScripts/UserScriptViewModel.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "UserScriptViewModel.hpp" | ||
#include <MellowPlayer/Application/UserScripts/IUserScript.hpp> | ||
|
||
using namespace MellowPlayer::Application; | ||
using namespace MellowPlayer::Presentation; | ||
|
||
UserScriptViewModel::UserScriptViewModel(IUserScript& model, QObject* parent): | ||
QObject(parent), model_(model) | ||
{ | ||
|
||
} | ||
|
||
QString UserScriptViewModel::name() const | ||
{ | ||
return model_.name(); | ||
} | ||
|
||
void UserScriptViewModel::setName(const QString& name) | ||
{ | ||
Q_UNUSED(name); | ||
if (name != model_.name()) { | ||
model_.setName(name); | ||
emit nameChanged(); | ||
} | ||
} | ||
|
||
QString UserScriptViewModel::code() const | ||
{ | ||
return model_.code(); | ||
} | ||
|
||
QString UserScriptViewModel::path() const | ||
{ | ||
return model_.path(); | ||
} | ||
|
||
IUserScript& UserScriptViewModel::model() | ||
{ | ||
return model_; | ||
} |
36 changes: 36 additions & 0 deletions
36
lib/MellowPlayer/Presentation/ViewModels/UserScripts/UserScriptViewModel.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include <QObject> | ||
|
||
namespace MellowPlayer::Application | ||
{ | ||
class IUserScript; | ||
} | ||
|
||
namespace MellowPlayer::Presentation | ||
{ | ||
class UserScriptViewModel: public QObject | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) | ||
Q_PROPERTY(QString code READ code CONSTANT) | ||
Q_PROPERTY(QString path READ path CONSTANT) | ||
public: | ||
UserScriptViewModel(Application::IUserScript& model, QObject* parent= nullptr); | ||
|
||
QString name() const; | ||
void setName(const QString& name); | ||
|
||
QString code() const; | ||
QString path() const; | ||
|
||
Application::IUserScript& model(); | ||
|
||
signals: | ||
void nameChanged(); | ||
|
||
private: | ||
Application::IUserScript& model_; | ||
|
||
}; | ||
} |
17 changes: 0 additions & 17 deletions
17
tests/UnitTests/Application/UserScripts/FakeUserScript.cpp
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
tests/UnitTests/Presentation/ViewModels/UserScripts/UserScriptViewModelTests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <catch.hpp> | ||
#include <UnitTests/Application/UserScripts/FakeUserScript.hpp> | ||
#include <MellowPlayer/Presentation/ViewModels/UserScripts/UserScriptViewModel.hpp> | ||
#include <QtTest/QSignalSpy> | ||
|
||
using namespace MellowPlayer::Application; | ||
using namespace MellowPlayer::Application::Tests; | ||
using namespace MellowPlayer::Presentation; | ||
|
||
SCENARIO("UserScritViewModelTests") | ||
{ | ||
GIVEN("a fake user script") | ||
{ | ||
FakeUserScript userScript; | ||
userScript.setName("name"); | ||
userScript.import("/path"); | ||
|
||
WHEN("a view model is created") { | ||
UserScriptViewModel viewModel(userScript); | ||
QSignalSpy spy(&viewModel, &UserScriptViewModel::nameChanged); | ||
|
||
THEN("code is the same as the user script code") | ||
{ | ||
REQUIRE(viewModel.code() == userScript.code()); | ||
} | ||
|
||
THEN("name is the same as the user script name") | ||
{ | ||
REQUIRE(viewModel.name() == userScript.name()); | ||
} | ||
|
||
THEN("path is the same as the user script path") | ||
{ | ||
REQUIRE(viewModel.path() == userScript.path()); | ||
} | ||
|
||
AND_WHEN("another name is set") | ||
{ | ||
viewModel.setName("Another name"); | ||
|
||
THEN("new name is saved") | ||
{ | ||
REQUIRE(viewModel.name() == "Another name"); | ||
|
||
AND_THEN("nameChanged signal is emitted") | ||
{ | ||
REQUIRE(spy.count() == 1); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |