From 397d804cddf4a4a0b2eb267b81fccfb384273533 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Mon, 19 Feb 2018 18:22:49 -0500 Subject: [PATCH] Add tests & minor edits --- src/gui/entry/EditEntryWidget.cpp | 4 ++-- src/gui/entry/EditEntryWidget.h | 2 +- tests/gui/TestGui.cpp | 27 +++++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index e54ceb625..4cb5e21e2 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -1137,7 +1137,7 @@ QMenu* EditEntryWidget::createPresetsMenu() return expirePresetsMenu; } -void EditEntryWidget::setupColorButton(bool foreground, QColor color) +void EditEntryWidget::setupColorButton(bool foreground, const QColor& color) { QWidget* button = m_advancedUi->fgColorButton; QCheckBox* checkBox = m_advancedUi->fgColorCheckBox; @@ -1165,7 +1165,7 @@ void EditEntryWidget::pickColor() oldColor = QColor(m_advancedUi->bgColorButton->property("color").toString()); } - QColorDialog colorDialog; + QColorDialog colorDialog(this); QColor newColor = colorDialog.getColor(oldColor); if (newColor.isValid()) { setupColorButton(isForeground, newColor); diff --git a/src/gui/entry/EditEntryWidget.h b/src/gui/entry/EditEntryWidget.h index 19c2ebe15..63b77323d 100644 --- a/src/gui/entry/EditEntryWidget.h +++ b/src/gui/entry/EditEntryWidget.h @@ -121,7 +121,7 @@ private: #endif void setupProperties(); void setupHistory(); - void setupColorButton(bool foreground, QColor color); + void setupColorButton(bool foreground, const QColor& color); bool passwordsEqual(); void setForms(const Entry* entry, bool restore = false); diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index b56589315..2e11fcf59 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -279,6 +280,7 @@ void TestGui::testTabs() void TestGui::testEditEntry() { QToolBar* toolBar = m_mainWindow->findChild("toolBar"); + int editCount = 0; // Select the first entry in the database EntryView* entryView = m_dbWidget->findChild("entryView"); @@ -305,7 +307,24 @@ void TestGui::testEditEntry() QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Apply), Qt::LeftButton); QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode); QCOMPARE(entry->title(), QString("Sample Entry_test")); - QCOMPARE(entry->historyItems().size(), 1); + QCOMPARE(entry->historyItems().size(), ++editCount); + + // Test entry colors (simulate choosing a color) + editEntryWidget->setCurrentPage(1); + auto fgColor = QColor(Qt::red); + auto bgColor = QColor(Qt::blue); + // Set foreground color + auto colorButton = editEntryWidget->findChild("fgColorButton"); + auto colorCheckBox = editEntryWidget->findChild("fgColorCheckBox"); + colorButton->setProperty("color", fgColor); + colorCheckBox->setChecked(true); + // Set background color + colorButton = editEntryWidget->findChild("bgColorButton"); + colorCheckBox = editEntryWidget->findChild("bgColorCheckBox"); + colorButton->setProperty("color", bgColor); + colorCheckBox->setChecked(true); + QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Apply), Qt::LeftButton); + QCOMPARE(entry->historyItems().size(), ++editCount); // Test protected attributes editEntryWidget->setCurrentPage(1); @@ -337,7 +356,11 @@ void TestGui::testEditEntry() // Confirm edit was made QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode); QCOMPARE(entry->title(), QString("Sample Entry_test")); - QCOMPARE(entry->historyItems().size(), 2); + QCOMPARE(entry->foregroundColor(), fgColor); + QCOMPARE(entryItem.data(Qt::ForegroundRole), QVariant(fgColor)); + QCOMPARE(entry->backgroundColor(), bgColor); + QCOMPARE(entryItem.data(Qt::BackgroundRole), QVariant(bgColor)); + QCOMPARE(entry->historyItems().size(), ++editCount); // Confirm modified indicator is showing QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("%1*").arg(m_dbFileName));