File indexing completed on 2024-05-19 05:41:56

0001 // mainwindow_basic_application_workflow.t.cpp                                      -*-C++-*-
0002 
0003 /* Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>
0004  * // SPDX-License-Identifier: Apache-2.0
0005  * //
0006  * // Licensed under the Apache License, Version 2.0 (the "License");
0007  * // you may not use this file except in compliance with the License.
0008  * // You may obtain a copy of the License at
0009  * //
0010  * //     http://www.apache.org/licenses/LICENSE-2.0
0011  * //
0012  * // Unless required by applicable law or agreed to in writing, software
0013  * // distributed under the License is distributed on an "AS IS" BASIS,
0014  * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015  * // See the License for the specific language governing permissions and
0016  * // limitations under the License.
0017  */
0018 
0019 #include <ct_lvtqtc_graphicsscene.h>
0020 #include <ct_lvtqtc_graphicsview.h>
0021 #include <ct_lvtqtc_lakosrelation.h>
0022 #include <ct_lvttst_fixture_qt.h>
0023 
0024 #include <apptesting_fixture.h>
0025 #include <catch2-local-includes.h>
0026 #include <variant>
0027 
0028 #include <preferences.h>
0029 
0030 // in a header
0031 Q_DECLARE_LOGGING_CATEGORY(LogTest)
0032 
0033 // in one source file
0034 Q_LOGGING_CATEGORY(LogTest, "log.test")
0035 
0036 using namespace Codethink::lvtldr;
0037 
0038 TEST_CASE_METHOD(CodeVisApplicationTestFixture, "Basic application workflow")
0039 {
0040     Preferences::self()->useDefaults(true);
0041 
0042     REQUIRE(isShowingWelcomePage());
0043     REQUIRE_FALSE(isShowingGraphPage());
0044     clickOn(Menubar::File::NewProject{});
0045     REQUIRE_FALSE(isShowingWelcomePage());
0046     REQUIRE(isShowingGraphPage());
0047 
0048     clickOn(Sidebar::ManipulationTool::NewPackage{"abc"});
0049     clickOn(CurrentGraph{100, 400});
0050     QTest::qWait(100);
0051 
0052     // position will change because of the layout algorithm,
0053     // so we need to request from the view.
0054     clickOn(Sidebar::ManipulationTool::NewPackage{"abcxyz"});
0055     const auto pos1 = findElementTopLeftPosition("abc");
0056     clickOn(CurrentGraph{pos1});
0057     QTest::qWait(100);
0058 
0059     clickOn(Sidebar::ManipulationTool::NewComponent{"abcxyz_comp1"});
0060     const auto pos2 = findElementTopLeftPosition("abc/abcxyz");
0061     clickOn(CurrentGraph{pos2});
0062 
0063     // Wait to make sure animations finished
0064     QTest::qWait(200);
0065 
0066     ctrlZ();
0067     ctrlShiftZ();
0068 
0069     clickOn(Sidebar::ManipulationTool::NewPackage{"def"});
0070     clickOn(CurrentGraph{600, 400});
0071     QTest::qWait(100);
0072 
0073     // position will change because of the layout algorithm,
0074     // so we need to request from the view.
0075     const auto pos3 = findElementTopLeftPosition("def");
0076 
0077     clickOn(Sidebar::ManipulationTool::NewPackage{"defxyz"});
0078     clickOn(CurrentGraph{pos3});
0079     QTest::qWait(100);
0080 
0081     clickOn(Sidebar::ManipulationTool::NewComponent{"defxyz_comp1"});
0082     const auto pos4 = findElementTopLeftPosition("def/defxyz");
0083     clickOn(CurrentGraph{pos4});
0084 
0085     // Wait to make sure animations finished
0086     QTest::qWait(200);
0087 
0088     ctrlZ();
0089     ctrlShiftZ();
0090 
0091     // Stress test
0092     ctrlZ();
0093     ctrlZ();
0094     ctrlZ();
0095     ctrlZ();
0096     ctrlShiftZ();
0097     ctrlShiftZ();
0098     ctrlShiftZ();
0099     ctrlShiftZ();
0100 
0101     clickOn(Sidebar::ManipulationTool::AddDependency{});
0102     auto posAbc = findElementTopLeftPosition("abc");
0103     clickOn(CurrentGraph{posAbc});
0104     auto posDef = findElementTopLeftPosition("def");
0105     clickOn(CurrentGraph{posDef});
0106 
0107     clickOn(Sidebar::ManipulationTool::AddDependency{});
0108     auto posAXyz = findElementTopLeftPosition("abc/abcxyz");
0109     clickOn(CurrentGraph{posAXyz});
0110 
0111     auto posDXyz = findElementTopLeftPosition("def/defxyz");
0112     clickOn(CurrentGraph{posDXyz});
0113 
0114     clickOn(Sidebar::ManipulationTool::AddDependency{});
0115     auto element1 = findElementTopLeftPosition("abc/abcxyz/abcxyz_comp1");
0116     clickOn(CurrentGraph{element1});
0117 
0118     auto element2 = findElementTopLeftPosition("def/defxyz/defxyz_comp1");
0119     clickOn(CurrentGraph{element2});
0120 
0121     clickOn(Sidebar::ManipulationTool::NewLogicalEntity{"klass", "Class"});
0122     clickOn(CurrentGraph{element1});
0123 
0124     QTest::qWait(100);
0125     ctrlZ();
0126     QTest::qWait(100);
0127     ctrlShiftZ();
0128     QTest::qWait(100);
0129 
0130     // Wait just for be human-noticeable
0131     QTest::qWait(100);
0132     clickOn(Menubar::File::CloseProject{});
0133 
0134     QTest::qWait(100);
0135 
0136     REQUIRE(isShowingWelcomePage());
0137     REQUIRE_FALSE(isShowingGraphPage());
0138 }