From 177df31d41583f876e2848bed3497556ac76aa9d Mon Sep 17 00:00:00 2001 From: vedantparanjape <22630228+VedantParanjape@users.noreply.github.com> Date: Tue, 4 Aug 2020 22:27:21 +0530 Subject: [PATCH] Added tests for toggle component, OnEnter event --- src/ftxui/component/toggle_test.cpp | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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); +}