From ccfe22bc24a83244783cbd202ccccc42df0fd9c4 Mon Sep 17 00:00:00 2001 From: Arthur Sonzogni Date: Sat, 1 Oct 2022 20:24:16 +0200 Subject: [PATCH] Test Page{Up,Down} for Radiobox. (#493) See: https://github.com/ArthurSonzogni/FTXUI/pull/491#issuecomment-1264335576 --- src/ftxui/component/radiobox_test.cpp | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/ftxui/component/radiobox_test.cpp b/src/ftxui/component/radiobox_test.cpp index 294e2a9..dfded22 100644 --- a/src/ftxui/component/radiobox_test.cpp +++ b/src/ftxui/component/radiobox_test.cpp @@ -160,6 +160,64 @@ TEST(RadioboxTest, NavigationHome) { EXPECT_EQ(selected, 0); } +TEST(RadioboxTest, NavigationPageDown) { + int selected = 0; + std::vector 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 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) { int selected = 0; std::vector entries = {"1", "2", "3"};