Merge pull request #1513 from DaTweety/fix/assistant-info-collection-paths

Write qet-assistant.json after the settings dialog applies the paths
This commit is contained in:
ispyisail
2026-10-18 08:25:51 +13:00
committed by GitHub
3 changed files with 110 additions and 3 deletions
+4
View File
@@ -267,6 +267,10 @@ endfunction()
# alone and with a group.
qet_add_app_test(tst_rotateselectionimage tst_rotateselectionimage.cpp)
# Accepting the settings dialog writes qet-assistant.json with the
# collection paths just chosen, not the ones they replace.
qet_add_app_test(tst_assistantinfopaths tst_assistantinfopaths.cpp)
# Escape during a picture's resize, rotate or pivot drag puts it back, keeps
# it selected and records no undo step (#1414); the key goes to the view.
qet_add_app_test(tst_imagehandleescape tst_imagehandleescape.cpp)
+100
View File
@@ -0,0 +1,100 @@
/*
Copyright 2006-2026 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qetapptest.h"
#include "scripting/assistantinfo.h"
#include "ui/configpage/generalconfigurationpage.h"
#include <QComboBox>
#include <QDir>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QSignalBlocker>
#include <QStandardPaths>
/**
qet-assistant.json names the user and company collections, and the qet
MCP server hands them to every headless run it starts. Accepting the
settings dialog wrote the file before the dialog applied the new
collection paths, so the file kept the old ones: a company collection
chosen in the dialog stayed unknown to the assistant, and company://
paths failed in its runs, until QElectroTech was started again.
*/
class tst_assistantinfopaths : public QObject
{
Q_OBJECT
static QString writtenPath(const QString &key)
{
QFile file(AssistantInfo::path());
if (!file.open(QIODevice::ReadOnly))
return QString();
const QJsonObject folders = QJsonDocument::fromJson(file.readAll())
.object().value(QStringLiteral("folders")).toObject();
return QDir::cleanPath(folders.value(key).toString());
}
static void choose(GeneralConfigurationPage &page, const QString &box, const QString &path)
{
auto *combo = page.findChild<QComboBox *>(box);
QVERIFY(combo);
//The state the page itself leaves once a folder is picked;
//signals blocked, or index 1 opens the folder dialog
const QSignalBlocker blocker(combo);
combo->setCurrentIndex(1);
combo->setItemData(1, path, Qt::DisplayRole);
}
private slots:
void companyCollectionChosenInTheDialogIsWritten()
{
QTemporaryDir company;
QVERIFY(company.isValid());
GeneralConfigurationPage page;
choose(page, QStringLiteral("m_company_elmt_path_cb"), company.path());
page.applyConf();
QCOMPARE(writtenPath(QStringLiteral("elements_company")),
QDir::cleanPath(company.path()));
}
void customCollectionChosenInTheDialogIsWritten()
{
QTemporaryDir custom;
QVERIFY(custom.isValid());
GeneralConfigurationPage page;
choose(page, QStringLiteral("m_custom_elmt_path_cb"), custom.path());
page.applyConf();
QCOMPARE(writtenPath(QStringLiteral("elements_custom")),
QDir::cleanPath(custom.path()));
}
};
int main(int argc, char **argv)
{
//AssistantInfo writes to the standard data folder, whatever
//--data-dir says, and QETApp writes it as its editor opens: test
//mode from the very start keeps the user's own file out of reach.
QStandardPaths::setTestModeEnabled(true);
return QetAppTest::run<tst_assistantinfopaths>(argc, argv);
}
#include "tst_assistantinfopaths.moc"