Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 30, 2018
1 parent caa6340 commit cb1172b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/gui/qgsfeaturelistcombobox.h
Expand Up @@ -221,6 +221,8 @@ class GUI_EXPORT QgsFeatureListComboBox : public QComboBox
bool mIsCurrentlyEdited = false;
bool mHasStoredEditState = false;
LineEditState mLineEditState;

friend class TestQgsFeatureListComboBox;
};

#endif // QGSFIELDLISTCOMBOBOX_H
2 changes: 2 additions & 0 deletions src/gui/qgsfilterlineedit.h
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions tests/src/gui/testqgsfeaturelistcombobox.cpp
Expand Up @@ -18,6 +18,7 @@

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

#include <QLineEdit>

class QgsFilterLineEdit;

class TestQgsFeatureListComboBox : public QObject
{
Q_OBJECT
Expand All @@ -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()
Expand Down Expand Up @@ -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()
{

Expand Down

0 comments on commit cb1172b

Please sign in to comment.