a bit of refactor

This commit is contained in:
Agel committed 2026-03-23 22:49:46 +01:00
1 parent 24d0b84aab
commit f84e109a64
19 files changed
+546 -232

No files matched your search

+47
View File
@@ -5,6 +5,19 @@
#include "backend/BookController.h"
#include "backend/ReadingModel.h"
#include "backend/AppState.h"
#include "backend/IFileDialogService.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
@@ -156,6 +169,40 @@ private slots:
QVERIFY(pos.contains("chapter"));
QCOMPARE(pos["chapter"].toInt(), 0);
}
// IFileDialogService tests
void browseAndOpenCallsServiceOpen()
{
BookController ctrl;
FakeFileDialogService svc;
ctrl.setFileDialogService(&svc);
ctrl.browseAndOpen();
QVERIFY(svc.openCalled);
}
void browseAndOpenUsesService()
{
BookController ctrl;
FakeFileDialogService svc;
ctrl.setFileDialogService(&svc);
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
svc.simulateSelection(fixturePath("sample.txt"));
QCOMPARE(readySpy.count(), 1);
QVERIFY(ctrl.hasBook());
}
void browseAndOpenNoopWhenNoService()
{
BookController ctrl;
// No service set — must not crash
ctrl.browseAndOpen();
QVERIFY(!ctrl.hasBook());
}
};
QTEST_MAIN(BookControllerTest)