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

0001 // mainwindow_auto_add_edges_from_packages.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 TEST_CASE_METHOD(CodeVisApplicationTestFixture, "Auto Add Edges From Packages")
0038 {
0039     Preferences::self()->useDefaults(true);
0040 
0041     clickOn(Menubar::File::NewProject{});
0042 
0043     clickOn(Sidebar::ManipulationTool::NewPackage{"abc"});
0044     clickOn(CurrentGraph{100, 400});
0045     QTest::qWait(100);
0046 
0047     clickOn(Sidebar::VisualizationTool::ResetZoom{});
0048 
0049     auto point = findElementTopLeftPosition("abc");
0050     clickOn(Sidebar::ManipulationTool::NewPackage{"abcxyz"});
0051     clickOn(CurrentGraph{point});
0052     QTest::qWait(400);
0053 
0054     clickOn(Sidebar::ManipulationTool::NewPackage{"def"});
0055     clickOn(CurrentGraph{800, 400});
0056     QTest::qWait(100);
0057 
0058     point = findElementTopLeftPosition("def");
0059 
0060     clickOn(Sidebar::ManipulationTool::NewPackage{"defg"});
0061     clickOn(CurrentGraph{point});
0062     QTest::qWait(100);
0063 
0064     clickOn(Sidebar::ManipulationTool::AddDependency{});
0065     auto element1 = findElementTopLeftPosition("abc/abcxyz");
0066     clickOn(CurrentGraph{element1});
0067 
0068     auto element2 = findElementTopLeftPosition("def/defg");
0069     clickOn(CurrentGraph{element2});
0070 
0071     QTest::qWait(100);
0072 
0073     LakosEntity *abc = findElement("abc");
0074     LakosEntity *def = findElement("def");
0075     LakosEntity *abcd = findElement("abc/abcxyz");
0076     LakosEntity *defg = findElement("def/defg");
0077 
0078     REQUIRE(abc->internalNode()->hasProvider(def->internalNode()));
0079     REQUIRE(abcd->internalNode()->hasProvider(defg->internalNode()));
0080 
0081     REQUIRE(abc->edgesCollection().size() == 1);
0082     REQUIRE(abc->edgesCollection()[0]->relations().size() == 1);
0083 
0084     ctrlZ();
0085     QTest::qWait(100);
0086 
0087     REQUIRE_FALSE(abcd->internalNode()->hasProvider(defg->internalNode()));
0088     REQUIRE_FALSE(abc->internalNode()->hasProvider(def->internalNode()));
0089 
0090     ctrlShiftZ();
0091     QTest::qWait(100);
0092 
0093     REQUIRE(abc->internalNode()->hasProvider(def->internalNode()));
0094     REQUIRE(abcd->internalNode()->hasProvider(defg->internalNode()));
0095 }