Remove obsolete BookController files and update documentation
BookController was superseded by the Book class during a prior refactoring. The old files were never removed and are not in CMakeLists.txt. Deleted: - src/backend/BookController.h/cpp (not in build, calls non-existent AppState APIs) - tests/BookControllerTest.cpp (not in CMake test targets) Updated CLAUDE.md architecture documentation to reference Book instead of BookController for all book management operations and tests. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
4 files changed
+8
-658
No files matched your search
@@ -1,296 +0,0 @@
|
||||
#include <QtTest>
|
||||
#include <QSignalSpy>
|
||||
#include <QUrl>
|
||||
#include <QSettings>
|
||||
#include "backend/BookController.h"
|
||||
#include "backend/ReadingModel.h"
|
||||
#include "backend/AppState.h"
|
||||
#include "backend/IFileDialogService.h"
|
||||
#include "backend/LibraryModel.h"
|
||||
|
||||
class FakeFileDialogService : public IFileDialogService {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FakeFileDialogService(QObject *parent = nullptr)
|
||||
: IFileDialogService(parent) {}
|
||||
|
||||
void open() override { openCalled = true; }
|
||||
void simulateSelection(const QString &path) { emit fileSelected(path); }
|
||||
|
||||
bool openCalled = false;
|
||||
};
|
||||
|
||||
class BookControllerTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QString fixturePath(const QString &filename) const
|
||||
{
|
||||
return QStringLiteral(FIXTURES_DIR) + "/" + filename;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
QCoreApplication::setOrganizationName(QStringLiteral("AsteriaTest"));
|
||||
QCoreApplication::setApplicationName(QStringLiteral("BookControllerTest"));
|
||||
}
|
||||
|
||||
void cleanup()
|
||||
{
|
||||
QSettings().clear();
|
||||
}
|
||||
void openValidBook()
|
||||
{
|
||||
BookController ctrl;
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
QVERIFY(readySpy.wait(5000));
|
||||
|
||||
QCOMPARE(readySpy.count(), 1);
|
||||
QVERIFY(ctrl.hasBook());
|
||||
QCOMPARE(ctrl.bookTitle(), QStringLiteral("sample"));
|
||||
}
|
||||
|
||||
void openInvalidPath()
|
||||
{
|
||||
BookController ctrl;
|
||||
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());
|
||||
QVERIFY(!ctrl.hasBook());
|
||||
}
|
||||
|
||||
void openUnsupportedFormat()
|
||||
{
|
||||
BookController ctrl;
|
||||
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"));
|
||||
QVERIFY(!ctrl.hasBook());
|
||||
}
|
||||
|
||||
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);
|
||||
ctrl.closeBook();
|
||||
|
||||
QVERIFY(!ctrl.hasBook());
|
||||
QVERIFY(ctrl.bookTitle().isEmpty());
|
||||
QVERIFY(ctrl.bookAuthor().isEmpty());
|
||||
QCOMPARE(changedSpy.count(), 1);
|
||||
}
|
||||
|
||||
void openBookSetsReadingModel()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void loadingTransitions()
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
void currentFilePathInitiallyEmpty()
|
||||
{
|
||||
BookController ctrl;
|
||||
QVERIFY(ctrl.currentFilePath().isEmpty());
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
void currentFilePathClearedOnClose()
|
||||
{
|
||||
BookController ctrl;
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
ctrl.closeBook();
|
||||
QVERIFY(ctrl.currentFilePath().isEmpty());
|
||||
}
|
||||
|
||||
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);
|
||||
ctrl.clearError();
|
||||
|
||||
QVERIFY(ctrl.errorMessage().isEmpty());
|
||||
QCOMPARE(spy.count(), 1);
|
||||
}
|
||||
|
||||
void openBookSavesPositionOfPrevious()
|
||||
{
|
||||
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));
|
||||
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 (0 at minimum)
|
||||
QVariantMap pos = appState.loadBookPosition(firstPath);
|
||||
QCOMPARE(pos[QStringLiteral("chunkIndex")].toInt(), 0);
|
||||
QCOMPARE(pos[QStringLiteral("intraChunkOffset")].toInt(), 0);
|
||||
}
|
||||
|
||||
// IFileDialogService tests
|
||||
|
||||
void browseAndOpenCallsServiceOpen() const
|
||||
{
|
||||
BookController ctrl;
|
||||
FakeFileDialogService svc;
|
||||
ctrl.setFileDialogService(&svc);
|
||||
|
||||
ctrl.browseAndOpen();
|
||||
|
||||
QVERIFY(svc.openCalled);
|
||||
}
|
||||
|
||||
void browseAndOpenUsesService() const
|
||||
{
|
||||
BookController ctrl;
|
||||
FakeFileDialogService svc;
|
||||
ctrl.setFileDialogService(&svc);
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
|
||||
svc.simulateSelection(fixturePath("sample.txt"));
|
||||
QVERIFY(readySpy.wait(5000));
|
||||
|
||||
QCOMPARE(readySpy.count(), 1);
|
||||
QVERIFY(ctrl.hasBook());
|
||||
}
|
||||
|
||||
void browseAndOpenNoopWhenNoService() const
|
||||
{
|
||||
BookController ctrl;
|
||||
// No service set — must not crash
|
||||
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)
|
||||
#include "BookControllerTest.moc"
|
||||
Reference in new issue
Block a user