2021-05-02 02:40:35 +08:00
|
|
|
#include <gtest/gtest-message.h> // for Message
|
|
|
|
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver, TestFactoryImpl
|
2020-03-27 06:15:52 +08:00
|
|
|
|
2021-05-02 02:40:35 +08:00
|
|
|
#include "ftxui/component/event.hpp" // for Event, Event::ArrowDown, Event::ArrowUp, Event::Tab, Event::TabReverse
|
|
|
|
#include "ftxui/component/mouse.hpp" // for ftxui
|
|
|
|
#include "ftxui/component/radiobox.hpp"
|
|
|
|
#include "gtest/gtest_pred_impl.h" // for EXPECT_EQ, Test, TEST
|
2020-03-27 06:15:52 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2020-08-16 06:24:18 +08:00
|
|
|
|
|
|
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// the LICENSE file.
|