File indexing completed on 2024-05-19 05:41:56
0001 // mainwindow.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 // TODO [#616]: Review test flaky on Windows 0040 TEST_CASE_METHOD(CodeVisApplicationTestFixture, "Correctly Show Relationship After Actions") 0041 { 0042 clickOn(Menubar::File::NewProject{}); 0043 0044 clickOn(Sidebar::ManipulationTool::NewPackage{"abc"}); 0045 clickOn(CurrentGraph{0, 0}); 0046 QTest::qWait(100); 0047 0048 clickOn(Sidebar::ManipulationTool::NewPackage{"def"}); 0049 clickOn(CurrentGraph{300, 400}); 0050 QTest::qWait(100); 0051 0052 clickOn(Sidebar::ManipulationTool::AddDependency{}); 0053 0054 auto point = findElementTopLeftPosition("abc"); 0055 clickOn(CurrentGraph{point}); 0056 QTest::qWait(100); 0057 0058 point = findElementTopLeftPosition("def"); 0059 clickOn(CurrentGraph{point}); 0060 QTest::qWait(100); 0061 0062 auto getRelation = [this]() -> LakosRelation * { 0063 auto *view = qobject_cast<GraphicsView *>(window().findChild<QGraphicsView *>()); 0064 LakosRelation *relation = nullptr; 0065 for (auto *item : view->items()) { 0066 relation = dynamic_cast<LakosRelation *>(item); 0067 if (relation) { 0068 return relation; 0069 } 0070 } 0071 return nullptr; 0072 }; 0073 0074 point = findElementTopLeftPosition("abc"); 0075 clickOn(Sidebar::ManipulationTool::NewPackage{"abcxyz"}); 0076 clickOn(CurrentGraph{point}); 0077 QTest::qWait(100); 0078 0079 auto *entity1 = findElement("abc"); 0080 0081 entity1->shrink(QtcUtil::CreateUndoAction::e_No, std::nullopt, LakosEntity::RelayoutBehavior::e_RequestRelayout); 0082 QTest::qWait(300); 0083 auto *relation = getRelation(); 0084 REQUIRE(relation); 0085 REQUIRE(relation->isVisible()); 0086 0087 entity1->expand(QtcUtil::CreateUndoAction::e_No, std::nullopt, LakosEntity::RelayoutBehavior::e_RequestRelayout); 0088 QTest::qWait(300); 0089 relation = getRelation(); 0090 REQUIRE(relation); 0091 REQUIRE(relation->isVisible()); 0092 0093 auto *view = window().findChild<GraphicsView *>(); 0094 auto *scene = qobject_cast<GraphicsScene *>(view->scene()); 0095 scene->collapseSecondaryEntities(); 0096 REQUIRE(relation); 0097 REQUIRE(relation->isVisible()); 0098 }