Skip to content

Commit

Permalink
Refactor BudgetDetailPresenter into BudgetSummaryPresenter (#43)
Browse files Browse the repository at this point in the history
- Redistributed test cases.

- Renamed everything

- BudgetSummaryPresenter tests expect only the summary.

- Minor adjusts and corrections.
  • Loading branch information
talesm committed Feb 20, 2016
1 parent 2cc722b commit 08163d6
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 240 deletions.
6 changes: 3 additions & 3 deletions orcamento.project
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@
<File Name="presenter/EstimateDetailPresenter.cpp"/>
<File Name="presenter/ExecutionListPresenter.hpp"/>
<File Name="presenter/ExecutionListPresenter.cpp"/>
<File Name="presenter/BudgetDetailPresenter.hpp"/>
<File Name="presenter/BudgetDetailPresenter.cpp"/>
<File Name="presenter/ControllerOwnerPresenter.hpp"/>
<File Name="presenter/ExecutionDetailPresenter.hpp"/>
<File Name="presenter/ExecutionDetailPresenter.cpp"/>
<File Name="presenter/BudgetSummaryPresenter.cpp"/>
<File Name="presenter/BudgetSummaryPresenter.hpp"/>
</VirtualDirectory>
<VirtualDirectory Name="presenter-test">
<File Name="presenter-test/CMakeLists.txt"/>
Expand All @@ -135,8 +135,8 @@
<File Name="presenter-test/EstimateDetailPresenter-unit.cpp"/>
<File Name="presenter-test/ExecutionListPresenter-unit.cpp"/>
<File Name="presenter-test/UserInputChecker.hpp"/>
<File Name="presenter-test/BudgetDetailPresenter-unit.cpp"/>
<File Name="presenter-test/ExecutionDetailPresenter-unit.cpp"/>
<File Name="presenter-test/BudgetSummaryPresenter-unit.cpp"/>
</VirtualDirectory>
<VirtualDirectory Name="standalone">
<File Name="standalone/CMakeLists.txt"/>
Expand Down
83 changes: 0 additions & 83 deletions presenter-test/BudgetDetailPresenter-unit.cpp

This file was deleted.

35 changes: 35 additions & 0 deletions presenter-test/BudgetSummaryPresenter-unit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "common.hpp"
#include "stubs/BudgetControllerStub.hpp"
#include "BudgetSummaryPresenter.hpp"

class BudgetSummaryFixture
{
protected:
CallRecorder call_recorder;
nana::form host{API::make_center(800, 600)};
nana::place placer { host };
BudgetSummaryPresenter budgetDetailPresenter{host, make_unique<BudgetControllerStub>(call_recorder)};

BudgetSummaryFixture()
{
placer.div("<main>");
placer.field("main") << budgetDetailPresenter.window();
placer.collocate();
}
};

SCENARIO_METHOD(BudgetSummaryFixture, "BudgetDetailPresenter summary", "[budget-summary-presenter-class][presenter]")
{
GIVEN("A BudgetSummaryPresenter correcly initialized")
{
WHEN("Summary tab is selected")
{
THEN("Show the summary")
{
UserInputChecker uic("", "the summary is shown");
exec(host);
REQUIRE(call_recorder.has("listEstimates"));
}
}
}
}
2 changes: 1 addition & 1 deletion presenter-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#######################
add_executable(presenter-test
#Unit tests
BudgetDetailPresenter-unit
BudgetSummaryPresenter-unit
EstimateDetailPresenter-unit
EstimateListPresenter-unit
ExecutionDetailPresenter-unit
Expand Down
65 changes: 62 additions & 3 deletions presenter-test/MainPresenter-unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ SCENARIO("MainPresenter startup with no file", "[presenter][main-presenter-class
}
}
}
}

