Upgrade to Qt 6.10.3, refactor AppState for LibraryModel integration, add ChunkMeasurer tests, and update CI/docker configurations.
This commit is contained in:
53 files changed
+2095
-880
No files matched your search
@@ -6,6 +6,7 @@
|
||||
#include "backend/ReadingModel.h"
|
||||
#include "backend/AppState.h"
|
||||
#include "backend/IFileDialogService.h"
|
||||
#include "backend/LibraryModel.h"
|
||||
|
||||
class FakeFileDialogService : public IFileDialogService {
|
||||
Q_OBJECT
|
||||
@@ -45,6 +46,7 @@ private slots:
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
QVERIFY(readySpy.wait(5000));
|
||||
|
||||
QCOMPARE(readySpy.count(), 1);
|
||||
QVERIFY(ctrl.hasBook());
|
||||
@@ -57,6 +59,7 @@ private slots:
|
||||
QSignalSpy errorSpy(&ctrl, &BookController::bookError);
|
||||
|
||||
ctrl.openBook(QUrl::fromLocalFile("/tmp/nonexistent_asteria_file.txt"));
|
||||
QVERIFY(errorSpy.wait(5000));
|
||||
|
||||
QCOMPARE(errorSpy.count(), 1);
|
||||
QVERIFY(!ctrl.errorMessage().isEmpty());
|
||||
@@ -69,6 +72,7 @@ private slots:
|
||||
QSignalSpy errorSpy(&ctrl, &BookController::bookError);
|
||||
|
||||
ctrl.openBook(QUrl::fromLocalFile("/tmp/file.xyz"));
|
||||
QVERIFY(errorSpy.wait(5000));
|
||||
|
||||
QCOMPARE(errorSpy.count(), 1);
|
||||
QCOMPARE(ctrl.errorMessage(), QStringLiteral("No format readers available"));
|
||||
@@ -78,7 +82,9 @@ private slots:
|
||||
void closeBook()
|
||||
{
|
||||
BookController ctrl;
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
QVERIFY(readySpy.wait(5000));
|
||||
QVERIFY(ctrl.hasBook());
|
||||
|
||||
QSignalSpy changedSpy(&ctrl, &BookController::bookChanged);
|
||||
@@ -95,8 +101,10 @@ private slots:
|
||||
BookController ctrl;
|
||||
ReadingModel model;
|
||||
ctrl.setReadingModel(&model);
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
QVERIFY(readySpy.wait(5000));
|
||||
|
||||
QVERIFY(model.totalChapters() > 0);
|
||||
}
|
||||
@@ -105,10 +113,15 @@ private slots:
|
||||
{
|
||||
BookController ctrl;
|
||||
QSignalSpy loadingSpy(&ctrl, &BookController::loadingChanged);
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
|
||||
// loading goes true then false → 2 emissions
|
||||
QCOMPARE(loadingSpy.count(), 1);
|
||||
QVERIFY(ctrl.loading());
|
||||
|
||||
QVERIFY(readySpy.wait(5000));
|
||||
QCOMPARE(loadingSpy.count(), 2);
|
||||
// After completion, loading should be false
|
||||
QVERIFY(!ctrl.loading());
|
||||
@@ -123,7 +136,9 @@ private slots:
|
||||
void currentFilePathSetOnOpen()
|
||||
{
|
||||
BookController ctrl;
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
QVERIFY(readySpy.wait(5000));
|
||||
QCOMPARE(ctrl.currentFilePath(), fixturePath("sample.txt"));
|
||||
}
|
||||
|
||||
@@ -138,7 +153,9 @@ private slots:
|
||||
void clearErrorResetsMessage()
|
||||
{
|
||||
BookController ctrl;
|
||||
QSignalSpy errorSpy(&ctrl, &BookController::bookError);
|
||||
ctrl.openBook(QUrl::fromLocalFile("/tmp/file.xyz"));
|
||||
QVERIFY(errorSpy.wait(5000));
|
||||
QVERIFY(!ctrl.errorMessage().isEmpty());
|
||||
|
||||
QSignalSpy spy(&ctrl, &BookController::errorMessageChanged);
|
||||
@@ -155,8 +172,10 @@ private slots:
|
||||
BookController ctrl;
|
||||
ctrl.setReadingModel(&model);
|
||||
ctrl.setAppState(&appState);
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
QVERIFY(readySpy.wait(5000));
|
||||
QVERIFY(ctrl.hasBook());
|
||||
QString firstPath = ctrl.currentFilePath();
|
||||
|
||||
@@ -164,10 +183,10 @@ private slots:
|
||||
// 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)
|
||||
// Position for sample.txt should have been saved (0 at minimum)
|
||||
QVariantMap pos = appState.loadBookPosition(firstPath);
|
||||
QVERIFY(pos.contains("chapter"));
|
||||
QCOMPARE(pos["chapter"].toInt(), 0);
|
||||
QCOMPARE(pos[QStringLiteral("chunkIndex")].toInt(), 0);
|
||||
QCOMPARE(pos[QStringLiteral("intraChunkOffset")].toInt(), 0);
|
||||
}
|
||||
|
||||
// IFileDialogService tests
|
||||
@@ -191,6 +210,7 @@ private slots:
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
|
||||
svc.simulateSelection(fixturePath("sample.txt"));
|
||||
QVERIFY(readySpy.wait(5000));
|
||||
|
||||
QCOMPARE(readySpy.count(), 1);
|
||||
QVERIFY(ctrl.hasBook());
|
||||
@@ -203,6 +223,73 @@ private slots:
|
||||
ctrl.browseAndOpen();
|
||||
QVERIFY(!ctrl.hasBook());
|
||||
}
|
||||
|
||||
void coverImageUrlInitiallyEmpty()
|
||||
{
|
||||
BookController ctrl;
|
||||
QVERIFY(ctrl.coverImageUrl().isEmpty());
|
||||
}
|
||||
|
||||
void txtBookHasNoCoverImage()
|
||||
{
|
||||
BookController ctrl;
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
QVERIFY(readySpy.wait(5000));
|
||||
QVERIFY(ctrl.hasBook());
|
||||
QVERIFY(ctrl.coverImageUrl().isEmpty());
|
||||
}
|
||||
|
||||
void coverImageUrlClearedOnClose()
|
||||
{
|
||||
BookController ctrl;
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
ctrl.closeBook();
|
||||
QVERIFY(ctrl.coverImageUrl().isEmpty());
|
||||
}
|
||||
|
||||
void openBookUpdatesLibrary()
|
||||
{
|
||||
AppState appState;
|
||||
ReadingModel model;
|
||||
BookController ctrl;
|
||||
ctrl.setReadingModel(&model);
|
||||
ctrl.setAppState(&appState);
|
||||
auto* libraryModel = qobject_cast<QAbstractListModel*>(appState.libraryModel());
|
||||
QCOMPARE(libraryModel->rowCount(), 0);
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
|
||||
// First book open does NOT update the library (only previous reader is saved)
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
QVERIFY(readySpy.wait(5000));
|
||||
QVERIFY(ctrl.hasBook());
|
||||
QCOMPARE(libraryModel->rowCount(), 0);
|
||||
|
||||
// Closing the book should save it to library
|
||||
ctrl.closeBook();
|
||||
QCOMPARE(libraryModel->rowCount(), 1);
|
||||
QCOMPARE(libraryModel->data(libraryModel->index(0), LibraryModel::FilePathRole).toString(),
|
||||
fixturePath("sample.txt"));
|
||||
}
|
||||
|
||||
void closeBookUpdatesLibrary()
|
||||
{
|
||||
AppState appState;
|
||||
ReadingModel model;
|
||||
BookController ctrl;
|
||||
ctrl.setReadingModel(&model);
|
||||
ctrl.setAppState(&appState);
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
QVERIFY(readySpy.wait(5000));
|
||||
ctrl.closeBook();
|
||||
|
||||
auto* libraryModel = qobject_cast<QAbstractListModel*>(appState.libraryModel());
|
||||
QCOMPARE(libraryModel->rowCount(), 1);
|
||||
QCOMPARE(libraryModel->data(libraryModel->index(0), LibraryModel::FilePathRole).toString(),
|
||||
fixturePath("sample.txt"));
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(BookControllerTest)
|
||||
|
||||
Reference in new issue
Block a user