FTXUI/src/ftxui/component/modal_test.cpp

48 lines
1.8 KiB
C++
Raw Normal View History

2022-06-12 23:08:22 +08:00
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPartResult, TestFactoryImpl
#include <ftxui/dom/elements.hpp> // for Element, operator|, text, border
#include <memory> // for shared_ptr, allocator, __shared_ptr_access
#include "ftxui/component/component.hpp" // for Renderer, Modal
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/screen.hpp" // for Screen
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST
namespace ftxui {
TEST(ModalTest, Basic) {
auto main = Renderer([] { return text("main") | border; });
auto modal = Renderer([] { return text("modal") | border; });
bool show_modal = false;
auto component = Modal(main, modal, &show_modal);
Screen screen(10, 7);
Render(screen, component->Render());
EXPECT_EQ(screen.ToString(),
"╭────────╮\r\n"
"│main │\r\n"
"│ │\r\n"
"│ │\r\n"
"│ │\r\n"
"│ │\r\n"
"╰────────╯");
show_modal = true;
Render(screen, component->Render());
EXPECT_EQ(screen.ToString(),
"╭────────╮\r\n"
"│main │\r\n"
"│╭─────╮ │\r\n"
"││modal│ │\r\n"
"│╰─────╯ │\r\n"
"│ │\r\n"
"╰────────╯");
}
} // namespace ftxui
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.