SCENARIO("MainPresenter startup with file", "[presenter][main-presenter-class][tabs]")
{
GIVEN("A Main Presenter with a filepath")
{
CallRecorder callRecorder;
Expand All @@ -63,8 +67,9 @@ SCENARIO("MainPresenter startup with no file", "[presenter][main-presenter-class

WHEN("Presented")
{
cout << "If splasher opens, cancel. It is already wrong." << endl;

UserInputChecker uic("",
"splasher does not open and the window should have three tabs, Summary, Estimates, "
"Executions, the first one being selected by default");
THEN("Does not show dialog at presentation")
{
bool calledListBudgets = false;
Expand Down Expand Up @@ -95,7 +100,7 @@ struct CounterMainController : public MainController {
};

// TODO: Fix the bug (Issue #42).
SCENARIO("MainPresenter startup with file", "[presenter][main-presenter-class][.][!mayfail]")
SCENARIO("MainPresenter startup with file2", "[presenter][main-presenter-class][.][!mayfail]")
{
GIVEN("A MainPresenter with a filepath")
{
Expand Down Expand Up @@ -245,3 +250,57 @@ SCENARIO("Exectution List Manipulation", "[presenter][main-presenter-class]")
}
}
}

SCENARIO("MainPresenter tab summary", "[main-presenter-class][presenter][tabs]")
{
GIVEN("A MainPresenter with a file loaded")
{
CallRecorder callRecorder;
Manager manager = createManagerForTest(callRecorder);
MainPresenter mainPresenter{manager, "teste"};
WHEN("Summary tab is selected")
{
THEN("Show the summary")
{
UserInputChecker uic("Click the first tab", "the summary is shown");
exec(mainPresenter);
}
}
}
}

SCENARIO("MainPresenter tab estimates", "[main-presenter-class][presenter][tabs]")
{
GIVEN("A MainPresenter with a file loaded")
{
CallRecorder callRecorder;
Manager manager = createManagerForTest(callRecorder);
MainPresenter mainPresenter{manager, "teste"};
WHEN("Estimates tab is selected")
{
THEN("Show the estimates")
{
UserInputChecker uic("Click the second tab", "the estimates are shown");
exec(mainPresenter);
}
}
}
}

SCENARIO("MainPresenter tab executions", "[main-presenter-class][presenter][tabs]")
{
GIVEN("A MainPresenter with a file loaded")
{
CallRecorder callRecorder;
Manager manager = createManagerForTest(callRecorder);
MainPresenter mainPresenter{manager, "teste"};
WHEN("Execution tab is selected")
{
THEN("Show the executions")
{
UserInputChecker uic("Click the third tab", "the executions are shown");
exec(mainPresenter);
}
}
}
}
63 changes: 0 additions & 63 deletions presenter/BudgetDetailPresenter.hpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,55 +1,13 @@
#include "BudgetDetailPresenter.hpp"
#include "ExecutionDetailPresenter.hpp"
#include "BudgetSummaryPresenter.hpp"
#include <iostream>
#include <cmath>

using namespace nana;
using namespace std;

orca::BudgetDetailPresenter::BudgetDetailPresenter(nana::window wd, std::unique_ptr<BudgetController> controller)
: BASE(move(controller)), a_estimates(wd, nullptr), a_executions(wd, nullptr), t_main(wd), l_summary(wd)
orca::BudgetSummaryPresenter::BudgetSummaryPresenter(nana::window wd, std::unique_ptr<BudgetController> controller)
: BASE(move(controller)), l_summary(wd)
{
t_main.append("Summary", l_summary, "summary");
t_main.append("Estimates", a_estimates.window(), "estimates");
t_main.append("Execution", a_executions.window(), "executions");
t_main.activated(0);

t_main.events().activated([this](auto&& arg) {
unique_ptr<BudgetController> controller;
switch(a_currentControllerOwner) {
case 0:
controller = move(a_controller);
break;
case 1:
controller = a_estimates.devolve();
break;
case 2:
controller = a_executions.devolve();
break;
default:
throw logic_error("Invalid tab");
}
a_currentControllerOwner = t_main.activated();
switch(a_currentControllerOwner) {
case 0:
a_controller = move(controller);
this->refresh();
break;
case 1:
a_estimates.receive(move(controller));
break;
case 2:
a_executions.receive(move(controller));
break;
default:
throw logic_error("Invalid tab");
}
});
a_executions.editViewHandler([this](auto&& view) {
ExecutionDetailPresenter edp(view);
edp.present();
view = edp.get();
});
l_summary.show_header(false);
l_summary.append_header("Name");
l_summary.append_header("Value");
Expand All @@ -68,7 +26,7 @@ listbox::oresolver& operator<<(listbox::oresolver& ores, const SummaryItem& item
return ores << item.name << item.value;
}

void orca::BudgetDetailPresenter::refresh()
void orca::BudgetSummaryPresenter::refresh()
{
// Data
enum ItensNumbers {
Expand Down Expand Up @@ -115,22 +73,3 @@ void orca::BudgetDetailPresenter::refresh()
catTotal.append(si);
}
}

void orca::BudgetDetailPresenter::activate(Tabs tab) { t_main.activated(tab); }
void orca::BudgetDetailPresenter::insertExecution()
{
activate(EXECUTION);
a_executions.insertExecution();
}

void orca::BudgetDetailPresenter::editExecution()
{
activate(EXECUTION);
a_executions.editSelectedExecutions();
}

void orca::BudgetDetailPresenter::deleteExecution()
{
activate(EXECUTION);
a_executions.deleteSelectedExecutions();
}
Loading

0 comments on commit 08163d6

Please sign in to comment.