From bf1d7ecf687adeadc98d60395a4efc7cb306e13f Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 24 Sep 2026 17:21:57 +0200 Subject: fix: add the toolbar New button, sync the month controls, and let a stale save be retried --- tests/test_calendarwindow.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'tests/test_calendarwindow.cpp') diff --git a/tests/test_calendarwindow.cpp b/tests/test_calendarwindow.cpp index 26f7237..c52f245 100644 --- a/tests/test_calendarwindow.cpp +++ b/tests/test_calendarwindow.cpp @@ -19,14 +19,17 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include +#include #include #include @@ -120,6 +123,9 @@ private slots: void saveWritesAndUndoRestoresTheOriginalBytes(); void aNewEventGoesToTheDefaultCalendar(); void aStaleSaveKeepsTheFormAndTheSyncedFile(); + void theToolbarCarriesTheNewEventAction(); + void aFreshWindowShowsTheCurrentMonth(); + void aStaleSaveCanBeRetried(); }; void TestCalendarWindow::loadsAndSelects() @@ -218,5 +224,48 @@ void TestCalendarWindow::aStaleSaveKeepsTheFormAndTheSyncedFile() QCOMPARE(w->findChild(QStringLiteral("eventTitle"))->text(), QStringLiteral("Mine")); } +void TestCalendarWindow::theToolbarCarriesTheNewEventAction() +{ + Fixture f; + std::unique_ptr w(f.window()); + auto *bar = w->findChild(QStringLiteral("calendarToolbar")); + QVERIFY(bar); + auto *newEvent = w->findChild(QStringLiteral("newEvent")); + QVERIFY(newEvent); + QVERIFY(bar->actions().contains(newEvent)); +} + +void TestCalendarWindow::aFreshWindowShowsTheCurrentMonth() +{ + Fixture f; + std::unique_ptr w( + new CalendarWindow(f.config, { QStringLiteral("me@example.org") }, + f.dir.filePath(QStringLiteral("uistate.conf")))); + const QDate today = QDate::currentDate(); + QCOMPARE(w->findChild(QStringLiteral("monthBox"))->currentData().toInt(), + today.month()); + QCOMPARE(w->findChild(QStringLiteral("yearSpin"))->value(), today.year()); +} + +void TestCalendarWindow::aStaleSaveCanBeRetried() +{ + Fixture f; + std::unique_ptr w(f.window()); + w->selectEvent(QStringLiteral("one@example.org")); + editTitle(w.get(), QStringLiteral("Mine")); + // A sync pulls a server change while the form is open. + const QByteArray synced = eventText(QStringLiteral("one@example.org"), QStringLiteral("Theirs"), 22); + writeFile(f.a(), synced); + w->findChild(QStringLiteral("saveEvent"))->click(); + QCOMPARE(read(f.a()), synced); // first Save refuses, nothing clobbered + QVERIFY(w->isEditing()); + + // The user checks what arrived and saves again deliberately: the form's + // bytes were rebased on the synced file, so this one lands. + w->findChild(QStringLiteral("saveEvent"))->click(); + QVERIFY(read(f.a()).contains("SUMMARY:Mine")); + QVERIFY(!w->isEditing()); +} + QTEST_MAIN(TestCalendarWindow) #include "test_calendarwindow.moc" -- cgit v1.2.3