Changeset View
Changeset View
Standalone View
Standalone View
tests/units/presentation/artifactfilterproxymodeltest.cpp
Show All 24 Lines | |||||
25 | 25 | | |||
26 | #include <QStandardItemModel> | 26 | #include <QStandardItemModel> | ||
27 | 27 | | |||
28 | #include "domain/note.h" | 28 | #include "domain/note.h" | ||
29 | #include "domain/task.h" | 29 | #include "domain/task.h" | ||
30 | 30 | | |||
31 | #include "presentation/artifactfilterproxymodel.h" | 31 | #include "presentation/artifactfilterproxymodel.h" | ||
32 | #include "presentation/querytreemodelbase.h" | 32 | #include "presentation/querytreemodelbase.h" | ||
33 | #include "utils/datetime.h" | ||||
33 | 34 | | |||
34 | Q_DECLARE_METATYPE(QList<QStandardItem*>) | 35 | Q_DECLARE_METATYPE(QList<QStandardItem*>) | ||
35 | 36 | | |||
36 | class ArtifactFilterProxyModelTest : public QObject | 37 | class ArtifactFilterProxyModelTest : public QObject | ||
37 | { | 38 | { | ||
38 | Q_OBJECT | 39 | Q_OBJECT | ||
39 | private: | 40 | private: | ||
40 | QStandardItem *createTaskItem(const QString &title, const QString &text, | 41 | QStandardItem *createTaskItem(const QString &title, const QString &text, | ||
41 | const QDate &start = QDate(), | 42 | const QDate &start = QDate(), | ||
42 | const QDate &due = QDate()) const | 43 | const QDate &due = QDate()) const | ||
43 | { | 44 | { | ||
44 | auto task = Domain::Task::Ptr::create(); | 45 | auto task = Domain::Task::Ptr::create(); | ||
45 | task->setTitle(title); | 46 | task->setTitle(title); | ||
46 | task->setText(text); | 47 | task->setText(text); | ||
47 | task->setStartDate(QDateTime(start)); | 48 | task->setStartDate(start); | ||
48 | task->setDueDate(QDateTime(due)); | 49 | task->setDueDate(due); | ||
49 | 50 | | |||
50 | auto item = new QStandardItem; | 51 | auto item = new QStandardItem; | ||
51 | item->setData(task->title(), Qt::DisplayRole); | 52 | item->setData(task->title(), Qt::DisplayRole); | ||
52 | item->setData(QVariant::fromValue(Domain::Artifact::Ptr(task)), | 53 | item->setData(QVariant::fromValue(Domain::Artifact::Ptr(task)), | ||
53 | Presentation::QueryTreeModelBase::ObjectRole); | 54 | Presentation::QueryTreeModelBase::ObjectRole); | ||
54 | return item; | 55 | return item; | ||
55 | } | 56 | } | ||
56 | 57 | | |||
57 | QStandardItem *createNoteItem(const QString &title, const QString &text) const | 58 | QStandardItem *createNoteItem(const QString &title, const QString &text) const | ||
58 | { | 59 | { | ||
59 | auto note = Domain::Note::Ptr::create(); | 60 | auto note = Domain::Note::Ptr::create(); | ||
60 | note->setTitle(title); | 61 | note->setTitle(title); | ||
61 | note->setText(text); | 62 | note->setText(text); | ||
62 | 63 | | |||
63 | auto item = new QStandardItem; | 64 | auto item = new QStandardItem; | ||
64 | item->setData(note->title(), Qt::DisplayRole); | 65 | item->setData(note->title(), Qt::DisplayRole); | ||
65 | item->setData(QVariant::fromValue(Domain::Artifact::Ptr(note)), | 66 | item->setData(QVariant::fromValue(Domain::Artifact::Ptr(note)), | ||
66 | Presentation::QueryTreeModelBase::ObjectRole); | 67 | Presentation::QueryTreeModelBase::ObjectRole); | ||
67 | return item; | 68 | return item; | ||
68 | } | 69 | } | ||
69 | 70 | | |||
70 | private slots: | 71 | private slots: | ||
72 | void initTestCase() | ||||
73 | { | ||||
74 | qputenv("ZANSHIN_OVERRIDE_DATE", "2015-03-11"); | ||||
75 | } | ||||
76 | | ||||
71 | void shouldHaveDefaultState() | 77 | void shouldHaveDefaultState() | ||
72 | { | 78 | { | ||
73 | Presentation::ArtifactFilterProxyModel proxy; | 79 | Presentation::ArtifactFilterProxyModel proxy; | ||
74 | QVERIFY(!proxy.sourceModel()); | 80 | QVERIFY(!proxy.sourceModel()); | ||
75 | QCOMPARE(proxy.sortColumn(), 0); | 81 | QCOMPARE(proxy.sortColumn(), 0); | ||
76 | QCOMPARE(proxy.sortOrder(), Qt::AscendingOrder); | 82 | QCOMPARE(proxy.sortOrder(), Qt::AscendingOrder); | ||
77 | QCOMPARE(proxy.sortType(), Presentation::ArtifactFilterProxyModel::TitleSort); | 83 | QCOMPARE(proxy.sortType(), Presentation::ArtifactFilterProxyModel::TitleSort); | ||
78 | QCOMPARE(proxy.sortCaseSensitivity(), Qt::CaseInsensitive); | 84 | QCOMPARE(proxy.sortCaseSensitivity(), Qt::CaseInsensitive); | ||
Show All 24 Lines | 89 | { | |||
103 | QCOMPARE(output.index(2, 0).data().toString(), QStringLiteral("4. foo")); | 109 | QCOMPARE(output.index(2, 0).data().toString(), QStringLiteral("4. foo")); | ||
104 | QCOMPARE(output.index(3, 0).data().toString(), QStringLiteral("5. find me")); | 110 | QCOMPARE(output.index(3, 0).data().toString(), QStringLiteral("5. find me")); | ||
105 | } | 111 | } | ||
106 | 112 | | |||
107 | void shouldFilterByStartDate() | 113 | void shouldFilterByStartDate() | ||
108 | { | 114 | { | ||
109 | // GIVEN | 115 | // GIVEN | ||
110 | QStandardItemModel input; | 116 | QStandardItemModel input; | ||
111 | input.appendRow(createTaskItem(QStringLiteral("1. past"), QStringLiteral(""), QDate::currentDate().addDays(-1))); | 117 | const auto today = Utils::DateTime::currentDate(); | ||
112 | input.appendRow(createTaskItem(QStringLiteral("2. present"), QStringLiteral(""), QDate::currentDate())); | 118 | input.appendRow(createTaskItem(QStringLiteral("1. past"), QStringLiteral(""), today.addDays(-1))); | ||
113 | input.appendRow(createTaskItem(QStringLiteral("3. future"), QStringLiteral(""), QDate::currentDate().addDays(1))); | 119 | input.appendRow(createTaskItem(QStringLiteral("2. present"), QStringLiteral(""), today)); | ||
120 | input.appendRow(createTaskItem(QStringLiteral("3. future"), QStringLiteral(""), today.addDays(1))); | ||||
114 | input.appendRow(createTaskItem(QStringLiteral("4. whatever"), QStringLiteral(""))); | 121 | input.appendRow(createTaskItem(QStringLiteral("4. whatever"), QStringLiteral(""))); | ||
115 | 122 | | |||
116 | Presentation::ArtifactFilterProxyModel output; | 123 | Presentation::ArtifactFilterProxyModel output; | ||
117 | output.setSourceModel(&input); | 124 | output.setSourceModel(&input); | ||
118 | 125 | | |||
119 | // WHEN | 126 | // WHEN | ||
120 | output.setShowFutureTasks(true); | 127 | output.setShowFutureTasks(true); | ||
121 | 128 | | |||
▲ Show 20 Lines • Show All 168 Lines • Show Last 20 Lines |