File indexing completed on 2025-01-19 04:56:59
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Kevin Ottens <ervin@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 0007 #include <testlib/qtest_gui_zanshin.h> 0008 0009 #include <QAbstractButton> 0010 #include <QLabel> 0011 #include <QListView> 0012 #include <QPlainTextEdit> 0013 #include <QStandardItemModel> 0014 #include <QToolButton> 0015 0016 #include <KDateComboBox> 0017 #include <KLocalizedString> 0018 0019 #include "domain/task.h" 0020 0021 #include "widgets/editorview.h" 0022 0023 class EditorModelStub : public QObject 0024 { 0025 Q_OBJECT 0026 public: 0027 EditorModelStub() 0028 { 0029 setProperty("editingInProgress", false); 0030 setProperty("attachmentModel", QVariant::fromValue(&attachmentModel)); 0031 } 0032 0033 void setPropertyAndSignal(const QByteArray &name, const QVariant &value) 0034 { 0035 if (property(name) == value) 0036 return; 0037 if (property("editingInProgress").toBool()) 0038 return; 0039 0040 setProperty(name, value); 0041 if (name == "task") 0042 emit taskChanged(value.value<Domain::Task::Ptr>()); 0043 else if (name == "text") 0044 emit textChanged(value.toString()); 0045 else if (name == "title") 0046 emit titleChanged(value.toString()); 0047 else if (name == "done") 0048 emit doneChanged(value.toBool()); 0049 else if (name == "startDate") 0050 emit startDateChanged(value.toDate()); 0051 else if (name == "dueDate") 0052 emit dueDateChanged(value.toDate()); 0053 else if (name == "recurrence") 0054 emit recurrenceChanged(value.value<Domain::Task::Recurrence>()); 0055 else 0056 qFatal("Unsupported property %s", name.constData()); 0057 } 0058 0059 public slots: 0060 void setTask(const Domain::Task::Ptr &task) { setPropertyAndSignal("task", QVariant::fromValue(task)); } 0061 void setTitle(const QString &title) { setPropertyAndSignal("title", title); } 0062 void setText(const QString &text) { setPropertyAndSignal("text", text); } 0063 void setDone(bool done) { setPropertyAndSignal("done", done); } 0064 void setStartDate(const QDate &start) { setPropertyAndSignal("startDate", start); } 0065 void setDueDate(const QDate &due) { setPropertyAndSignal("dueDate", due); } 0066 void setRecurrence(Domain::Task::Recurrence recurrence) { setPropertyAndSignal("recurrence", QVariant::fromValue(recurrence)); } 0067 void makeTaskAvailable() { setTask(Domain::Task::Ptr(new Domain::Task)); } 0068 0069 void addAttachment(const QString &fileName) 0070 { 0071 auto item = new QStandardItem(fileName); 0072 attachmentModel.appendRow(QList<QStandardItem*>() << item); 0073 } 0074 0075 void removeAttachment(const QModelIndex &index) 0076 { 0077 if (index.isValid()) 0078 attachmentModel.removeRows(index.row(), 1, QModelIndex()); 0079 } 0080 0081 signals: 0082 void taskChanged(const Domain::Task::Ptr &task); 0083 void textChanged(const QString &text); 0084 void titleChanged(const QString &title); 0085 void doneChanged(bool done); 0086 void startDateChanged(const QDate &date); 0087 void dueDateChanged(const QDate &due); 0088 void recurrenceChanged(Domain::Task::Recurrence recurrence); 0089 0090 public: 0091 QStandardItemModel attachmentModel; 0092 }; 0093 0094 class EditorViewTest : public QObject 0095 { 0096 Q_OBJECT 0097 public: 0098 explicit EditorViewTest(QObject *parent = nullptr) 0099 : QObject(parent) 0100 { 0101 qputenv("ZANSHIN_UNIT_TEST_RUN", "1"); 0102 } 0103 0104 private slots: 0105 void shouldHaveDefaultState() 0106 { 0107 Widgets::EditorView editor; 0108 0109 QVERIFY(!editor.isEnabled()); 0110 0111 auto textEdit = editor.findChild<QPlainTextEdit*>(QStringLiteral("textEdit")); 0112 QVERIFY(textEdit); 0113 QVERIFY(textEdit->isVisibleTo(&editor)); 0114 0115 auto startDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("startDateEdit")); 0116 QVERIFY(startDateEdit); 0117 QVERIFY(startDateEdit->isVisibleTo(&editor)); 0118 0119 auto dueDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("dueDateEdit")); 0120 QVERIFY(dueDateEdit); 0121 QVERIFY(dueDateEdit->isVisibleTo(&editor)); 0122 0123 auto recurrenceCombo = editor.findChild<QComboBox*>(QStringLiteral("recurrenceCombo")); 0124 QVERIFY(recurrenceCombo); 0125 QVERIFY(recurrenceCombo->isVisibleTo(&editor)); 0126 0127 auto doneButton = editor.findChild<QAbstractButton*>(QStringLiteral("doneButton")); 0128 QVERIFY(doneButton); 0129 QVERIFY(doneButton->isVisibleTo(&editor)); 0130 0131 auto attachmentList = editor.findChild<QListView*>(QStringLiteral("attachmentList")); 0132 QVERIFY(attachmentList); 0133 QVERIFY(attachmentList->isVisibleTo(&editor)); 0134 0135 auto addAttachmentButton = editor.findChild<QToolButton*>(QStringLiteral("addAttachmentButton")); 0136 QVERIFY(addAttachmentButton); 0137 QVERIFY(addAttachmentButton->isVisibleTo(&editor)); 0138 0139 auto removeAttachmentButton = editor.findChild<QToolButton*>(QStringLiteral("removeAttachmentButton")); 0140 QVERIFY(removeAttachmentButton); 0141 QVERIFY(removeAttachmentButton->isVisibleTo(&editor)); 0142 } 0143 0144 void shouldNotCrashForNullModel() 0145 { 0146 // GIVEN 0147 Widgets::EditorView editor; 0148 EditorModelStub model; 0149 model.setTitle(QStringLiteral("Foo")); 0150 model.setText(QStringLiteral("Bar")); 0151 editor.setModel(&model); 0152 0153 auto textEdit = editor.findChild<QPlainTextEdit*>(QStringLiteral("textEdit")); 0154 QVERIFY(textEdit); 0155 0156 auto startDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("startDateEdit")); 0157 QVERIFY(startDateEdit); 0158 0159 auto dueDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("dueDateEdit")); 0160 QVERIFY(dueDateEdit); 0161 0162 auto recurrenceCombo = editor.findChild<QComboBox*>(QStringLiteral("recurrenceCombo")); 0163 QVERIFY(recurrenceCombo); 0164 0165 auto doneButton = editor.findChild<QAbstractButton*>(QStringLiteral("doneButton")); 0166 QVERIFY(doneButton); 0167 0168 auto attachmentList = editor.findChild<QListView*>(QStringLiteral("attachmentList")); 0169 QVERIFY(attachmentList); 0170 QCOMPARE(attachmentList->model(), &model.attachmentModel); 0171 0172 auto addAttachmentButton = editor.findChild<QToolButton*>(QStringLiteral("addAttachmentButton")); 0173 QVERIFY(addAttachmentButton); 0174 0175 auto removeAttachmentButton = editor.findChild<QToolButton*>(QStringLiteral("removeAttachmentButton")); 0176 QVERIFY(removeAttachmentButton); 0177 0178 // WHEN 0179 editor.setModel(nullptr); 0180 0181 // THEN 0182 QVERIFY(!editor.isEnabled()); 0183 QVERIFY(textEdit->toPlainText().isEmpty()); 0184 QVERIFY(!startDateEdit->isVisibleTo(&editor)); 0185 QVERIFY(!dueDateEdit->isVisibleTo(&editor)); 0186 QVERIFY(!recurrenceCombo->isVisibleTo(&editor)); 0187 QVERIFY(!doneButton->isVisibleTo(&editor)); 0188 QVERIFY(!attachmentList->isVisibleTo(&editor)); 0189 QVERIFY(attachmentList->model() == nullptr); 0190 QVERIFY(!addAttachmentButton->isVisibleTo(&editor)); 0191 QVERIFY(!removeAttachmentButton->isVisibleTo(&editor)); 0192 } 0193 0194 void shouldBeEnabledOnlyWhenAnTaskIsAvailable() 0195 { 0196 // GIVEN 0197 Widgets::EditorView editor; 0198 EditorModelStub model; 0199 0200 // WHEN 0201 editor.setModel(&model); 0202 0203 // THEN 0204 QVERIFY(!editor.isEnabled()); 0205 0206 // WHEN 0207 // like model.makeTaskAvailable() does: 0208 Domain::Task::Ptr task(new Domain::Task); 0209 model.setPropertyAndSignal("task", QVariant::fromValue(task)); 0210 0211 // THEN 0212 QVERIFY(editor.isEnabled()); 0213 0214 // WHEN 0215 model.setPropertyAndSignal("task", QVariant::fromValue(Domain::Task::Ptr())); 0216 0217 // THEN 0218 QVERIFY(!editor.isEnabled()); 0219 0220 0221 0222 // GIVEN 0223 EditorModelStub model2; 0224 model2.setPropertyAndSignal("task", QVariant::fromValue(task)); 0225 0226 // WHEN 0227 editor.setModel(&model2); 0228 0229 // THEN 0230 QVERIFY(editor.isEnabled()); 0231 } 0232 0233 void shouldDisplayModelProperties() 0234 { 0235 // GIVEN 0236 Widgets::EditorView editor; 0237 EditorModelStub model; 0238 model.makeTaskAvailable(); 0239 model.setProperty("title", "My title"); 0240 model.setProperty("text", "\nMy text"); 0241 model.setProperty("startDate", QDate::currentDate()); 0242 model.setProperty("dueDate", QDate::currentDate().addDays(2)); 0243 model.setProperty("recurrence", QVariant::fromValue(Domain::Task::RecursWeekly)); 0244 model.setProperty("done", true); 0245 0246 auto textEdit = editor.findChild<QPlainTextEdit*>(QStringLiteral("textEdit")); 0247 auto startDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("startDateEdit")); 0248 auto dueDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("dueDateEdit")); 0249 auto recurrenceCombo = editor.findChild<QComboBox*>(QStringLiteral("recurrenceCombo")); 0250 auto doneButton = editor.findChild<QAbstractButton*>(QStringLiteral("doneButton")); 0251 0252 // WHEN 0253 editor.setModel(&model); 0254 0255 // THEN 0256 QCOMPARE(textEdit->toPlainText(), QString(model.property("title").toString() 0257 + '\n' 0258 + model.property("text").toString())); 0259 QCOMPARE(startDateEdit->date(), model.property("startDate").toDate()); 0260 QCOMPARE(dueDateEdit->date(), model.property("dueDate").toDate()); 0261 QCOMPARE(recurrenceCombo->currentData().value<Domain::Task::Recurrence>(), model.property("recurrence").value<Domain::Task::Recurrence>()); 0262 QCOMPARE(doneButton->isChecked(), model.property("done").toBool()); 0263 } 0264 0265 void shouldNotReactToChangesWhileEditing() 0266 { 0267 // GIVEN 0268 Widgets::EditorView editor; 0269 EditorModelStub model; 0270 model.makeTaskAvailable(); 0271 model.setProperty("title", "My title"); 0272 model.setProperty("text", "\nMy text"); 0273 model.setProperty("startDate", QDate::currentDate()); 0274 model.setProperty("dueDate", QDate::currentDate().addDays(2)); 0275 model.setProperty("recurrence", QVariant::fromValue(Domain::Task::RecursWeekly)); 0276 model.setProperty("done", true); 0277 editor.setModel(&model); 0278 0279 auto textEdit = editor.findChild<QPlainTextEdit*>(QStringLiteral("textEdit")); 0280 auto startDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("startDateEdit")); 0281 auto dueDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("dueDateEdit")); 0282 auto recurrenceCombo = editor.findChild<QComboBox*>(QStringLiteral("recurrenceCombo")); 0283 auto doneButton = editor.findChild<QAbstractButton*>(QStringLiteral("doneButton")); 0284 editor.setModel(&model); 0285 0286 // WHEN 0287 editor.show(); 0288 QVERIFY(QTest::qWaitForWindowExposed(&editor)); 0289 editor.activateWindow(); 0290 textEdit->setFocus(); 0291 model.setTitle("New title"); 0292 model.setText("New text"); 0293 startDateEdit->setFocus(); 0294 model.setStartDate(QDate::currentDate().addDays(1)); 0295 dueDateEdit->setFocus(); 0296 model.setDueDate(QDate::currentDate().addDays(3)); 0297 recurrenceCombo->setFocus(); 0298 model.setRecurrence(Domain::Task::RecursDaily); 0299 doneButton->setFocus(); 0300 model.setDone(false); 0301 0302 // THEN (nothing changed) 0303 QCOMPARE(textEdit->toPlainText(), QStringLiteral("My title\n\nMy text")); 0304 QCOMPARE(startDateEdit->date(), QDate::currentDate()); 0305 QCOMPARE(dueDateEdit->date(), QDate::currentDate().addDays(2)); 0306 QCOMPARE(recurrenceCombo->currentData().value<Domain::Task::Recurrence>(), Domain::Task::RecursWeekly); 0307 QVERIFY(doneButton->isChecked()); 0308 } 0309 0310 void shouldReactToTitleChanges() 0311 { 0312 // GIVEN 0313 Widgets::EditorView editor; 0314 EditorModelStub model; 0315 model.makeTaskAvailable(); 0316 model.setProperty("title", "My title"); 0317 model.setProperty("text", "\nMy text"); 0318 model.setProperty("startDate", QDate::currentDate()); 0319 model.setProperty("dueDate", QDate::currentDate().addDays(2)); 0320 model.setProperty("done", true); 0321 editor.setModel(&model); 0322 0323 auto textEdit = editor.findChild<QPlainTextEdit*>(QStringLiteral("textEdit")); 0324 0325 // WHEN 0326 model.setPropertyAndSignal("title", "New title"); 0327 0328 // THEN 0329 QCOMPARE(textEdit->toPlainText(), QString(model.property("title").toString() 0330 + '\n' 0331 + model.property("text").toString())); 0332 } 0333 0334 void shouldReactToTextChanges() 0335 { 0336 // GIVEN 0337 Widgets::EditorView editor; 0338 EditorModelStub model; 0339 model.makeTaskAvailable(); 0340 model.setProperty("title", "My title"); 0341 model.setProperty("text", "\nMy text"); 0342 model.setProperty("startDate", QDate::currentDate()); 0343 model.setProperty("dueDate", QDate::currentDate().addDays(2)); 0344 model.setProperty("done", true); 0345 editor.setModel(&model); 0346 0347 auto textEdit = editor.findChild<QPlainTextEdit*>(QStringLiteral("textEdit")); 0348 0349 // WHEN 0350 model.setPropertyAndSignal("text", "\nNew text"); 0351 0352 // THEN 0353 QCOMPARE(textEdit->toPlainText(), QString(model.property("title").toString() 0354 + '\n' 0355 + model.property("text").toString())); 0356 } 0357 0358 void shouldApplyTextEditChanges_data() 0359 { 0360 QTest::addColumn<QString>("plainText"); 0361 QTest::addColumn<QString>("expectedTitle"); 0362 QTest::addColumn<QString>("expectedText"); 0363 0364 QTest::newRow("nominal case") << "Title\n\nText" << "Title" << "\nText"; 0365 QTest::newRow("single line") << "Title" << "Title" << ""; 0366 } 0367 0368 void shouldApplyTextEditChanges() 0369 { 0370 // GIVEN 0371 Widgets::EditorView editor; 0372 EditorModelStub model; 0373 model.makeTaskAvailable(); 0374 editor.setModel(&model); 0375 0376 auto textEdit = editor.findChild<QPlainTextEdit*>(QStringLiteral("textEdit")); 0377 0378 // WHEN 0379 QFETCH(QString, plainText); 0380 textEdit->setPlainText(plainText); 0381 0382 // THEN 0383 QFETCH(QString, expectedTitle); 0384 QCOMPARE(model.property("title").toString(), expectedTitle); 0385 QFETCH(QString, expectedText); 0386 QCOMPARE(model.property("text").toString(), expectedText); 0387 } 0388 0389 void shouldReactToDoneChanges() 0390 { 0391 // GIVEN 0392 Widgets::EditorView editor; 0393 EditorModelStub model; 0394 model.makeTaskAvailable(); 0395 model.setProperty("title", "My title"); 0396 model.setProperty("text", "\nMy text"); 0397 model.setProperty("startDate", QDate::currentDate()); 0398 model.setProperty("dueDate", QDate::currentDate().addDays(2)); 0399 model.setProperty("done", false); 0400 editor.setModel(&model); 0401 0402 auto doneButton = editor.findChild<QAbstractButton*>(QStringLiteral("doneButton")); 0403 QVERIFY(!doneButton->isChecked()); 0404 0405 // WHEN 0406 model.setPropertyAndSignal("done", true); 0407 0408 // THEN 0409 QVERIFY(doneButton->isChecked()); 0410 } 0411 0412 void shouldApplyDoneButtonChanges() 0413 { 0414 // GIVEN 0415 Widgets::EditorView editor; 0416 EditorModelStub model; 0417 model.makeTaskAvailable(); 0418 editor.setModel(&model); 0419 0420 auto doneButton = editor.findChild<QAbstractButton*>(QStringLiteral("doneButton")); 0421 0422 // WHEN 0423 doneButton->setChecked(true); 0424 0425 // THEN 0426 QCOMPARE(model.property("done").toBool(), true); 0427 } 0428 0429 void shouldReactToStartDateChanges() 0430 { 0431 // GIVEN 0432 Widgets::EditorView editor; 0433 EditorModelStub model; 0434 model.makeTaskAvailable(); 0435 model.setProperty("title", "My title"); 0436 model.setProperty("text", "\nMy text"); 0437 model.setProperty("startDate", QDate::currentDate()); 0438 model.setProperty("dueDate", QDate::currentDate().addDays(2)); 0439 model.setProperty("done", false); 0440 editor.setModel(&model); 0441 0442 auto startDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("startDateEdit")); 0443 0444 // WHEN 0445 model.setPropertyAndSignal("startDate", QDate::currentDate().addDays(-2)); 0446 0447 // THEN 0448 QCOMPARE(startDateEdit->date(), model.property("startDate").toDate()); 0449 } 0450 0451 void shouldApplyStartDateEditChanges() 0452 { 0453 // GIVEN 0454 Widgets::EditorView editor; 0455 EditorModelStub model; 0456 model.makeTaskAvailable(); 0457 editor.setModel(&model); 0458 0459 auto startDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("startDateEdit")); 0460 auto today = QDate::currentDate(); 0461 0462 // WHEN 0463 startDateEdit->setEditText(today.toString(QStringLiteral("M/d/yyyy"))); 0464 QTest::keyClick(startDateEdit, Qt::Key_Enter); 0465 0466 // THEN 0467 const QDate newStartDate = model.property("startDate").toDate(); 0468 QCOMPARE(newStartDate, today); 0469 } 0470 0471 void shouldReactToDueDateChanges() 0472 { 0473 // GIVEN 0474 Widgets::EditorView editor; 0475 EditorModelStub model; 0476 model.setProperty("title", "My title"); 0477 model.setProperty("text", "\nMy text"); 0478 model.setProperty("startDate", QDate::currentDate()); 0479 model.setProperty("dueDate", QDate::currentDate().addDays(2)); 0480 model.setProperty("done", false); 0481 editor.setModel(&model); 0482 0483 auto dueDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("dueDateEdit")); 0484 0485 // WHEN 0486 model.setPropertyAndSignal("dueDate", QDate::currentDate().addDays(-2)); 0487 0488 // THEN 0489 QCOMPARE(dueDateEdit->date(), model.property("dueDate").toDate()); 0490 } 0491 0492 void shouldApplyDueDateEditChanges() 0493 { 0494 // GIVEN 0495 Widgets::EditorView editor; 0496 EditorModelStub model; 0497 model.makeTaskAvailable(); 0498 editor.setModel(&model); 0499 0500 auto dueDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("dueDateEdit")); 0501 auto today = QDate::currentDate(); 0502 0503 // WHEN 0504 QVERIFY(dueDateEdit->isEnabled()); 0505 dueDateEdit->setEditText(today.toString(QStringLiteral("M/d/yyyy"))); 0506 QTest::keyClick(dueDateEdit, Qt::Key_Enter); 0507 0508 // THEN 0509 QCOMPARE(model.property("dueDate").toDate(), today); 0510 } 0511 0512 void shouldApplyStartTodayChanges() 0513 { 0514 // GIVEN 0515 Widgets::EditorView editor; 0516 EditorModelStub model; 0517 model.makeTaskAvailable(); 0518 editor.setModel(&model); 0519 0520 QAbstractButton *startTodayButton = editor.findChild<QAbstractButton *>(QStringLiteral("startTodayButton")); 0521 QVERIFY(startTodayButton); 0522 auto startDateEdit = editor.findChild<KDateComboBox*>(QStringLiteral("startDateEdit")); 0523 auto today = QDate::currentDate(); 0524 0525 // WHEN 0526 QVERIFY(startTodayButton->isEnabled()); 0527 startTodayButton->click(); 0528 0529 // THEN 0530 QCOMPARE(startDateEdit->currentText(), today.toString(QStringLiteral("M/d/yyyy"))); 0531 QCOMPARE(model.property("startDate").toDate(), today); 0532 } 0533 0534 void shouldReactToRecurrenceChanges() 0535 { 0536 // GIVEN 0537 Widgets::EditorView editor; 0538 EditorModelStub model; 0539 model.makeTaskAvailable(); 0540 model.setProperty("title", "My title"); 0541 model.setProperty("text", "\nMy text"); 0542 model.setProperty("startDate", QDate::currentDate()); 0543 model.setProperty("dueDate", QDate::currentDate().addDays(2)); 0544 model.setProperty("recurrence", QVariant::fromValue(Domain::Task::RecursWeekly)); 0545 model.setProperty("done", false); 0546 editor.setModel(&model); 0547 0548 auto recurrenceCombo = editor.findChild<QComboBox*>(QStringLiteral("recurrenceCombo")); 0549 0550 // WHEN 0551 model.setPropertyAndSignal("recurrence", Domain::Task::RecursMonthly); 0552 0553 // THEN 0554 QCOMPARE(recurrenceCombo->currentData().value<Domain::Task::Recurrence>(), model.property("recurrence").value<Domain::Task::Recurrence>()); 0555 } 0556 0557 void shouldApplyRecurrenceComboChanges() 0558 { 0559 // GIVEN 0560 Widgets::EditorView editor; 0561 EditorModelStub model; 0562 model.makeTaskAvailable(); 0563 editor.setModel(&model); 0564 0565 auto recurrenceCombo = editor.findChild<QComboBox*>(QStringLiteral("recurrenceCombo")); 0566 0567 // WHEN 0568 recurrenceCombo->setCurrentIndex(2); // Weekly 0569 0570 // THEN 0571 QCOMPARE(model.property("recurrence").value<Domain::Task::Recurrence>(), Domain::Task::RecursWeekly); 0572 } 0573 0574 void shouldAddAttachments() 0575 { 0576 // GIVEN 0577 Widgets::EditorView editor; 0578 editor.setRequestFileNameFunction([](QWidget*) { return "/tmp/foobar"; }); 0579 EditorModelStub model; 0580 model.makeTaskAvailable(); 0581 editor.setModel(&model); 0582 0583 auto addAttachmentButton = editor.findChild<QToolButton*>(QStringLiteral("addAttachmentButton")); 0584 0585 // WHEN 0586 addAttachmentButton->click(); 0587 0588 // THEN 0589 QCOMPARE(model.attachmentModel.rowCount(), 1); 0590 QCOMPARE(model.attachmentModel.data(model.attachmentModel.index(0, 0)).toString(), 0591 QStringLiteral("/tmp/foobar")); 0592 } 0593 0594 void shouldRemoveAttachments() 0595 { 0596 // GIVEN 0597 Widgets::EditorView editor; 0598 EditorModelStub model; 0599 model.makeTaskAvailable(); 0600 model.addAttachment("/tmp/foo"); 0601 model.addAttachment("/tmp/bar"); 0602 editor.setModel(&model); 0603 0604 auto attachmentList = editor.findChild<QListView*>(QStringLiteral("attachmentList")); 0605 auto removeAttachmentButton = editor.findChild<QToolButton*>(QStringLiteral("removeAttachmentButton")); 0606 0607 // THEN 0608 QVERIFY(!removeAttachmentButton->isEnabled()); 0609 0610 // WHEN 0611 attachmentList->selectionModel()->select(model.attachmentModel.index(0, 0), QItemSelectionModel::ClearAndSelect); 0612 0613 // THEN 0614 QVERIFY(removeAttachmentButton->isEnabled()); 0615 0616 // WHEN 0617 removeAttachmentButton->click(); 0618 0619 // THEN 0620 QCOMPARE(model.attachmentModel.rowCount(), 1); 0621 QCOMPARE(model.attachmentModel.data(model.attachmentModel.index(0, 0)).toString(), 0622 QStringLiteral("/tmp/bar")); 0623 } 0624 }; 0625 0626 ZANSHIN_TEST_MAIN(EditorViewTest) 0627 0628 #include "editorviewtest.moc"