test_issue_saved_searches.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # from datetime import datetime
  2. # from unittest.mock import patch
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.common.keys import Keys
  5. from selenium.webdriver.support.wait import WebDriverWait
  6. from fixtures.page_objects.issue_list import IssueListPage
  7. from sentry.models import Visibility
  8. from sentry.models.savedsearch import SavedSearch, SortOptions
  9. from sentry.testutils import AcceptanceTestCase, SnubaTestCase
  10. from sentry.testutils.silo import region_silo_test
  11. @region_silo_test
  12. class OrganizationGroupIndexTest(AcceptanceTestCase, SnubaTestCase):
  13. def setUp(self):
  14. super().setUp()
  15. self.user = self.create_user("foo@example.com")
  16. self.org = self.create_organization(owner=self.user, name="Rowdy Tiger")
  17. self.team = self.create_team(
  18. organization=self.org, name="Mariachi Band", members=[self.user]
  19. )
  20. self.project = self.create_project(organization=self.org, teams=[self.team], name="Bengal")
  21. self.other_project = self.create_project(
  22. organization=self.org, teams=[self.team], name="Sumatra"
  23. )
  24. self.login_as(self.user)
  25. self.page = IssueListPage(self.browser, self.client)
  26. self.dismiss_assistant()
  27. # Create recommended saved searches
  28. self.create_saved_search(
  29. name="Assigned to Me",
  30. query="is:unresolved assigned:me",
  31. visibility=Visibility.ORGANIZATION,
  32. is_global=True,
  33. )
  34. self.create_saved_search(
  35. name="Errors Only",
  36. query="is:unresolved evel:error",
  37. visibility=Visibility.ORGANIZATION,
  38. is_global=True,
  39. )
  40. def test_click_saved_search(self):
  41. self.page.visit_issue_list(self.org.slug)
  42. self.browser.click_when_visible('button[aria-label="Custom Search"]')
  43. # Navigate to a recommended saved search
  44. self.browser.click('button[aria-label="Errors Only"]')
  45. self.page.wait_until_loaded()
  46. self.browser.snapshot("issue list after navigating to saved search", desktop_only=True)
  47. def test_create_saved_search(self):
  48. self.page.visit_issue_list(self.org.slug)
  49. self.browser.click_when_visible('button[aria-label="Custom Search"]')
  50. self.browser.snapshot("issue list with no saved searches", desktop_only=True)
  51. self.browser.click('[aria-label="Create a new saved search"]')
  52. self.browser.wait_until('[role="dialog"]')
  53. self.browser.snapshot("create saved search modal open", desktop_only=True)
  54. self.browser.find_element(by=By.NAME, value="name").send_keys("My Saved Search")
  55. query_input = self.browser.find_element(
  56. by=By.CSS_SELECTOR, value='[role="dialog"] textarea'
  57. )
  58. self.browser.click('[role="dialog"] button[aria-label="Clear search"]')
  59. query_input.send_keys("browser.name:Firefox", Keys.ENTER)
  60. self.browser.click('[role="dialog"] button[aria-label="Save"]')
  61. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  62. # The saved search should have been created with the correct options
  63. created_search = SavedSearch.objects.get(name="My Saved Search")
  64. assert created_search
  65. assert created_search.query == "browser.name:Firefox"
  66. assert created_search.sort == SortOptions.DATE
  67. assert created_search.visibility == Visibility.OWNER
  68. assert not created_search.is_global
  69. assert created_search.owner_id == self.user.id
  70. # And the sidebar should have been updated with the new search item
  71. assert self.browser.find_element(
  72. by=By.CSS_SELECTOR, value='button[aria-label="My Saved Search"]'
  73. )
  74. def test_edit_saved_search(self):
  75. # Start with a user saved search
  76. self.create_saved_search(
  77. organization=self.org,
  78. name="My Saved Search",
  79. query="browser.name:Firefox",
  80. visibility=Visibility.OWNER,
  81. owner=self.user,
  82. )
  83. self.page.visit_issue_list(self.org.slug)
  84. self.browser.click_when_visible('button[aria-label="Custom Search"]')
  85. self.browser.move_to('button[aria-label="My Saved Search"]')
  86. self.browser.wait_until_clickable('button[aria-label="Saved search options"]')
  87. self.browser.click('button[aria-label="Saved search options"]')
  88. self.browser.click('[data-test-id="edit"]')
  89. self.browser.wait_until('[role="dialog"]')
  90. self.browser.snapshot("edit saved search modal open", desktop_only=True)
  91. self.browser.find_element(by=By.NAME, value="name").clear()
  92. self.browser.find_element(by=By.NAME, value="name").send_keys("New Saved Search Name")
  93. self.browser.click('[role="dialog"] button[aria-label="Save"]')
  94. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  95. # The saved search should have been updated with the correct options
  96. created_search = SavedSearch.objects.get(name="New Saved Search Name")
  97. assert created_search
  98. assert created_search.query == "browser.name:Firefox"
  99. assert created_search.sort == SortOptions.DATE
  100. assert created_search.visibility == Visibility.OWNER
  101. assert not created_search.is_global
  102. assert created_search.owner_id == self.user.id
  103. # And the sidebar should have been updated
  104. assert self.browser.find_element(
  105. by=By.CSS_SELECTOR, value='button[aria-label="New Saved Search Name"]'
  106. )
  107. def test_delete_saved_search(self):
  108. # Start with a user saved search
  109. self.create_saved_search(
  110. organization=self.org,
  111. name="My Saved Search",
  112. query="browser.name:Firefox",
  113. visibility=Visibility.OWNER,
  114. owner=self.user,
  115. )
  116. self.page.visit_issue_list(self.org.slug)
  117. self.browser.click_when_visible('button[aria-label="Custom Search"]')
  118. self.browser.move_to('button[aria-label="My Saved Search"]')
  119. self.browser.wait_until_clickable('button[aria-label="Saved search options"]')
  120. self.browser.click('button[aria-label="Saved search options"]')
  121. self.browser.click('[data-test-id="delete"]')
  122. self.browser.wait_until('[role="dialog"]')
  123. self.browser.click('[role="dialog"] button[aria-label="Confirm"]')
  124. # Search is immediately removed from the UI
  125. assert not self.browser.element_exists('button[aria-label="My Saved Search"]')
  126. # The saved search should be removed from the db
  127. # Since this is an optimistic update there is nothing to wait for in the UI
  128. wait = WebDriverWait(self.browser.driver, 10)
  129. wait.until(lambda _: not SavedSearch.objects.filter(name="My Saved Search").exists())