Changeset View
Changeset View
Standalone View
Standalone View
tests/featurelib/zanshincontext.h
- This file was added.
1 | /* This file is part of Zanshin | ||||
---|---|---|---|---|---|
2 | | ||||
3 | Copyright 2014-2019 Kevin Ottens <ervin@kde.org> | ||||
4 | | ||||
5 | This program is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU General Public License as | ||||
7 | published by the Free Software Foundation; either version 2 of | ||||
8 | the License or (at your option) version 3 or any later version | ||||
9 | accepted by the membership of KDE e.V. (or its successor approved | ||||
10 | by the membership of KDE e.V.), which shall act as a proxy | ||||
11 | defined in Section 14 of version 3 of the license. | ||||
12 | | ||||
13 | This program is distributed in the hope that it will be useful, | ||||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
16 | GNU General Public License for more details. | ||||
17 | | ||||
18 | You should have received a copy of the GNU General Public License | ||||
19 | along with this program; if not, write to the Free Software | ||||
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||||
21 | USA. | ||||
22 | */ | ||||
23 | | ||||
24 | #include <QObject> | ||||
25 | #include <QPersistentModelIndex> | ||||
26 | #include <QSharedPointer> | ||||
27 | #include <QVector> | ||||
28 | | ||||
29 | #include "domain/task.h" | ||||
30 | #include "presentation/errorhandler.h" | ||||
31 | | ||||
32 | #include "testlib/akonadifakedata.h" | ||||
33 | #include "testlib/fakejob.h" | ||||
34 | | ||||
35 | class QAbstractItemModel; | ||||
36 | class QSortFilterProxyModel; | ||||
37 | class MonitorSpy; | ||||
38 | | ||||
39 | class FakeErrorHandler : public Presentation::ErrorHandler | ||||
40 | { | ||||
41 | public: | ||||
42 | void doDisplayMessage(const QString &) override; | ||||
43 | }; | ||||
44 | | ||||
45 | #define ZANSHIN_CONTEXT ZanshinContext context | ||||
46 | #define Given(a) QVERIFY(context.a) | ||||
47 | #define When(a) QVERIFY(context.a) | ||||
48 | #define Then(a) QVERIFY(context.a) | ||||
49 | #define And(a) QVERIFY(context.a) | ||||
50 | | ||||
51 | class ZanshinContext : public QObject | ||||
52 | { | ||||
53 | Q_OBJECT | ||||
54 | public: | ||||
55 | struct TableData | ||||
56 | { | ||||
57 | QVector<QByteArray> roles; | ||||
58 | QVector<QVector<QVariant>> rows; | ||||
59 | }; | ||||
60 | | ||||
61 | explicit ZanshinContext(QObject *parent = nullptr); | ||||
62 | | ||||
63 | // GIVEN | ||||
64 | Q_REQUIRED_RESULT bool I_display_the_available_data_sources(); | ||||
65 | Q_REQUIRED_RESULT bool I_display_the_available_pages(); | ||||
66 | Q_REQUIRED_RESULT bool I_display_the_page(const QString &pageName); | ||||
67 | Q_REQUIRED_RESULT bool there_is_an_item_in_the_central_list(const QString &taskName); | ||||
68 | Q_REQUIRED_RESULT bool there_is_an_item_in_the_available_data_sources(const QString &sourceName); | ||||
69 | Q_REQUIRED_RESULT bool the_central_list_contains_items_named(const QStringList &taskNames); | ||||
70 | | ||||
71 | // WHEN | ||||
72 | Q_REQUIRED_RESULT bool I_look_at_the_central_list(); | ||||
73 | Q_REQUIRED_RESULT bool I_check_the_item(); | ||||
74 | Q_REQUIRED_RESULT bool I_uncheck_the_item(); | ||||
75 | Q_REQUIRED_RESULT bool I_remove_the_item(); | ||||
76 | Q_REQUIRED_RESULT bool I_promote_the_item(); | ||||
77 | Q_REQUIRED_RESULT bool I_add_a_project(const QString &projectName, const QString &parentSourceName); | ||||
78 | Q_REQUIRED_RESULT bool I_add_a_context(const QString &contextName); | ||||
79 | Q_REQUIRED_RESULT bool I_add_a_task(const QString &taskName); | ||||
80 | Q_REQUIRED_RESULT bool I_rename_a_page(const QString &path, const QString &oldName, const QString &newName); | ||||
81 | Q_REQUIRED_RESULT bool I_remove_a_page(const QString &path, const QString &pageName); | ||||
82 | Q_REQUIRED_RESULT bool I_add_a_task_child(const QString &childName, const QString &parentName); | ||||
83 | Q_REQUIRED_RESULT bool I_list_the_items(); | ||||
84 | Q_REQUIRED_RESULT bool I_open_the_item_in_the_editor(); | ||||
85 | Q_REQUIRED_RESULT bool I_mark_the_item_done_in_the_editor(); | ||||
86 | Q_REQUIRED_RESULT bool I_change_the_editor_field(const QString &field, const QVariant &value); | ||||
87 | Q_REQUIRED_RESULT bool I_rename_the_item(const QString &taskName); | ||||
88 | Q_REQUIRED_RESULT bool I_open_the_item_in_the_editor_again(); | ||||
89 | Q_REQUIRED_RESULT bool I_drop_the_item_on_the_central_list(const QString &dropSiteName); | ||||
90 | Q_REQUIRED_RESULT bool I_drop_the_item_on_the_blank_area_of_the_central_list(); | ||||
91 | Q_REQUIRED_RESULT bool I_drop_items_on_the_central_list(const QString &dropSiteName); | ||||
92 | Q_REQUIRED_RESULT bool I_drop_the_item_on_the_page_list(const QString &pageName); | ||||
93 | Q_REQUIRED_RESULT bool I_drop_items_on_the_page_list(const QString &pageName); | ||||
94 | Q_REQUIRED_RESULT bool I_change_the_setting(const QString &key, qint64 id); | ||||
95 | Q_REQUIRED_RESULT bool I_change_the_default_data_source(const QString &sourceName); | ||||
96 | | ||||
97 | // THEN | ||||
98 | Q_REQUIRED_RESULT bool the_list_is(const TableData &data); | ||||
99 | Q_REQUIRED_RESULT bool the_list_contains(const QString &itemName); | ||||
100 | Q_REQUIRED_RESULT bool the_list_does_not_contain(const QString &itemName); | ||||
101 | Q_REQUIRED_RESULT bool the_task_corresponding_to_the_item_is_done(); | ||||
102 | Q_REQUIRED_RESULT bool the_editor_shows_the_task_as_done(); | ||||
103 | Q_REQUIRED_RESULT bool the_editor_shows_the_field(const QString &field, const QVariant &expectedValue); | ||||
104 | Q_REQUIRED_RESULT bool the_default_data_source_is(const QString &sourceName); | ||||
105 | Q_REQUIRED_RESULT bool the_setting_is(const QString &key, qint64 expectedId); | ||||
106 | | ||||
107 | private: | ||||
108 | void setModel(QAbstractItemModel *model); | ||||
109 | QAbstractItemModel *sourceModel() const; | ||||
110 | QAbstractItemModel *model() const; | ||||
111 | | ||||
112 | Domain::Task::Ptr currentTask() const; | ||||
113 | | ||||
114 | void waitForEmptyJobQueue(); | ||||
115 | void waitForStableState(); | ||||
116 | | ||||
117 | void collectIndicesImpl(const QModelIndex &root = QModelIndex()); | ||||
118 | void collectIndices(); | ||||
119 | | ||||
120 | QSharedPointer<QObject> m_appModel; | ||||
121 | | ||||
122 | QList<QPersistentModelIndex> m_indices; | ||||
123 | QPersistentModelIndex m_index; | ||||
124 | QObject *m_presentation; | ||||
125 | QObject *m_editor; | ||||
126 | QList<QPersistentModelIndex> m_dragIndices; | ||||
127 | | ||||
128 | Testlib::AkonadiFakeData m_data; | ||||
129 | | ||||
130 | QSortFilterProxyModel *m_proxyModel; | ||||
131 | QAbstractItemModel *m_model; | ||||
132 | QAbstractItemModel *m_sourceModel; | ||||
133 | MonitorSpy *m_monitorSpy; | ||||
134 | FakeErrorHandler m_errorHandler; | ||||
135 | }; |