add library with reading history, progress tracking, and view persistence

This commit is contained in:
Agel committed 2026-03-20 11:20:16 +01:00
1 parent c62733bc26
commit c4046d8533
15 files changed
+685 -40

No files matched your search

+47
View File
@@ -1,8 +1,10 @@
#include <QtTest>
#include <QSignalSpy>
#include <QUrl>
#include <QSettings>
#include "backend/BookController.h"
#include "backend/ReadingModel.h"
#include "backend/AppState.h"
class BookControllerTest : public QObject {
Q_OBJECT
@@ -14,6 +16,16 @@ private:
}
private slots:
void initTestCase()
{
QCoreApplication::setOrganizationName(QStringLiteral("AsteriaTest"));
QCoreApplication::setApplicationName(QStringLiteral("BookControllerTest"));
}
void cleanup()
{
QSettings().clear();
}
void openValidBook()
{
BookController ctrl;
@@ -109,6 +121,41 @@ private slots:
ctrl.closeBook();
QVERIFY(ctrl.currentFilePath().isEmpty());
}
void clearErrorResetsMessage()
{
BookController ctrl;
ctrl.openBook(QUrl::fromLocalFile("/tmp/file.xyz"));
QVERIFY(!ctrl.errorMessage().isEmpty());
QSignalSpy spy(&ctrl, &BookController::errorMessageChanged);
ctrl.clearError();
QVERIFY(ctrl.errorMessage().isEmpty());
QCOMPARE(spy.count(), 1);
}
void openBookSavesPositionOfPrevious()
{
AppState appState;
ReadingModel model;
BookController ctrl;
ctrl.setReadingModel(&model);
ctrl.setAppState(&appState);
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
QVERIFY(ctrl.hasBook());
QString firstPath = ctrl.currentFilePath();
// Attempt to open a second book — position of first book should be saved
// regardless of whether the second open succeeds
ctrl.openBook(QUrl::fromLocalFile("/tmp/file.xyz"));
// Position for sample.txt should have been saved (chapter 0 at minimum)
QVariantMap pos = appState.loadBookPosition(firstPath);
QVERIFY(pos.contains("chapter"));
QCOMPARE(pos["chapter"].toInt(), 0);
}
};
QTEST_MAIN(BookControllerTest)