diff --git a/src/ftxui/component/toggle_test.cpp b/src/ftxui/component/toggle_test.cpp index 190cc66..cf376d6 100644 --- a/src/ftxui/component/toggle_test.cpp +++ b/src/ftxui/component/toggle_test.cpp @@ -102,3 +102,37 @@ TEST(ToggleTest, OnChange) { EXPECT_FALSE(toggle.OnEvent(Event::ArrowLeft)); // Reached far left. EXPECT_EQ(counter, 4); } + +TEST(ToggleTest, OnEnter) { + Toggle toggle; + toggle.entries = {L"1", L"2", L"3"}; + + int counter = 0; + toggle.on_enter = [&] { counter++; }; + + EXPECT_FALSE(toggle.OnEvent(Event::ArrowLeft)); // Reached far left. + EXPECT_TRUE(toggle.OnEvent(Event::Return)); + EXPECT_EQ(counter, 1); + + EXPECT_TRUE(toggle.OnEvent(Event::ArrowRight)); // [0] -> [1] + EXPECT_TRUE(toggle.OnEvent(Event::Return)); + EXPECT_EQ(counter, 2); + EXPECT_TRUE(toggle.OnEvent(Event::ArrowRight)); // [1] -> [2] + EXPECT_TRUE(toggle.OnEvent(Event::Return)); + EXPECT_EQ(counter, 3); + + EXPECT_FALSE(toggle.OnEvent(Event::ArrowRight)); // Reached far right. + EXPECT_TRUE(toggle.OnEvent(Event::Return)); + EXPECT_EQ(counter, 4); + + EXPECT_TRUE(toggle.OnEvent(Event::ArrowLeft)); // [2] -> [1] + EXPECT_TRUE(toggle.OnEvent(Event::Return)); + EXPECT_EQ(counter, 5); + EXPECT_TRUE(toggle.OnEvent(Event::ArrowLeft)); // [1] -> [0] + EXPECT_TRUE(toggle.OnEvent(Event::Return)); + EXPECT_EQ(counter, 6); + + EXPECT_FALSE(toggle.OnEvent(Event::ArrowLeft)); // Reached far left. + EXPECT_TRUE(toggle.OnEvent(Event::Return)); + EXPECT_EQ(counter, 7); +}