Commit 5ed7df56 authored by Claudio Cambra's avatar Claudio Cambra
Browse files

Add barebones testing for todosortfilterproxymodel

parents f7662347 6e76da25
Pipeline #134612 passed with stage
in 1 minute and 28 seconds
......@@ -8,23 +8,32 @@ include_directories(${kalendar_CURRENT_BINARY_DIR})
include_directories(${kalendar_BINARY_DIR})
include_directories(${kalendar_BINARY_DIR}/src)
set(incidenceOccurrenceModelTest_SRCS
incidenceoccurrencemodeltest.cpp
../src/models/incidenceoccurrencemodel.cpp
)
ecm_qt_declare_logging_category(incidenceOccurrenceModelTest_SRCS HEADER kalendar_debug.h IDENTIFIER KALENDAR_LOG CATEGORY_NAME org.kde.kalendar DESCRIPTION "kalendar" EXPORT KALENDAR)
set (incidenceOccurrenceModelTest_LIBS
set (commonAkonadiTest_LIBS
Qt::Test
Qt5::Core
KF5::ConfigCore
KF5::CalendarCore
KF5::CalendarSupport
KF5::AkonadiCore
KF5::AkonadiCalendar
KF5::EventViews
)
set(incidenceOccurrenceModelTest_SRCS
incidenceoccurrencemodeltest.cpp
../src/models/incidenceoccurrencemodel.cpp
)
set(todoSortFilterProxyModelTest_SRCS
todosortfilterproxymodeltest.cpp
../src/models/todosortfilterproxymodel.cpp
)
ecm_qt_declare_logging_category(incidenceOccurrenceModelTest_SRCS HEADER kalendar_debug.h IDENTIFIER KALENDAR_LOG CATEGORY_NAME org.kde.kalendar DESCRIPTION "kalendar" EXPORT KALENDAR)
# the tests need the ical resource, which we might not have at this point (e.g. on the CI)
find_program(AKONADI_ICAL_RESOURCE NAMES akonadi_ical_resource)
# if (AKONADI_ICAL_RESOURCE)
add_akonadi_isolated_test_advanced(incidenceoccurrencemodeltest.cpp "${incidenceOccurrenceModelTest_SRCS}" "${incidenceOccurrenceModelTest_LIBS}")
add_akonadi_isolated_test_advanced(incidenceoccurrencemodeltest.cpp "${incidenceOccurrenceModelTest_SRCS}" "${commonAkonadiTest_LIBS}")
add_akonadi_isolated_test_advanced(todosortfilterproxymodeltest.cpp "${todoSortFilterProxyModelTest_SRCS}" "${commonAkonadiTest_LIBS}")
# endif()
// SPDX-FileCopyrightText: 2022 Claudio Cambra <claudio.cambra@gmail.com>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "../src/models/todosortfilterproxymodel.h"
#include <Akonadi/Calendar/IncidenceChanger>
#include <KCalendarCore/Incidence>
#include <KCheckableProxyModel>
#include <KFormat>
#include <QAbstractItemModelTester>
#include <QSignalSpy>
#include <QTest>
#include <akonadi/qtest_akonadi.h>
class TodoSortFilterProxyModelTest : public QObject
{
Q_OBJECT
public:
TodoSortFilterProxyModelTest() = default;
~TodoSortFilterProxyModelTest() = default;
void checkAllItems(KCheckableProxyModel *model, const QModelIndex &parent = QModelIndex())
{
const int rowCount = model->rowCount(parent);
for (int row = 0; row < rowCount; ++row) {
QModelIndex index = model->index(row, 0, parent);
model->setData(index, Qt::Checked, Qt::CheckStateRole);
if (model->rowCount(index) > 0) {
checkAllItems(model, index);
}
}
}
signals:
void calendarLoaded();
private:
Akonadi::ETMCalendar::Ptr calendar;
TodoSortFilterProxyModel model;
QAbstractItemModelTester modelTester = QAbstractItemModelTester(&model);
QTimer loadedCheckTimer;
QDateTime now = QDate(2022, 01, 10).startOfDay();
private slots:
void initTestCase()
{
AkonadiTest::checkTestIsIsolated();
calendar.reset(new Akonadi::ETMCalendar);
QSignalSpy collectionsAdded(calendar.data(), &Akonadi::ETMCalendar::collectionsAdded);
QVERIFY(collectionsAdded.wait(10000));
loadedCheckTimer.setInterval(300);
loadedCheckTimer.setSingleShot(true);
connect(&loadedCheckTimer, &QTimer::timeout, this, [&]() {
if (calendar->isLoaded()) {
Q_EMIT calendarLoaded();
} else {
loadedCheckTimer.start();
}
});
QSignalSpy loaded(this, &TodoSortFilterProxyModelTest::calendarLoaded);
loaded.wait(10000);
checkAllItems(calendar->checkableProxyModel());
qRegisterMetaType<QList<QPersistentModelIndex>>();
qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>();
}
void testAddCalendar()
{
QVERIFY(calendar->isLoaded());
QVERIFY(calendar->items().count() > 0);
QSignalSpy fetchFinished(&model, &QAbstractItemModel::modelReset);
model.setCalendar(calendar);
QCOMPARE(model.calendar()->id(), calendar->id());
fetchFinished.wait(10000);
// Our test calendar file has two todos, with sub-todos
QCOMPARE(model.rowCount(), 2);
}
};
QTEST_MAIN(TodoSortFilterProxyModelTest)
#include "todosortfilterproxymodeltest.moc"
......@@ -2,12 +2,62 @@ BEGIN:VCALENDAR
PRODID:-//K Desktop Environment//NONSGML libkcal 4.3//EN
VERSION:2.0
X-KDE-ICAL-IMPLEMENTATION-VERSION:1.0
BEGIN:VTODO
DTSTAMP:20220206T113034Z
CREATED:20220129T134803Z
UID:93ffb2ae-8d28-40e7-a839-8b6989a63bcf
SEQUENCE:1
LAST-MODIFIED:20220206T113034Z
SUMMARY:Ndt1 sub todo 2
RELATED-TO:feb26aa4-4da9-41dc-8397-643687e97fbf
COMPLETED:20220206T113034Z
PERCENT-COMPLETE:100
STATUS:COMPLETED
END:VTODO
BEGIN:VTODO
DTSTAMP:20220129T134801Z
CREATED:20220129T134735Z
UID:7ae6148e-aedb-4653-b9e6-d7a70ec3c95e
SEQUENCE:1
LAST-MODIFIED:20220129T134801Z
SUMMARY:Ndt1 st1 sub todo 1
RELATED-TO:3e61490d-888e-48c4-9b8b-a081295abe9c
PERCENT-COMPLETE:0
END:VTODO
BEGIN:VTODO
DTSTAMP:20220129T134716Z
CREATED:20220129T134716Z
UID:feb26aa4-4da9-41dc-8397-643687e97fbf
LAST-MODIFIED:20220129T134716Z
SUMMARY:No date todo 1
PERCENT-COMPLETE:0
END:VTODO
BEGIN:VTODO
DTSTAMP:20220206T113031Z
CREATED:20220129T134720Z
UID:2b81b1bb-1aec-46d2-8df1-20f77789e450
SEQUENCE:1
LAST-MODIFIED:20220206T113031Z
SUMMARY:No date todo 2
COMPLETED:20220206T113031Z
PERCENT-COMPLETE:100
STATUS:COMPLETED
END:VTODO
BEGIN:VTODO
DTSTAMP:20220129T134724Z
CREATED:20220129T134724Z
UID:3e61490d-888e-48c4-9b8b-a081295abe9c
LAST-MODIFIED:20220129T134724Z
SUMMARY:Ndt1 sub todo 1
RELATED-TO:feb26aa4-4da9-41dc-8397-643687e97fbf
PERCENT-COMPLETE:0
END:VTODO
BEGIN:VEVENT
DTSTAMP:20220116T150158Z
DTSTAMP:20220206T113125Z
CREATED:20220115T134647Z
UID:0729311a-d9ad-40b5-a836-b4cc64c96727
SEQUENCE:9
LAST-MODIFIED:20220116T150158Z
LAST-MODIFIED:20220206T113125Z
DESCRIPTION:Big testing description
SUMMARY:Test event
LOCATION:Testing land
......
......@@ -33,6 +33,11 @@ TodoSortFilterProxyModel::~TodoSortFilterProxyModel()
delete m_todoTreeModel;
}
int TodoSortFilterProxyModel::columnCount(const QModelIndex &parent) const
{
return 1;
}
QHash<int, QByteArray> TodoSortFilterProxyModel::roleNames() const
{
QHash<int, QByteArray> roleNames = QSortFilterProxyModel::roleNames();
......
......@@ -77,6 +77,7 @@ public:
TodoSortFilterProxyModel(QObject *parent = nullptr);
~TodoSortFilterProxyModel();
int columnCount(const QModelIndex &parent) const override;
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool filterAcceptsRow(int row, const QModelIndex &sourceParent) const override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment