File indexing completed on 2024-05-19 05:42:22

0001 // ct_lvtqtc_tool_add_component.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_tool_add_component.h>
0021 
0022 #include <ct_lvtclr_colormanagement.h>
0023 #include <ct_lvtldr_lakosiannode.h>
0024 #include <ct_lvtqtc_graphicsscene.h>
0025 #include <ct_lvtqtc_lakosentity.h>
0026 #include <ct_lvtqtc_testing_utils.h>
0027 #include <ct_lvttst_fixture_qt.h>
0028 
0029 #include <catch2-local-includes.h>
0030 #include <ct_lvtldr_nodestoragetestutils.h>
0031 #include <ct_lvttst_tmpdir.h>
0032 
0033 #include <QLineEdit>
0034 #include <memory>
0035 
0036 using namespace Codethink::lvtqtc;
0037 using namespace Codethink::lvtldr;
0038 using namespace Codethink::lvtclr;
0039 using namespace Codethink::lvtshr;
0040 
0041 TEST_CASE_METHOD(QTApplicationFixture, "Add component")
0042 {
0043     auto tmpDir = TmpDir{"add_component"};
0044     auto dbPath = tmpDir.path() / "codedb.db";
0045     auto nodeStorage = NodeStorageTestUtils::createEmptyNodeStorage(dbPath);
0046 
0047     auto gv = GraphicsViewWrapperForTesting{nodeStorage};
0048     auto *gs = qobject_cast<GraphicsScene *>(gv.scene());
0049     gv.setColorManagement(std::make_shared<ColorManagement>(false));
0050     gv.show();
0051 
0052     auto *pkg = nodeStorage.addPackage("pkg", "pkg", nullptr, gv.scene()).value();
0053 
0054     auto tool = ToolAddComponent{&gv, nodeStorage};
0055     auto *inputDialog = tool.inputDialog();
0056 
0057     inputDialog->overrideExec([inputDialog] {
0058         auto *nameLineEdit = inputDialog->findChild<QLineEdit *>("name");
0059         REQUIRE(nameLineEdit->text() == "pkg_");
0060         nameLineEdit->setText("pkg_comp1");
0061         return true;
0062     });
0063 
0064     REQUIRE(nodeStorage.findByQualifiedName(DiagramType::ComponentType, "pkg/pkg_comp1") == nullptr);
0065     REQUIRE(gs->allEntities().size() == 1);
0066 
0067     mousePressAt(tool, gv.getEntityPosition(pkg->uid()));
0068 
0069     REQUIRE(nodeStorage.findByQualifiedName(DiagramType::ComponentType, "pkg/pkg_comp1") != nullptr);
0070     REQUIRE(gs->allEntities().size() == 2);
0071 }