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
|
2021-07-10 19:20:43 +08:00
|
|
|
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
|
2021-08-09 06:27:37 +08:00
|
|
|
#include <string> // for string, basic_string
|
2021-07-10 19:20:43 +08:00
|
|
|
#include <vector> // for vector
|
2020-03-27 06:15:52 +08:00
|
|
|
|
2021-07-10 19:20:43 +08:00
|
|
|
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
|
|
|
#include "ftxui/component/component.hpp" // for Radiobox
|
|
|
|
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
2021-05-10 02:32:27 +08:00
|
|
|
#include "ftxui/component/event.hpp" // for Event, Event::Return, Event::ArrowDown, Event::ArrowUp, Event::Tab, Event::TabReverse
|
2021-07-10 19:07:01 +08:00
|
|
|
#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) {
|
2021-05-10 02:32:27 +08:00
|
|
|
int selected = 0;
|
2021-08-09 06:27:37 +08:00
|
|
|
std::vector<std::string> entries = {"1", "2", "3"};
|
2021-05-10 02:32:27 +08:00
|
|
|
auto radiobox = Radiobox(&entries, &selected);
|
2020-03-27 06:15:52 +08:00
|
|
|
|
|
|
|
// With arrow key.
|
2021-05-10 02:32:27 +08:00
|
|
|
EXPECT_EQ(selected, 0);
|
|
|
|
radiobox->OnEvent(Event::ArrowDown);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 1);
|
|
|
|
radiobox->OnEvent(Event::ArrowDown);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 2);
|
|
|
|
radiobox->OnEvent(Event::ArrowDown);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 2);
|
|
|
|
radiobox->OnEvent(Event::ArrowUp);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 1);
|
|
|
|
radiobox->OnEvent(Event::ArrowUp);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 0);
|
|
|
|
radiobox->OnEvent(Event::ArrowUp);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 0);
|
2020-03-27 06:15:52 +08:00
|
|
|
|
|
|
|
// With vim like characters.
|
2021-05-10 02:32:27 +08:00
|
|
|
EXPECT_EQ(selected, 0);
|
|
|
|
radiobox->OnEvent(Event::Character('j'));
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 1);
|
|
|
|
radiobox->OnEvent(Event::Character('j'));
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 2);
|
|
|
|
radiobox->OnEvent(Event::Character('j'));
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 2);
|
|
|
|
radiobox->OnEvent(Event::Character('k'));
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 1);
|
|
|
|
radiobox->OnEvent(Event::Character('k'));
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 0);
|
|
|
|
radiobox->OnEvent(Event::Character('k'));
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 0);
|
2020-03-27 06:15:52 +08:00
|
|
|
|
|
|
|
// With more entries
|
2021-08-09 06:27:37 +08:00
|
|
|
entries = {"1", "2", "3"};
|
2021-05-10 02:32:27 +08:00
|
|
|
EXPECT_EQ(selected, 0);
|
|
|
|
radiobox->OnEvent(Event::ArrowDown);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 1);
|
|
|
|
radiobox->OnEvent(Event::ArrowDown);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 2);
|
|
|
|
radiobox->OnEvent(Event::ArrowDown);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 2);
|
|
|
|
radiobox->OnEvent(Event::ArrowUp);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 1);
|
|
|
|
radiobox->OnEvent(Event::ArrowUp);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 0);
|
|
|
|
radiobox->OnEvent(Event::ArrowUp);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 0);
|
2020-03-27 06:15:52 +08:00
|
|
|
|
|
|
|
// With tab.
|
2021-05-10 02:32:27 +08:00
|
|
|
EXPECT_EQ(selected, 0);
|
|
|
|
radiobox->OnEvent(Event::Tab);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 1);
|
|
|
|
radiobox->OnEvent(Event::Tab);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 2);
|
|
|
|
radiobox->OnEvent(Event::Tab);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 0);
|
|
|
|
radiobox->OnEvent(Event::Tab);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 1);
|
|
|
|
radiobox->OnEvent(Event::Tab);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 2);
|
|
|
|
radiobox->OnEvent(Event::TabReverse);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 1);
|
|
|
|
radiobox->OnEvent(Event::TabReverse);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 0);
|
|
|
|
radiobox->OnEvent(Event::TabReverse);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 2);
|
|
|
|
radiobox->OnEvent(Event::TabReverse);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
|
|
|
EXPECT_EQ(selected, 1);
|
|
|
|
radiobox->OnEvent(Event::TabReverse);
|
|
|
|
radiobox->OnEvent(Event::Return);
|
2020-03-27 06:15:52 +08:00
|
|
|
}
|
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.
|