|
1 | 1 | from time import sleep |
2 | 2 | from unittest.mock import patch |
| 3 | +from urllib.parse import quote_plus |
3 | 4 |
|
4 | 5 | from django.contrib.auth.models import Permission |
5 | 6 | from django.contrib.staticfiles.testing import StaticLiveServerTestCase |
@@ -457,6 +458,50 @@ def test_infinite_scroll_on_popup(self): |
457 | 458 | table_entries = self.find_elements(By.CSS_SELECTOR, ".map-detail tbody tr") |
458 | 459 | self.assertEqual(len(table_entries), 20) |
459 | 460 |
|
| 461 | + def test_url_fragment_actions_on_geo_map(self): |
| 462 | + device_location = self._create_object_location() |
| 463 | + device = device_location.device |
| 464 | + location = device_location.location |
| 465 | + self.login() |
| 466 | + mapId = "dashboard-geo-map" |
| 467 | + |
| 468 | + with self.subTest("Test setting url fragments on click event of node"): |
| 469 | + self.open_popup("_owGeoMap", location.id) |
| 470 | + current_hash = self.web_driver.execute_script( |
| 471 | + "return window.location.hash;" |
| 472 | + ) |
| 473 | + expected_hash = f"id={mapId}&nodeId={location.id}" |
| 474 | + self.assertIn(expected_hash, current_hash) |
| 475 | + |
| 476 | + with self.subTest("Test applying url fragment state on map"): |
| 477 | + current_url = self.web_driver.current_url |
| 478 | + self.web_driver.switch_to.new_window("tab") |
| 479 | + tabs = self.web_driver.window_handles |
| 480 | + self.web_driver.switch_to.window(tabs[1]) |
| 481 | + self.web_driver.get(current_url) |
| 482 | + sleep(0.5) |
| 483 | + popup = self.find_element(By.CSS_SELECTOR, ".map-detail") |
| 484 | + device_link = self.find_element( |
| 485 | + By.XPATH, f".//td[@class='col-name']/a[text()='{device.name}']" |
| 486 | + ) |
| 487 | + self.assertTrue(popup.is_displayed()) |
| 488 | + self.assertTrue(device_link.is_displayed()) |
| 489 | + self.web_driver.close() |
| 490 | + self.web_driver.switch_to.window(tabs[0]) |
| 491 | + |
| 492 | + with self.subTest("Test with incorrect node Id"): |
| 493 | + incorrect_url = ( |
| 494 | + f"{self.live_server_url}/admin/#id={mapId}&nodeId=incorrectId" |
| 495 | + ) |
| 496 | + self.web_driver.switch_to.new_window("tab") |
| 497 | + tabs = self.web_driver.window_handles |
| 498 | + self.web_driver.switch_to.window(tabs[1]) |
| 499 | + self.web_driver.get(incorrect_url) |
| 500 | + sleep(0.5) |
| 501 | + self.wait_for_invisibility(By.CSS_SELECTOR, ".map-detail") |
| 502 | + self.web_driver.close() |
| 503 | + self.web_driver.switch_to.window(tabs[0]) |
| 504 | + |
460 | 505 | def test_floorplan_overlay(self): |
461 | 506 | org = self._get_org() |
462 | 507 | location = self._create_location(type="indoor", organization=org) |
@@ -612,6 +657,67 @@ def test_switching_floorplan_in_fullscreen_mode(self): |
612 | 657 | ) |
613 | 658 | self.assertIsNotNone(canvases) |
614 | 659 |
|
| 660 | + def test_url_fragment_actions_on_indoor_map(self): |
| 661 | + org = self._get_org() |
| 662 | + device = self._create_device(organization=org) |
| 663 | + location = self._create_location(type="indoor", organization=org) |
| 664 | + floorplan = self._create_floorplan(floor=1, location=location) |
| 665 | + device_location = self._create_object_location( |
| 666 | + content_object=device, |
| 667 | + location=location, |
| 668 | + floorplan=floorplan, |
| 669 | + organization=org, |
| 670 | + ) |
| 671 | + self.login() |
| 672 | + self.open_popup("_owGeoMap", location.id) |
| 673 | + self.wait_for( |
| 674 | + "element_to_be_clickable", |
| 675 | + By.CSS_SELECTOR, |
| 676 | + ".map-detail .floorplan-btn", |
| 677 | + timeout=5, |
| 678 | + ).click() |
| 679 | + sleep(0.5) |
| 680 | + mapId = "dashboard-geo-map" |
| 681 | + indoorMapId = f"{location.id}:{floorplan.floor}" |
| 682 | + |
| 683 | + with self.subTest("Test setting url fragments on click event of node"): |
| 684 | + self.open_popup("_owIndoorMap", device.id) |
| 685 | + # import ipdb; ipdb.set_trace() |
| 686 | + current_hash = self.web_driver.execute_script( |
| 687 | + "return window.location.hash;" |
| 688 | + ) |
| 689 | + expected_hash = ( |
| 690 | + f"#id={mapId}&nodeId={location.id};" |
| 691 | + f"id={quote_plus(indoorMapId)}&nodeId={device_location.id}" |
| 692 | + ) |
| 693 | + self.assertIn(expected_hash, current_hash) |
| 694 | + |
| 695 | + with self.subTest("Test applying url fragment state on indoor map"): |
| 696 | + current_url = self.web_driver.current_url |
| 697 | + self.web_driver.switch_to.new_window("tab") |
| 698 | + tabs = self.web_driver.window_handles |
| 699 | + self.web_driver.switch_to.window(tabs[1]) |
| 700 | + self.web_driver.get(current_url) |
| 701 | + sleep(0.5) |
| 702 | + popup = self.find_element(By.CSS_SELECTOR, ".njg-tooltip-inner") |
| 703 | + self.assertTrue(popup.is_displayed()) |
| 704 | + self.assertIn(device.name, popup.get_attribute("innerHTML")) |
| 705 | + self.web_driver.close() |
| 706 | + self.web_driver.switch_to.window(tabs[0]) |
| 707 | + |
| 708 | + with self.subTest("Test with incorrect node Id"): |
| 709 | + incorrect_url = ( |
| 710 | + f"{self.live_server_url}/admin/#id={indoorMapId}&nodeId=incorrectId" |
| 711 | + ) |
| 712 | + self.web_driver.switch_to.new_window("tab") |
| 713 | + tabs = self.web_driver.window_handles |
| 714 | + self.web_driver.switch_to.window(tabs[1]) |
| 715 | + self.web_driver.get(incorrect_url) |
| 716 | + sleep(0.5) |
| 717 | + self.wait_for_invisibility(By.CSS_SELECTOR, ".njg-tooltip-inner") |
| 718 | + self.web_driver.close() |
| 719 | + self.web_driver.switch_to.window(tabs[0]) |
| 720 | + |
615 | 721 | def test_dashboard_map_without_permissions(self): |
616 | 722 | user = self._create_user( |
617 | 723 | username="testuser", password="password", is_staff=True, is_superuser=True |
|
0 commit comments