File indexing completed on 2024-05-19 05:41:56
0001 // mainwindow_auto_add_edges_from_components.t.cpp -*-C++-*- 0002 0003 /* 0004 * // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 * // SPDX-License-Identifier: Apache-2.0 0006 * // 0007 * // Licensed under the Apache License, Version 2.0 (the "License"); 0008 * // you may not use this file except in compliance with the License. 0009 * // You may obtain a copy of the License at 0010 * // 0011 * // http://www.apache.org/licenses/LICENSE-2.0 0012 * // 0013 * // Unless required by applicable law or agreed to in writing, software 0014 * // distributed under the License is distributed on an "AS IS" BASIS, 0015 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 * // See the License for the specific language governing permissions and 0017 * // limitations under the License. 0018 */ 0019 0020 #include <ct_lvtqtc_graphicsscene.h> 0021 #include <ct_lvtqtc_graphicsview.h> 0022 #include <ct_lvtqtc_lakosrelation.h> 0023 #include <ct_lvttst_fixture_qt.h> 0024 0025 #include <apptesting_fixture.h> 0026 #include <catch2-local-includes.h> 0027 #include <variant> 0028 0029 #include <preferences.h> 0030 0031 // in a header 0032 Q_DECLARE_LOGGING_CATEGORY(LogTest) 0033 0034 // in one source file 0035 Q_LOGGING_CATEGORY(LogTest, "log.test") 0036 0037 using namespace Codethink::lvtldr; 0038 0039 TEST_CASE_METHOD(CodeVisApplicationTestFixture, "Auto Add Edge From Components") 0040 { 0041 Preferences::self()->useDefaults(true); 0042 0043 clickOn(Menubar::File::NewProject{}); 0044 0045 clickOn(Sidebar::ManipulationTool::NewPackage{"abc"}); 0046 clickOn(CurrentGraph{100, 400}); 0047 QTest::qWait(1000); 0048 0049 clickOn(Sidebar::VisualizationTool::ResetZoom{}); 0050 0051 auto point = findElementTopLeftPosition("abc"); 0052 clickOn(Sidebar::ManipulationTool::NewPackage{"abcxyz"}); 0053 clickOn(CurrentGraph{point}); 0054 QTest::qWait(1000); 0055 0056 point = findElementTopLeftPosition("abc/abcxyz"); 0057 0058 clickOn(Sidebar::ManipulationTool::NewComponent{"abcxyz_comp1"}); 0059 clickOn(CurrentGraph{point}); 0060 QTest::qWait(1000); 0061 0062 clickOn(Sidebar::ManipulationTool::NewPackage{"def"}); 0063 clickOn(CurrentGraph{point.x() + 200, point.y() + 200}); 0064 QTest::qWait(1000); 0065 point = findElementTopLeftPosition("def"); 0066 0067 clickOn(Sidebar::ManipulationTool::NewPackage{"defg"}); 0068 clickOn(CurrentGraph{point}); 0069 QTest::qWait(1000); 0070 point = findElementTopLeftPosition("def/defg"); 0071 0072 clickOn(Sidebar::ManipulationTool::NewComponent{"defg_comp1"}); 0073 clickOn(CurrentGraph{point}); 0074 QTest::qWait(1000); 0075 0076 auto element1 = findElementTopLeftPosition("abc/abcxyz/abcxyz_comp1"); 0077 auto element2 = findElementTopLeftPosition("def/defg/defg_comp1"); 0078 0079 clickOn(Sidebar::ManipulationTool::AddDependency{}); 0080 clickOn(CurrentGraph{element1}); 0081 clickOn(CurrentGraph{element2}); 0082 0083 QTest::qWait(100); 0084 0085 LakosEntity *abc = findElement("abc"); 0086 LakosEntity *def = findElement("def"); 0087 LakosEntity *abcd = findElement("abc/abcxyz"); 0088 LakosEntity *defg = findElement("def/defg"); 0089 LakosEntity *abc_comp1 = findElement("abc/abcxyz/abcxyz_comp1"); 0090 LakosEntity *def_comp1 = findElement("def/defg/defg_comp1"); 0091 0092 REQUIRE(abc->internalNode()->hasProvider(def->internalNode())); 0093 REQUIRE(abcd->internalNode()->hasProvider(defg->internalNode())); 0094 REQUIRE(abc_comp1->internalNode()->hasProvider(def_comp1->internalNode())); 0095 REQUIRE(abc->edgesCollection().size() == 1); 0096 REQUIRE(abc->edgesCollection()[0]->relations().size() == 1); 0097 0098 ctrlZ(); 0099 QTest::qWait(100); 0100 0101 REQUIRE_FALSE(abc->internalNode()->hasProvider(def->internalNode())); 0102 REQUIRE_FALSE(abcd->internalNode()->hasProvider(defg->internalNode())); 0103 REQUIRE_FALSE(abc_comp1->internalNode()->hasProvider(def_comp1->internalNode())); 0104 0105 ctrlShiftZ(); 0106 QTest::qWait(100); 0107 0108 REQUIRE(abc->internalNode()->hasProvider(def->internalNode())); 0109 REQUIRE(abcd->internalNode()->hasProvider(defg->internalNode())); 0110 REQUIRE(abc_comp1->internalNode()->hasProvider(def_comp1->internalNode())); 0111 }