Skip to content
Permalink
Browse files

tests for switching between values

especially setting the NULL value and checking if it's selected
checking if the clear button is activ when it should and inactive when it should

git cherry-pick 2e01811
  • Loading branch information
signedav committed Oct 25, 2018
1 parent caa6340 commit cb1172bd44652b3ba242e3001dcc137ce7b78eb8
Showing with 50 additions and 0 deletions.
  1. +2 −0 src/gui/qgsfeaturelistcombobox.h
  2. +2 −0 src/gui/qgsfilterlineedit.h
  3. +46 −0 tests/src/gui/testqgsfeaturelistcombobox.cpp
@@ -221,6 +221,8 @@ class GUI_EXPORT QgsFeatureListComboBox : public QComboBox
bool mIsCurrentlyEdited = false;
bool mHasStoredEditState = false;
LineEditState mLineEditState;

friend class TestQgsFeatureListComboBox;
};

#endif // QGSFIELDLISTCOMBOBOX_H
@@ -294,6 +294,8 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit

//! Returns true if clear button should be shown
bool shouldShowClear() const;

friend class TestQgsFeatureListComboBox;
};

/// @cond PRIVATE
@@ -18,6 +18,7 @@

#include "qgsapplication.h"
#include "qgsfeaturelistcombobox.h"
#include "qgsfilterlineedit.h"
#include "qgsvectorlayer.h"
#include "qgsfeaturefiltermodel.h"
#include "qgsgui.h"
@@ -26,6 +27,8 @@

#include <QLineEdit>

class QgsFilterLineEdit;

class TestQgsFeatureListComboBox : public QObject
{
Q_OBJECT
@@ -41,12 +44,15 @@ class TestQgsFeatureListComboBox : public QObject
void testSetGetLayer();
void testSetGetForeignKey();
void testAllowNull();
void testValuesAndSelection();
void nullRepresentation();

private:
void waitForLoaded( QgsFeatureListComboBox *cb );

std::unique_ptr<QgsVectorLayer> mLayer;

friend class QgsFeatureListComboBox;
};

void TestQgsFeatureListComboBox::initTestCase()
@@ -137,6 +143,46 @@ void TestQgsFeatureListComboBox::testAllowNull()
// Note to self: implement this!
}

void TestQgsFeatureListComboBox::testValuesAndSelection()
{
QgsApplication::setNullRepresentation( QStringLiteral( "nope" ) );
std::unique_ptr<QgsFeatureListComboBox> cb( new QgsFeatureListComboBox() );

cb->setSourceLayer( mLayer.get() );
cb->setDisplayExpression( QStringLiteral( "\"raccord\"" ) );
cb->setAllowNull( true );

//check if everything is fine:
waitForLoaded( cb.get() );
QCOMPARE( cb->currentIndex(), cb->nullIndex() );
QCOMPARE( cb->currentText(), QStringLiteral( "nope" ) );

//check if text correct, selected and if the clear button disappeared:
cb->mLineEdit->clearValue();
waitForLoaded( cb.get() );
QCOMPARE( cb->currentIndex(), cb->nullIndex() );
QCOMPARE( cb->currentText(), QStringLiteral( "nope" ) );
QCOMPARE( cb->lineEdit()->selectedText(), QStringLiteral( "nope" ) );
QVERIFY( ! cb->mLineEdit->mClearAction );

//check if text is selected after receiving focus
cb->setFocus();
waitForLoaded( cb.get() );
QCOMPARE( cb->currentIndex(), cb->nullIndex() );
QCOMPARE( cb->currentText(), QStringLiteral( "nope" ) );
QCOMPARE( cb->lineEdit()->selectedText(), QStringLiteral( "nope" ) );
QVERIFY( ! cb->mLineEdit->mClearAction );

//check with another entry, clear button needs to be there then:
QTest::keyClicks( cb.get(), QStringLiteral( "sleeve" ) );
//QTest::keyClick(cb.get(), Qt::Key_Enter );
waitForLoaded( cb.get() );
QCOMPARE( cb->currentText(), QStringLiteral( "sleeve" ) );
QVERIFY( cb->mLineEdit->mClearAction );
//QVERIFY( cb->currentIndex() != cb->nullIndex());
//QCOMPARE( cb->model()->data( cb->currentModelIndex() ).toString(), QStringLiteral( "sleeve" ) );
}

void TestQgsFeatureListComboBox::nullRepresentation()
{

0 comments on commit cb1172b

Please sign in to comment.
You can’t perform that action at this time.