mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-26 04:31:34 +08:00
Add RadioboxTest
This commit is contained in:
parent
580e648147
commit
2cef695216
@ -63,6 +63,7 @@ add_library(component
|
||||
src/ftxui/component/input.cpp
|
||||
src/ftxui/component/menu.cpp
|
||||
src/ftxui/component/radiobox.cpp
|
||||
src/ftxui/component/radiobox.cpp
|
||||
src/ftxui/component/screen_interactive.cpp
|
||||
src/ftxui/component/toggle.cpp
|
||||
include/ftxui/component/checkbox.hpp
|
||||
@ -155,6 +156,7 @@ find_package(GTest)
|
||||
if (FTXUI_BUILD_TESTS AND GTEST_FOUND AND THREADS_FOUND)
|
||||
add_executable(tests
|
||||
src/ftxui/component/toggle_test.cpp
|
||||
src/ftxui/component/radiobox_test.cpp
|
||||
src/ftxui/dom/gauge_test.cpp
|
||||
src/ftxui/dom/hbox_test.cpp
|
||||
src/ftxui/dom/text_test.cpp
|
||||
|
79
src/ftxui/component/radiobox_test.cpp
Normal file
79
src/ftxui/component/radiobox_test.cpp
Normal 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);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user