Add RadioboxTest

This commit is contained in:
ArthurSonzogni 2020-03-26 23:15:52 +01:00 committed by Arthur Sonzogni
parent 580e648147
commit 2cef695216
2 changed files with 81 additions and 0 deletions

View File

@ -63,6 +63,7 @@ add_library(component
src/ftxui/component/input.cpp src/ftxui/component/input.cpp
src/ftxui/component/menu.cpp src/ftxui/component/menu.cpp
src/ftxui/component/radiobox.cpp src/ftxui/component/radiobox.cpp
src/ftxui/component/radiobox.cpp
src/ftxui/component/screen_interactive.cpp src/ftxui/component/screen_interactive.cpp
src/ftxui/component/toggle.cpp src/ftxui/component/toggle.cpp
include/ftxui/component/checkbox.hpp include/ftxui/component/checkbox.hpp
@ -155,6 +156,7 @@ find_package(GTest)
if (FTXUI_BUILD_TESTS AND GTEST_FOUND AND THREADS_FOUND) if (FTXUI_BUILD_TESTS AND GTEST_FOUND AND THREADS_FOUND)
add_executable(tests add_executable(tests
src/ftxui/component/toggle_test.cpp src/ftxui/component/toggle_test.cpp
src/ftxui/component/radiobox_test.cpp
src/ftxui/dom/gauge_test.cpp src/ftxui/dom/gauge_test.cpp
src/ftxui/dom/hbox_test.cpp src/ftxui/dom/hbox_test.cpp
src/ftxui/dom/text_test.cpp src/ftxui/dom/text_test.cpp

View File

@ -0,0 +1,79 @@
#include "ftxui/component/radiobox.hpp"
#include "gtest/gtest.h"
using namespace ftxui;
TEST(RadioboxTest, Navigation) {
RadioBox radiobox;
radiobox.entries = {L"1", L"2", L"3"};
// With arrow key.
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::ArrowDown);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::ArrowDown);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::ArrowDown);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::ArrowUp);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::ArrowUp);
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::ArrowUp);
EXPECT_EQ(radiobox.focused, 0);
// With vim like characters.
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::Character('j'));
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::Character('j'));
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::Character('j'));
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::Character('k'));
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::Character('k'));
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::Character('k'));
EXPECT_EQ(radiobox.focused, 0);
// With more entries
radiobox.entries = {L"1", L"2", L"3"};
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::ArrowDown);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::ArrowDown);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::ArrowDown);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::ArrowUp);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::ArrowUp);
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::ArrowUp);
EXPECT_EQ(radiobox.focused, 0);
// With tab.
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::Tab);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::Tab);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::Tab);
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::Tab);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::Tab);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::TabReverse);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::TabReverse);
EXPECT_EQ(radiobox.focused, 0);
radiobox.OnEvent(Event::TabReverse);
EXPECT_EQ(radiobox.focused, 2);
radiobox.OnEvent(Event::TabReverse);
EXPECT_EQ(radiobox.focused, 1);
radiobox.OnEvent(Event::TabReverse);
}