test_issue_saved_searches.py 6.3 KB

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