Changeset View
Changeset View
Standalone View
Standalone View
tests/units/widgets/pageviewtest.cpp
Show All 18 Lines | 1 | /* This file is part of Zanshin | |||
---|---|---|---|---|---|
19 | along with this program; if not, write to the Free Software | 19 | along with this program; if not, write to the Free Software | ||
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
21 | USA. | 21 | USA. | ||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | #include <testlib/qtest_gui_zanshin.h> | 24 | #include <testlib/qtest_gui_zanshin.h> | ||
25 | 25 | | |||
26 | #include <QAbstractItemModel> | 26 | #include <QAbstractItemModel> | ||
27 | #include <QSortFilterProxyModel> | ||||
27 | #include <QAction> | 28 | #include <QAction> | ||
28 | #include <QHeaderView> | 29 | #include <QHeaderView> | ||
29 | #include <QLayout> | 30 | #include <QLayout> | ||
30 | #include <QLineEdit> | 31 | #include <QLineEdit> | ||
31 | #include <QMessageBox> | 32 | #include <QMessageBox> | ||
32 | #include <QStandardItemModel> | 33 | #include <QStandardItemModel> | ||
33 | #include <QToolButton> | 34 | #include <QToolButton> | ||
34 | #include <QTreeView> | 35 | #include <QTreeView> | ||
Show All 17 Lines | |||||
52 | 53 | | |||
53 | #include "messageboxstub.h" | 54 | #include "messageboxstub.h" | ||
54 | 55 | | |||
55 | class PageModelStub : public QObject | 56 | class PageModelStub : public QObject | ||
56 | { | 57 | { | ||
57 | Q_OBJECT | 58 | Q_OBJECT | ||
58 | Q_PROPERTY(QAbstractItemModel* centralListModel READ centralListModel) | 59 | Q_PROPERTY(QAbstractItemModel* centralListModel READ centralListModel) | ||
59 | public: | 60 | public: | ||
61 | void setProxyModel(QAbstractProxyModel *proxy) | ||||
62 | { | ||||
63 | proxyModel = proxy; | ||||
64 | proxyModel->setSourceModel(&itemModel); | ||||
65 | } | ||||
66 | | ||||
60 | QAbstractItemModel *centralListModel() | 67 | QAbstractItemModel *centralListModel() | ||
61 | { | 68 | { | ||
69 | if (proxyModel) | ||||
70 | return proxyModel; | ||||
62 | return &itemModel; | 71 | return &itemModel; | ||
63 | } | 72 | } | ||
64 | 73 | | |||
65 | QStandardItem *addStubItem(const QString &title, QStandardItem *parentItem = Q_NULLPTR) | 74 | QStandardItem *addStubItem(const QString &title, QStandardItem *parentItem = Q_NULLPTR) | ||
66 | { | 75 | { | ||
67 | QStandardItem *item = new QStandardItem; | 76 | QStandardItem *item = new QStandardItem; | ||
68 | item->setData(title, Qt::DisplayRole); | 77 | item->setData(title, Qt::DisplayRole); | ||
69 | if (!parentItem) | 78 | if (!parentItem) | ||
Show All 39 Lines | 103 | public slots: | |||
109 | } | 118 | } | ||
110 | 119 | | |||
111 | public: | 120 | public: | ||
112 | QStringList taskNames; | 121 | QStringList taskNames; | ||
113 | QList<QPersistentModelIndex> parentIndices; | 122 | QList<QPersistentModelIndex> parentIndices; | ||
114 | QList<QPersistentModelIndex> removedIndices; | 123 | QList<QPersistentModelIndex> removedIndices; | ||
115 | QList<QPersistentModelIndex> promotedIndices; | 124 | QList<QPersistentModelIndex> promotedIndices; | ||
116 | QStandardItemModel itemModel; | 125 | QStandardItemModel itemModel; | ||
126 | QAbstractProxyModel *proxyModel = nullptr; | ||||
117 | }; | 127 | }; | ||
118 | 128 | | |||
119 | class RunningTaskModelStub : public Presentation::RunningTaskModelInterface | 129 | class RunningTaskModelStub : public Presentation::RunningTaskModelInterface | ||
120 | { | 130 | { | ||
121 | Q_OBJECT | 131 | Q_OBJECT | ||
122 | public: | 132 | public: | ||
123 | Domain::Task::Ptr runningTask() const Q_DECL_OVERRIDE { return m_runningTask; } | 133 | Domain::Task::Ptr runningTask() const Q_DECL_OVERRIDE { return m_runningTask; } | ||
124 | void setRunningTask(const Domain::Task::Ptr &task) Q_DECL_OVERRIDE { m_runningTask = task; } | 134 | void setRunningTask(const Domain::Task::Ptr &task) Q_DECL_OVERRIDE { m_runningTask = task; } | ||
▲ Show 20 Lines • Show All 486 Lines • ▼ Show 20 Line(s) | 596 | { | |||
611 | QTest::keyPress(centralView, Qt::Key_Delete); | 621 | QTest::keyPress(centralView, Qt::Key_Delete); | ||
612 | 622 | | |||
613 | // THEN | 623 | // THEN | ||
614 | QVERIFY(msgbox->called()); | 624 | QVERIFY(msgbox->called()); | ||
615 | QCOMPARE(stubPageModel.removedIndices.size(), 1); | 625 | QCOMPARE(stubPageModel.removedIndices.size(), 1); | ||
616 | QCOMPARE(stubPageModel.removedIndices.first(), index); | 626 | QCOMPARE(stubPageModel.removedIndices.first(), index); | ||
617 | } | 627 | } | ||
618 | 628 | | |||
629 | void shouldDisplayNotificationWhenHittingTheDeleteKeyOnAnItemWithHiddenChildren() | ||||
630 | { | ||||
631 | // GIVEN | ||||
632 | PageModelStub stubPageModel; | ||||
633 | Q_ASSERT(stubPageModel.property("centralListModel").canConvert<QAbstractItemModel*>()); | ||||
634 | stubPageModel.addStubItems(QStringList() << QStringLiteral("A") << QStringLiteral("B")); | ||||
635 | QStandardItem *parentIndex = stubPageModel.itemModel.item(1, 0); | ||||
636 | stubPageModel.addStubItem(QStringLiteral("C"), parentIndex); | ||||
637 | | ||||
638 | QSortFilterProxyModel proxyModel; | ||||
639 | stubPageModel.setProxyModel(&proxyModel); | ||||
640 | proxyModel.setFilterFixedString("B"); | ||||
641 | | ||||
642 | QPersistentModelIndex index = stubPageModel.centralListModel()->index(0, 0); | ||||
643 | QCOMPARE(index.data().toString(), QLatin1String("B")); | ||||
644 | Widgets::PageView page; | ||||
645 | page.setModel(&stubPageModel); | ||||
646 | auto msgbox = MessageBoxStub::Ptr::create(); | ||||
647 | page.setMessageBoxInterface(msgbox); | ||||
648 | | ||||
649 | QTreeView *centralView = page.findChild<QTreeView*>(QStringLiteral("centralView")); | ||||
650 | centralView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); | ||||
651 | QVERIFY(centralView->selectionModel()->currentIndex().isValid()); | ||||
652 | centralView->setFocus(); | ||||
653 | | ||||
654 | // Needed for shortcuts to work | ||||
655 | page.show(); | ||||
656 | QVERIFY(QTest::qWaitForWindowShown(&page)); | ||||
657 | QTest::qWait(100); | ||||
658 | | ||||
659 | // WHEN | ||||
660 | QTest::keyPress(centralView, Qt::Key_Delete); | ||||
661 | | ||||
662 | // THEN | ||||
663 | QVERIFY(msgbox->called()); | ||||
664 | QCOMPARE(stubPageModel.removedIndices.size(), 1); | ||||
665 | QCOMPARE(stubPageModel.removedIndices.first(), index); | ||||
666 | } | ||||
667 | | ||||
619 | void shouldDeleteItemsWhenHittingTheDeleteKey() | 668 | void shouldDeleteItemsWhenHittingTheDeleteKey() | ||
620 | { | 669 | { | ||
621 | // GIVEN | 670 | // GIVEN | ||
622 | PageModelStub stubPageModel; | 671 | PageModelStub stubPageModel; | ||
623 | Q_ASSERT(stubPageModel.property("centralListModel").canConvert<QAbstractItemModel*>()); | 672 | Q_ASSERT(stubPageModel.property("centralListModel").canConvert<QAbstractItemModel*>()); | ||
624 | stubPageModel.addStubItems(QStringList() << QStringLiteral("A") << QStringLiteral("B") << QStringLiteral("C")); | 673 | stubPageModel.addStubItems(QStringList() << QStringLiteral("A") << QStringLiteral("B") << QStringLiteral("C")); | ||
625 | QPersistentModelIndex index = stubPageModel.itemModel.index(1, 0); | 674 | QPersistentModelIndex index = stubPageModel.itemModel.index(1, 0); | ||
626 | QPersistentModelIndex index2 = stubPageModel.itemModel.index(2, 0); | 675 | QPersistentModelIndex index2 = stubPageModel.itemModel.index(2, 0); | ||
▲ Show 20 Lines • Show All 224 Lines • Show Last 20 Lines |