fix(glossary): handle save errors and improve playlist controls

This commit is contained in:
tri committed 2026-11-07 18:48:04 +07:00
1 parent 8c42ee5a72
commit e7760e22e0
7 files changed
+204 -33

No files matched your search

+32
View File
@@ -2,6 +2,8 @@
#include "glossarystore.h"
#include <QDir>
#include <QFile>
#include <QStandardPaths>
#include <QTest>
using namespace Qt::Literals::StringLiterals;
@@ -24,6 +26,36 @@ private Q_SLOTS:
QCOMPARE(merged.entries.at(0).target, u"Lâm"_s);
QCOMPARE(merged.entries.at(1).source, u"Sect"_s);
}
void saveFailureReturnsError()
{
QTemporaryDir temp;
QVERIFY(temp.isValid());
QStandardPaths::setTestModeEnabled(true);
const QString appData = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
const QString glossaries = appData + u"/glossaries"_s;
QDir(glossaries).removeRecursively();
QVERIFY(QDir().mkpath(appData));
QFile blocker(glossaries);
QVERIFY(blocker.open(QIODevice::WriteOnly));
blocker.write("blocked");
blocker.close();
GlossaryStore::Glossary glossary{temp.path(), {{u"Original"_s, u"Translation"_s}}};
QString error;
QVERIFY(!GlossaryStore::save(glossary, &error));
QVERIFY(!error.isEmpty());
QFile::remove(glossaries);
}
void saveRejectsIncompleteEntry()
{
QString error;
QVERIFY(!GlossaryStore::save({QDir::tempPath(), {{u"Original"_s, {}}}}, &error));
QVERIFY(error.contains(u"both"_s));
}
};
QTEST_MAIN(GlossaryStoreTest)