Skip to content

Commit

Permalink
Add some tests for Menu::getUserChoice method.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Oct 2, 2024
1 parent 5908ee8 commit cc8fb8a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/MenuTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <src/Menu.h>

#include "FakeDisplay.h"
#include "src/InputAction.h"
#include "src/UserChoice.h"
#include "test/FakeInput.h"

TEST_CASE("Menu usage", "[Menu]")
{
Expand All @@ -29,4 +32,43 @@ TEST_CASE("Menu usage", "[Menu]")
REQUIRE(menu.choiceToLevel(UserChoice::LEVEL_MENU) == Level::LEVEL_4);
REQUIRE(menu.choiceToLevel(UserChoice::EXIT) == Level::LEVEL_4);
}

SECTION("getUserChoice EXIT")
{
FakeInput input{InputAction::QUIT, {}, {}};
UserChoice choice{menu.getUserChoice(input)};
REQUIRE(choice == UserChoice::EXIT);
}

SECTION("getUserChoice accept in main menu")
{
menu.refresh(UserChoice::MAIN_MENU);
FakeInput input{InputAction::ACCEPT, {}, {}};
UserChoice choice{menu.getUserChoice(input)};
REQUIRE(choice == UserChoice::LEVEL_MENU);
}

SECTION("getUserChoice back in main menu")
{
menu.refresh(UserChoice::MAIN_MENU);
FakeInput input{InputAction::BACK, {}, {}};
UserChoice choice{menu.getUserChoice(input)};
REQUIRE(choice == UserChoice::EXIT);
}

SECTION("getUserChoice back in level menu")
{
menu.refresh(UserChoice::LEVEL_MENU);
FakeInput input{InputAction::BACK, {}, {}};
UserChoice choice{menu.getUserChoice(input)};
REQUIRE(choice == UserChoice::BACK);
}

SECTION("getUserChoice accept in level menu")
{
menu.refresh(UserChoice::LEVEL_MENU);
FakeInput input{InputAction::ACCEPT, {}, {}};
UserChoice choice{menu.getUserChoice(input)};
REQUIRE(choice == UserChoice::LEVEL_1);
}
}

0 comments on commit cc8fb8a

Please sign in to comment.