Refactor using Fable

This commit is contained in:
Agel committed 2026-07-31 17:31:02 +02:00
1 parent 1a60a6b93c
commit 83968646c6
90 files changed
+2080 -2267

No files matched your search

+22 -13
View File
@@ -12,13 +12,18 @@
#include "backend/FormatReader.h"
#include "backend/formats/EpubReader.h"
#include "backend/formats/TxtReader.h"
#include "backend/formats/ReaderFactory.h"
#include "backend/formats/FormatRegistry.h"
#include "backend/formats/sources/ZipByteSource.h"
static ReaderFactory makeFactory()
static FormatRegistry makeRegistry()
{
return ReaderFactory({
[] { return std::make_unique<TxtReader>(); },
[] { return std::make_unique<EpubReader>(); },
return FormatRegistry({
{QStringLiteral("txt"), false, {},
[] { return std::make_unique<TxtReader>(); }, nullptr},
{QStringLiteral("epub"), false, QStringLiteral("epub"),
[] { return std::make_unique<EpubReader>(); },
[] { return std::make_unique<ZipByteSource>(); },
/*loaderIncludesWeb=*/true},
});
}
@@ -125,10 +130,11 @@ private slots:
const QString epubPath = buildEpubWithCover();
QVERIFY(!epubPath.isEmpty());
ReaderFactory factory = makeFactory();
HistoryBookModel model(epubPath, 0.0, QString(), factory);
FormatRegistry registry = makeRegistry();
HistoryBookModel model(epubPath, 0.0, QString(), registry);
QSignalSpy spy(&model, &HistoryBookModel::metadataLoaded);
QSignalSpy coverSpy(&model, &HistoryBookModel::coverImageLoaded);
model.loadMetadata();
// Wait up to 5 seconds for the async metadata load to complete
@@ -136,10 +142,13 @@ private slots:
QFile::remove(epubPath);
// coverImageUrl's NOTIFY signal must fire so QML bindings update
QCOMPARE(coverSpy.count(), 1);
const QString url = model.coverImageUrl();
QVERIFY2(!url.isEmpty(), "coverImageUrl should be set after loadMetadata for an EPUB with cover");
// Format: image://epub/<internal-path>?epub=<encoded-epub-path>
QVERIFY2(url.startsWith(QStringLiteral("image://epub/OEBPS/Images/cover.png?epub=")),
// Format: image://epub/<internal-path>?src=<encoded-epub-path>
QVERIFY2(url.startsWith(QStringLiteral("image://epub/OEBPS/Images/cover.png?src=")),
qPrintable("Expected query-param URL format, got: " + url));
const QString encodedPath = QString::fromUtf8(QUrl::toPercentEncoding(epubPath));
QVERIFY2(url.contains(encodedPath),
@@ -151,8 +160,8 @@ private slots:
const QString txtPath = QStringLiteral(FIXTURES_DIR) + "/sample.txt";
QVERIFY(QFile::exists(txtPath));
ReaderFactory factory = makeFactory();
HistoryBookModel model(txtPath, 0.0, QString(), factory);
FormatRegistry registry = makeRegistry();
HistoryBookModel model(txtPath, 0.0, QString(), registry);
QSignalSpy spy(&model, &HistoryBookModel::metadataLoaded);
model.loadMetadata();
@@ -168,8 +177,8 @@ private slots:
const QString epubPath = buildEpubWithCover();
QVERIFY(!epubPath.isEmpty());
ReaderFactory factory = makeFactory();
HistoryBookModel model(epubPath, 0.0, QString(), factory);
FormatRegistry registry = makeRegistry();
HistoryBookModel model(epubPath, 0.0, QString(), registry);
QSignalSpy spy(&model, &HistoryBookModel::metadataLoaded);
model.loadMetadata();