test_issue_saved_searches.py 7.2 KB

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