2020-04-20 03:00:37 +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.
|
|
|
|
|
2020-03-27 06:15:52 +08:00
|
|
|
#include "ftxui/component/radiobox.hpp"
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|