Skip to content

Commit fc876fe

Browse files
committedOct 10, 2017
Add some tests
1 parent f18293f commit fc876fe

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
 

‎tests/src/gui/testqgsrelationreferencewidget.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class TestQgsRelationReferenceWidget : public QObject
4040

4141
void testChainFilter();
4242
void testChainFilterRefreshed();
43+
void testChainFilterDeleteForeignKey();
4344

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

226+
void TestQgsRelationReferenceWidget::testChainFilterDeleteForeignKey()
227+
{
228+
// init a relation reference widget
229+
QStringList filterFields = { "material", "diameter", "raccord" };
230+
231+
QgsRelationReferenceWidget w( new QWidget() );
232+
w.setChainFilters( true );
233+
w.setFilterFields( filterFields );
234+
w.setRelation( *mRelation, true );
235+
w.init();
236+
237+
// check the default status of filter comboboxes
238+
QList<QComboBox *> cbs = w.mFilterComboBoxes;
239+
240+
QCOMPARE( cbs[0]->currentText(), QString( "material" ) );
241+
QCOMPARE( cbs[0]->isEnabled(), true );
242+
243+
QCOMPARE( cbs[1]->currentText(), QString( "diameter" ) );
244+
QCOMPARE( cbs[1]->isEnabled(), false );
245+
246+
QCOMPARE( cbs[2]->currentText(), QString( "raccord" ) );
247+
QCOMPARE( cbs[2]->isEnabled(), false );
248+
249+
// set a foreign key
250+
w.setForeignKey( QVariant( 11 ) );
251+
252+
QCOMPARE( cbs[0]->currentText(), QString( "iron" ) );
253+
QCOMPARE( cbs[1]->currentText(), QString( "120" ) );
254+
QCOMPARE( cbs[2]->currentText(), QString( "sleeve" ) );
255+
256+
// delete the foreign key
257+
w.deleteForeignKey();
258+
259+
QCOMPARE( cbs[0]->currentText(), QString( "material" ) );
260+
QCOMPARE( cbs[0]->isEnabled(), true );
261+
262+
QCOMPARE( cbs[1]->currentText(), QString( "diameter" ) );
263+
QCOMPARE( cbs[1]->isEnabled(), false );
264+
265+
QCOMPARE( cbs[2]->currentText(), QString( "raccord" ) );
266+
QCOMPARE( cbs[2]->isEnabled(), false );
267+
}
268+
225269
QGSTEST_MAIN( TestQgsRelationReferenceWidget )
226270
#include "testqgsrelationreferencewidget.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.