|
| 1 | + |
1 | 2 | from qgis.PyQt.QtWidgets import QLineEdit
|
2 |
| -from qgis._core import QgsSettings |
| 3 | +from qgis._core import ( |
| 4 | + QgsSettings, |
| 5 | + QgsVectorLayer, |
| 6 | + QgsFeature, |
| 7 | + QgsGeometry, |
| 8 | + QgsProject, |
| 9 | + QgsPointXY, |
| 10 | +) |
3 | 11 | from qgis.gui import QgsCollapsibleGroupBox
|
4 | 12 | from qgis.testing import unittest
|
5 | 13 |
|
@@ -358,3 +366,42 @@ def test_ORStoolsDialogConfig_url(self):
|
358 | 366 | "POINT(8.67251100000000008 49.39887900000000087)",
|
359 | 367 | next(layer.getFeatures()).geometry().asPolyline()[0].asWkt(),
|
360 | 368 | )
|
| 369 | + |
| 370 | + def test_load_valid_point_layer(self): |
| 371 | + """Test loading vertices from valid point layer.""" |
| 372 | + from ORStools.gui.ORStoolsDialog import ORStoolsDialogMain |
| 373 | + |
| 374 | + dialog_main = ORStoolsDialogMain(IFACE) |
| 375 | + dialog_main._init_gui_control() |
| 376 | + |
| 377 | + # Create test layers |
| 378 | + self.point_layer = QgsVectorLayer("Point?crs=EPSG:4326", "test_points", "memory") |
| 379 | + self.line_layer = QgsVectorLayer("LineString?crs=EPSG:4326", "test_lines", "memory") |
| 380 | + |
| 381 | + # Add 3 features to point layer |
| 382 | + for coords in [(1, 2), (3, 4), (5, 6)]: |
| 383 | + feat = QgsFeature() |
| 384 | + feat.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(*coords))) |
| 385 | + self.point_layer.dataProvider().addFeature(feat) |
| 386 | + |
| 387 | + QgsProject.instance().addMapLayers([self.point_layer, self.line_layer]) |
| 388 | + |
| 389 | + # Run test |
| 390 | + dialog_main.dlg.load_vertices_from_layer("ok") |
| 391 | + |
| 392 | + # Verify |
| 393 | + self.assertTrue(dialog_main.dlg.line_tool is not None) |
| 394 | + self.assertEqual(dialog_main.dlg.routing_fromline_list.count(), 3) |
| 395 | + self.assertIsInstance(dialog_main.dlg.rubber_band, QgsRubberBand) |
| 396 | + |
| 397 | + def test_user_cancels_operation(self): |
| 398 | + """Test when user cancels the dialog.""" |
| 399 | + from ORStools.gui.ORStoolsDialog import ORStoolsDialogMain |
| 400 | + |
| 401 | + dialog_main = ORStoolsDialogMain(IFACE) |
| 402 | + dialog_main._init_gui_control() |
| 403 | + dialog_main.dlg.load_vertices_from_layer("not_ok") |
| 404 | + |
| 405 | + self.assertTrue(dialog_main.dlg.line_tool is not None) |
| 406 | + self.assertEqual(dialog_main.dlg.routing_fromline_list.count(), 0) |
| 407 | + self.assertNotIsInstance(dialog_main.dlg.rubber_band, QgsRubberBand) |
0 commit comments