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 19, 2017
1 parent f7687e2 commit b70d9b5
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 @@ -38,6 +38,7 @@ class TestQgsRelationReferenceWidget : public QObject

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

private:
QgsVectorLayer* mLayer1;
Expand Down Expand Up @@ -220,5 +221,48 @@ void TestQgsRelationReferenceWidget::testChainFilterRefreshed()
QCOMPARE( cbs[2]->currentText(), QString( "sleeve" ) );
}

void TestQgsRelationReferenceWidget::testChainFilterDeleteForeignKey()
{
// init a relation reference widget
QStringList filterFields = QStringList() << "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 );
}

QTEST_MAIN( TestQgsRelationReferenceWidget )
#include "testqgsrelationreferencewidget.moc"

0 comments on commit b70d9b5

Please sign in to comment.