5be7f7f04b
- Qt 6 desktop client with day/month/year views, AI scheduling, and TOML settings\n- Go sync server with SQLite change stream, WebSocket notifications, and Docker deployment\n- Client outbox/LWW sync, offline retry, and dual-client integration tests\n- Linux fcitx5 setup, validation reports, and Windows MinGW preset
133 lines
3.9 KiB
C++
133 lines
3.9 KiB
C++
#include <QApplication>
|
|
#include <QScrollBar>
|
|
#include <QTemporaryDir>
|
|
#include <QTimer>
|
|
#include <QtTest>
|
|
|
|
#include <memory>
|
|
|
|
#include "core/ScheduleItem.h"
|
|
#include "services/NotificationService.h"
|
|
#include "services/ScheduleService.h"
|
|
#include "storage/SqliteStore.h"
|
|
#include "ui/MainWindow.h"
|
|
#include "ui/dialogs/BlockEditDialog.h"
|
|
#include "ui/theme/ThemeManager.h"
|
|
#include "ui/views/ScheduleGridView.h"
|
|
#include "utils/AppSettings.h"
|
|
|
|
#include "ElaLineEdit.h"
|
|
|
|
class TestMainWindow : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
void initTestCase();
|
|
void createEditAndDeleteThroughUi();
|
|
|
|
private:
|
|
static void fillDialogAndAccept(const QString& title, bool accept);
|
|
|
|
QTemporaryDir m_tempDir;
|
|
std::unique_ptr<AppSettings> m_settings;
|
|
};
|
|
|
|
void TestMainWindow::initTestCase()
|
|
{
|
|
QVERIFY(m_tempDir.isValid());
|
|
QCoreApplication::setOrganizationName(QStringLiteral("ScheduleTest"));
|
|
QCoreApplication::setApplicationName(QStringLiteral("ScheduleTest"));
|
|
m_settings = std::make_unique<AppSettings>(m_tempDir.filePath(QStringLiteral("config.toml")));
|
|
}
|
|
|
|
void TestMainWindow::fillDialogAndAccept(const QString& title, bool accept)
|
|
{
|
|
QTimer::singleShot(400, [title, accept]() {
|
|
for (QWidget* widget : QApplication::topLevelWidgets())
|
|
{
|
|
auto* dialog = qobject_cast<BlockEditDialog*>(widget);
|
|
if (!dialog)
|
|
{
|
|
continue;
|
|
}
|
|
const auto edits = dialog->findChildren<ElaLineEdit*>();
|
|
if (!edits.isEmpty())
|
|
{
|
|
edits.first()->setText(title);
|
|
}
|
|
if (accept)
|
|
{
|
|
dialog->accept();
|
|
}
|
|
else
|
|
{
|
|
dialog->reject();
|
|
}
|
|
return;
|
|
}
|
|
});
|
|
QTimer::singleShot(2000, []() {
|
|
for (QWidget* widget : QApplication::topLevelWidgets())
|
|
{
|
|
if (auto* dialog = qobject_cast<BlockEditDialog*>(widget))
|
|
{
|
|
dialog->reject();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
void TestMainWindow::createEditAndDeleteThroughUi()
|
|
{
|
|
QTemporaryDir databaseDir;
|
|
QVERIFY(databaseDir.isValid());
|
|
SqliteStore store(databaseDir.filePath(QStringLiteral("schedule.db")));
|
|
QString error;
|
|
QVERIFY2(store.open(&error), qPrintable(error));
|
|
|
|
ThemeManager theme(*m_settings);
|
|
theme.initialize();
|
|
ScheduleService service(store, QStringLiteral("ui-test-device"));
|
|
NotificationService notifications(service);
|
|
|
|
MainWindow window(service, notifications, theme, *m_settings);
|
|
window.show();
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
QTest::qWait(60);
|
|
|
|
auto* grid = window.findChild<ScheduleGridView*>();
|
|
QVERIFY(grid);
|
|
grid->scrollToHour(8);
|
|
QTest::qWait(20);
|
|
const int scroll = grid->verticalScrollBar()->value();
|
|
const QPoint createPoint(300, 8 * 120 - scroll + 5);
|
|
|
|
fillDialogAndAccept(QStringLiteral("自动测试日程"), true);
|
|
QTest::mouseDClick(grid->viewport(), Qt::LeftButton, Qt::NoModifier, createPoint, 10);
|
|
QTest::qWait(80);
|
|
|
|
QVector<ScheduleItem> items = service.itemsForDay(QDate::currentDate());
|
|
QCOMPARE(items.size(), 1);
|
|
QCOMPARE(items.first().task.title, QStringLiteral("自动测试日程"));
|
|
const QString blockId = items.first().block.id;
|
|
|
|
const QPoint editPoint(300, 8 * 120 - scroll + 40);
|
|
fillDialogAndAccept(QStringLiteral("改名为复盘"), true);
|
|
QTest::mouseDClick(grid->viewport(), Qt::LeftButton, Qt::NoModifier, editPoint, 10);
|
|
QTest::qWait(80);
|
|
|
|
items = service.itemsForDay(QDate::currentDate());
|
|
QCOMPARE(items.size(), 1);
|
|
QCOMPARE(items.first().task.title, QStringLiteral("改名为复盘"));
|
|
|
|
grid->setFocus();
|
|
grid->setSelectedBlock(blockId);
|
|
QTest::keyClick(grid, Qt::Key_Delete);
|
|
QTest::qWait(80);
|
|
QVERIFY(service.itemsForDay(QDate::currentDate()).isEmpty());
|
|
}
|
|
|
|
QTEST_MAIN(TestMainWindow)
|
|
#include "test_mainwindow.moc"
|