fix(glossary): handle save errors and improve playlist controls
This commit is contained in:
1 parent
3d8f644d8d
commit
309801d059
7 files changed
+204
-33
No files matched your search
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user