Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Oct 10, 2017
1 parent f18293f commit fc876fe
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/src/gui/testqgsrelationreferencewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class TestQgsRelationReferenceWidget : public QObject

void testChainFilter();
void testChainFilterRefreshed();
void testChainFilterDeleteForeignKey();

private:
std::unique_ptr<QgsVectorLayer> mLayer1;
Expand Down Expand Up @@ -222,5 +223,48 @@ void TestQgsRelationReferenceWidget::testChainFilterRefreshed()
QCOMPARE( cbs[2]->currentText(), QString( "sleeve" ) );
}

void TestQgsRelationReferenceWidget::testChainFilterDeleteForeignKey()
{
// init a relation reference widget
QStringList filterFields = { "material", "diameter", "raccord" };

QgsRelationReferenceWidget w( new QWidget() );
w.setChainFilters( true );
w.setFilterFields( filterFields );
w.setRelation( *mRelation, true );
w.init();

// check the default status of filter comboboxes
QList<QComboBox *> cbs = w.mFilterComboBoxes;

QCOMPARE( cbs[0]->currentText(), QString( "material" ) );
QCOMPARE( cbs[0]->isEnabled(), true );

QCOMPARE( cbs[1]->currentText(), QString( "diameter" ) );
QCOMPARE( cbs[1]->isEnabled(), false );

QCOMPARE( cbs[2]->currentText(), QString( "raccord" ) );
QCOMPARE( cbs[2]->isEnabled(), false );

// set a foreign key
w.setForeignKey( QVariant( 11 ) );

QCOMPARE( cbs[0]->currentText(), QString( "iron" ) );
QCOMPARE( cbs[1]->currentText(), QString( "120" ) );
QCOMPARE( cbs[2]->currentText(), QString( "sleeve" ) );

// delete the foreign key
w.deleteForeignKey();

QCOMPARE( cbs[0]->currentText(), QString( "material" ) );
QCOMPARE( cbs[0]->isEnabled(), true );

QCOMPARE( cbs[1]->currentText(), QString( "diameter" ) );
QCOMPARE( cbs[1]->isEnabled(), false );

QCOMPARE( cbs[2]->currentText(), QString( "raccord" ) );
QCOMPARE( cbs[2]->isEnabled(), false );
}

QGSTEST_MAIN( TestQgsRelationReferenceWidget )
#include "testqgsrelationreferencewidget.moc"

0 comments on commit fc876fe

Please sign in to comment.