Test Page{Up,Down} for Radiobox. (#493)

See: https://github.com/ArthurSonzogni/FTXUI/pull/491#issuecomment-1264335576
This commit is contained in:
Arthur Sonzogni 2022-10-01 20:24:16 +02:00 committed by GitHub
parent 5ba29a9539
commit ccfe22bc24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -160,6 +160,64 @@ TEST(RadioboxTest, NavigationHome) {
EXPECT_EQ(selected, 0); EXPECT_EQ(selected, 0);
} }
TEST(RadioboxTest, NavigationPageDown) {
int selected = 0;
std::vector<std::string> entries = {"1", "2", "3", "4", "5", "6"};
auto radiobox = Radiobox(&entries, &selected) | yframe;
Screen screen(1, 3);
Render(screen, radiobox->Render());
EXPECT_TRUE(radiobox->OnEvent(Event::PageDown));
EXPECT_EQ(selected, 0);
EXPECT_TRUE(radiobox->OnEvent(Event::Return));
EXPECT_EQ(selected, 2);
EXPECT_TRUE(radiobox->OnEvent(Event::PageDown));
EXPECT_EQ(selected, 2);
EXPECT_TRUE(radiobox->OnEvent(Event::Return));
EXPECT_EQ(selected, 4);
EXPECT_TRUE(radiobox->OnEvent(Event::PageDown));
EXPECT_EQ(selected, 4);
EXPECT_TRUE(radiobox->OnEvent(Event::Return));
EXPECT_EQ(selected, 5);
EXPECT_FALSE(radiobox->OnEvent(Event::PageDown));
EXPECT_EQ(selected, 5);
EXPECT_TRUE(radiobox->OnEvent(Event::Return));
EXPECT_EQ(selected, 5);
}
TEST(RadioboxTest, NavigationPageUp) {
int selected = 5;
std::vector<std::string> entries = {"1", "2", "3", "4", "5", "6"};
auto radiobox = Radiobox(&entries, &selected) | yframe;
Screen screen(1, 3);
Render(screen, radiobox->Render());
EXPECT_TRUE(radiobox->OnEvent(Event::PageUp));
EXPECT_EQ(selected, 5);
EXPECT_TRUE(radiobox->OnEvent(Event::Return));
EXPECT_EQ(selected, 3);
EXPECT_TRUE(radiobox->OnEvent(Event::PageUp));
EXPECT_EQ(selected, 3);
EXPECT_TRUE(radiobox->OnEvent(Event::Return));
EXPECT_EQ(selected, 1);
EXPECT_TRUE(radiobox->OnEvent(Event::PageUp));
EXPECT_EQ(selected, 1);
EXPECT_TRUE(radiobox->OnEvent(Event::Return));
EXPECT_EQ(selected, 0);
EXPECT_FALSE(radiobox->OnEvent(Event::PageUp));
EXPECT_EQ(selected, 0);
EXPECT_TRUE(radiobox->OnEvent(Event::Return));
EXPECT_EQ(selected, 0);
}
TEST(RadioboxTest, NavigationEnd) { TEST(RadioboxTest, NavigationEnd) {
int selected = 0; int selected = 0;
std::vector<std::string> entries = {"1", "2", "3"}; std::vector<std::string> entries = {"1", "2", "3"};