added txt support
This commit is contained in:
1 parent
3c0037cfc9
commit
64a70bc4cf
22 files changed
+800
-186
No files matched your search
@@ -0,0 +1,94 @@
|
||||
#include <QtTest>
|
||||
#include <QSignalSpy>
|
||||
#include <QUrl>
|
||||
#include "backend/BookController.h"
|
||||
#include "backend/ReadingModel.h"
|
||||
|
||||
class BookControllerTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QString fixturePath(const QString &filename) const
|
||||
{
|
||||
return QStringLiteral(FIXTURES_DIR) + "/" + filename;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void openValidBook()
|
||||
{
|
||||
BookController ctrl;
|
||||
QSignalSpy readySpy(&ctrl, &BookController::bookReady);
|
||||
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
|
||||
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"));
|
||||
|
||||
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"));
|
||||
|
||||
QCOMPARE(errorSpy.count(), 1);
|
||||
QCOMPARE(ctrl.errorMessage(), QStringLiteral("No format readers available"));
|
||||
QVERIFY(!ctrl.hasBook());
|
||||
}
|
||||
|
||||
void closeBook()
|
||||
{
|
||||
BookController ctrl;
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
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);
|
||||
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
|
||||
QVERIFY(model.totalChapters() > 0);
|
||||
}
|
||||
|
||||
void loadingTransitions()
|
||||
{
|
||||
BookController ctrl;
|
||||
QSignalSpy loadingSpy(&ctrl, &BookController::loadingChanged);
|
||||
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
|
||||
// loading goes true then false → 2 emissions
|
||||
QCOMPARE(loadingSpy.count(), 2);
|
||||
// After completion, loading should be false
|
||||
QVERIFY(!ctrl.loading());
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(BookControllerTest)
|
||||
#include "BookControllerTest.moc"
|
||||
Reference in new issue
Block a user