mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-11 23:39:50 -05:00
Correct testing status bar text
This commit is contained in:
parent
0a2e716525
commit
8dec687798
@ -91,6 +91,7 @@ void TestGui::initTestCase()
|
||||
|
||||
m_mainWindow.reset(new MainWindow());
|
||||
m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
|
||||
m_statusBarLabel = m_mainWindow->findChild<QLabel*>("statusBarLabel");
|
||||
m_mainWindow->show();
|
||||
m_mainWindow->resize(1024, 768);
|
||||
}
|
||||
@ -288,7 +289,7 @@ void TestGui::testCreateDatabase()
|
||||
|
||||
QCOMPARE(m_tabWidget->count(), 2);
|
||||
|
||||
statusBarLabelShouldBe("0 Entry(s)");
|
||||
checkStatusBarText("0 Ent");
|
||||
|
||||
// there is a new empty db
|
||||
m_db = m_tabWidget->currentDatabaseWidget()->database();
|
||||
@ -310,14 +311,14 @@ void TestGui::testCreateDatabase()
|
||||
compositeKey->addKey(fileKey);
|
||||
QCOMPARE(m_db->key()->rawKey(), compositeKey->rawKey());
|
||||
|
||||
statusBarLabelShouldBe("0 Entry(s)");
|
||||
checkStatusBarText("0 Ent");
|
||||
|
||||
// Test the switching to other DB tab
|
||||
m_tabWidget->setCurrentIndex(0);
|
||||
statusBarLabelShouldBe("1 Entry(s)");
|
||||
checkStatusBarText("1 Ent");
|
||||
|
||||
m_tabWidget->setCurrentIndex(1);
|
||||
statusBarLabelShouldBe("0 Entry(s)");
|
||||
checkStatusBarText("0 Ent");
|
||||
|
||||
// close the new database
|
||||
MessageBox::setNextAnswer(MessageBox::No);
|
||||
@ -606,7 +607,7 @@ void TestGui::testAddEntry()
|
||||
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
||||
|
||||
// Given the status bar label with initial number of entries.
|
||||
statusBarLabelShouldBe("1 Entry(s)");
|
||||
checkStatusBarText("1 Ent");
|
||||
|
||||
// Find the new entry action
|
||||
auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
||||
@ -643,7 +644,7 @@ void TestGui::testAddEntry()
|
||||
m_db->updateCommonUsernames();
|
||||
|
||||
// Then the status bar label should be updated with incremented number of entries.
|
||||
statusBarLabelShouldBe("2 Entry(s)");
|
||||
checkStatusBarText("2 Ent");
|
||||
|
||||
// Add entry "something 2"
|
||||
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
||||
@ -664,9 +665,6 @@ void TestGui::testAddEntry()
|
||||
QCOMPARE(entry->username(), QString("AutocompletionUsername"));
|
||||
QCOMPARE(entry->historyItems().size(), 0);
|
||||
|
||||
// Then the status bar label should be updated with incremented number of entries.
|
||||
statusBarLabelShouldBe("3 Entry(s)");
|
||||
|
||||
// Add entry "something 5" but click cancel button (does NOT add entry)
|
||||
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
||||
QTest::keyClicks(titleEdit, "something 5");
|
||||
@ -677,7 +675,6 @@ void TestGui::testAddEntry()
|
||||
|
||||
// Confirm no changed entry count
|
||||
QTRY_COMPARE(entryView->model()->rowCount(), 3);
|
||||
statusBarLabelShouldBe("3 Entry(s)");
|
||||
}
|
||||
|
||||
void TestGui::testPasswordEntryEntropy_data()
|
||||
@ -1110,7 +1107,7 @@ void TestGui::testDeleteEntry()
|
||||
{
|
||||
// Add canned entries for consistent testing
|
||||
addCannedEntries();
|
||||
statusBarLabelShouldBe("4 Entry(s)");
|
||||
checkStatusBarText("4 Ent");
|
||||
|
||||
auto* groupView = m_dbWidget->findChild<GroupView*>("groupView");
|
||||
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
||||
@ -1140,7 +1137,7 @@ void TestGui::testDeleteEntry()
|
||||
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1);
|
||||
}
|
||||
|
||||
statusBarLabelShouldBe("3 Entry(s)");
|
||||
checkStatusBarText("3 Ent");
|
||||
|
||||
// Select multiple entries and move them to the recycling bin
|
||||
clickIndex(entryView->model()->index(1, 1), entryView, Qt::LeftButton);
|
||||
@ -1162,7 +1159,6 @@ void TestGui::testDeleteEntry()
|
||||
QCOMPARE(entryView->model()->rowCount(), 1);
|
||||
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);
|
||||
}
|
||||
statusBarLabelShouldBe("1 Entry(s)");
|
||||
|
||||
// Go to the recycling bin
|
||||
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
|
||||
@ -1171,7 +1167,6 @@ void TestGui::testDeleteEntry()
|
||||
groupView,
|
||||
Qt::LeftButton);
|
||||
QCOMPARE(groupView->currentGroup()->name(), m_db->metadata()->recycleBin()->name());
|
||||
statusBarLabelShouldBe("3 Entry(s)");
|
||||
|
||||
// Delete one entry from the bin
|
||||
clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton);
|
||||
@ -1179,7 +1174,6 @@ void TestGui::testDeleteEntry()
|
||||
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
||||
QCOMPARE(entryView->model()->rowCount(), 3);
|
||||
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);
|
||||
statusBarLabelShouldBe("3 Entry(s)");
|
||||
|
||||
MessageBox::setNextAnswer(MessageBox::Delete);
|
||||
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
||||
@ -1193,7 +1187,6 @@ void TestGui::testDeleteEntry()
|
||||
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
|
||||
QCOMPARE(entryView->model()->rowCount(), 0);
|
||||
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 0);
|
||||
statusBarLabelShouldBe("0 Entry(s)");
|
||||
|
||||
// Ensure the entry preview widget shows the recycling group since all entries are deleted
|
||||
auto* previewWidget = m_dbWidget->findChild<EntryPreviewWidget*>("previewWidget");
|
||||
@ -1914,14 +1907,12 @@ void TestGui::checkSaveDatabase()
|
||||
QFAIL("Could not save database.");
|
||||
}
|
||||
|
||||
void TestGui::statusBarLabelShouldBe(const char* expectedText)
|
||||
void TestGui::checkStatusBarText(const QString& textFragment)
|
||||
{
|
||||
// Wait a little to have updated status bar text.
|
||||
// It fails with 150ms on i7 2.5Ghz, let's have double more time: 300ms.
|
||||
Tools::wait(300);
|
||||
auto* statusBarLabel = m_mainWindow->findChild<QLabel*>("statusBarLabel");
|
||||
QVERIFY2(statusBarLabel->isVisible(), "StatusBarLabel is to be visible");
|
||||
QCOMPARE(statusBarLabel->text(), QString(expectedText));
|
||||
QApplication::processEvents();
|
||||
QVERIFY(m_statusBarLabel->isVisible());
|
||||
QTRY_VERIFY2(m_statusBarLabel->text().startsWith(textFragment),
|
||||
qPrintable(QString("'%1' doesn't start with '%2'").arg(m_statusBarLabel->text(), textFragment)));
|
||||
}
|
||||
|
||||
void TestGui::triggerAction(const QString& name)
|
||||
|
@ -84,9 +84,10 @@ private:
|
||||
Qt::MouseButton button,
|
||||
Qt::KeyboardModifiers stateKey = 0);
|
||||
void checkSaveDatabase();
|
||||
void statusBarLabelShouldBe(const char* expectedText);
|
||||
void checkStatusBarText(const QString& textFragment);
|
||||
|
||||
QScopedPointer<MainWindow> m_mainWindow;
|
||||
QPointer<QLabel> m_statusBarLabel;
|
||||
QPointer<DatabaseTabWidget> m_tabWidget;
|
||||
QPointer<DatabaseWidget> m_dbWidget;
|
||||
QSharedPointer<Database> m_db;
|
||||
|
Loading…
Reference in New Issue
Block a user