File indexing completed on 2024-12-01 04:35:23

0001 /*
0002    SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "discussionsfilterproxymodeltest.h"
0008 #include "discussions/discussions.h"
0009 #include "model/discussionsfilterproxymodel.h"
0010 #include "model/discussionsmodel.h"
0011 #include <QTest>
0012 QTEST_GUILESS_MAIN(DiscussionsFilterProxyModelTest)
0013 DiscussionsFilterProxyModelTest::DiscussionsFilterProxyModelTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void DiscussionsFilterProxyModelTest::shouldHaveDefaultValues()
0019 {
0020     DiscussionsFilterProxyModel proxy;
0021     DiscussionsModel model;
0022     proxy.setSourceModel(&model);
0023     QCOMPARE(proxy.rowCount(), 0);
0024 
0025     QCOMPARE(proxy.filterCaseSensitivity(), Qt::CaseInsensitive);
0026     QCOMPARE(proxy.filterRole(), DiscussionsModel::Description);
0027     QCOMPARE(proxy.sortRole(), DiscussionsModel::SortByTimeStamp);
0028 }
0029 
0030 void DiscussionsFilterProxyModelTest::shouldAssignValue()
0031 {
0032     DiscussionsFilterProxyModel proxy;
0033     DiscussionsModel model;
0034     proxy.setSourceModel(&model);
0035 
0036     Discussions discussionList;
0037     for (int i = 0; i < 10; ++i) {
0038         Discussion c;
0039         c.setDescription(QStringLiteral("roomid%1").arg(i));
0040         c.setNumberMessages(i);
0041         c.setParentRoomId(QStringLiteral("online"));
0042         discussionList.append(std::move(c));
0043     }
0044     model.setDiscussions(discussionList);
0045 
0046     QCOMPARE(model.rowCount(), 10);
0047     QCOMPARE(proxy.rowCount(), 10);
0048 
0049     discussionList.clear();
0050     for (int i = 0; i < 3; ++i) {
0051         Discussion c;
0052         c.setDescription(QStringLiteral("roomid%1").arg(i));
0053         c.setNumberMessages(i);
0054         c.setParentRoomId(QStringLiteral("online"));
0055         discussionList.append(std::move(c));
0056     }
0057     model.setDiscussions(discussionList);
0058     QCOMPARE(model.rowCount(), 3);
0059     QCOMPARE(proxy.rowCount(), 3);
0060 }
0061 
0062 #include "moc_discussionsfilterproxymodeltest.cpp"