test_issue_saved_searches.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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"] textarea'
  53. )
  54. self.browser.click('[role="dialog"] button[aria-label="Clear search"]')
  55. query_input.send_keys("browser.name:Firefox", 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 created_search.query == "browser.name:Firefox"
  62. assert created_search.sort == SortOptions.DATE
  63. assert created_search.visibility == Visibility.OWNER
  64. assert not created_search.is_global
  65. assert created_search.owner_id == self.user.id
  66. # And the sidebar should have been updated with the new search item
  67. assert self.browser.find_element(
  68. by=By.CSS_SELECTOR, value='button[aria-label="My Saved Search"]'
  69. )
  70. def test_edit_saved_search(self):
  71. # Start with a user saved search
  72. self.create_saved_search(
  73. organization=self.org,
  74. name="My Saved Search",
  75. query="browser.name:Firefox",
  76. visibility=Visibility.OWNER,
  77. owner=self.user,
  78. )
  79. self.page.visit_issue_list(self.org.slug)
  80. self.browser.click_when_visible('button[aria-label="Custom Search"]')
  81. self.browser.move_to('button[aria-label="My Saved Search"]')
  82. self.browser.wait_until_clickable('button[aria-label="Saved search options"]')
  83. self.browser.click('button[aria-label="Saved search options"]')
  84. self.browser.click('[data-test-id="edit"]')
  85. self.browser.wait_until('[role="dialog"]')
  86. self.browser.find_element(by=By.NAME, value="name").clear()
  87. self.browser.find_element(by=By.NAME, value="name").send_keys("New Saved Search Name")
  88. self.browser.click('[role="dialog"] button[aria-label="Save"]')
  89. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  90. # The saved search should have been updated with the correct options
  91. created_search = SavedSearch.objects.get(name="New Saved Search Name")
  92. assert created_search
  93. assert created_search.query == "browser.name:Firefox"
  94. assert created_search.sort == SortOptions.DATE
  95. assert created_search.visibility == Visibility.OWNER
  96. assert not created_search.is_global
  97. assert created_search.owner_id == self.user.id
  98. # And the sidebar should have been updated
  99. assert self.browser.find_element(
  100. by=By.CSS_SELECTOR, value='button[aria-label="New Saved Search Name"]'
  101. )
  102. def test_delete_saved_search(self):
  103. # Start with a user saved search
  104. self.create_saved_search(
  105. organization=self.org,
  106. name="My Saved Search",
  107. query="browser.name:Firefox",
  108. visibility=Visibility.OWNER,
  109. owner=self.user,
  110. )
  111. self.page.visit_issue_list(self.org.slug)
  112. self.browser.click_when_visible('button[aria-label="Custom Search"]')
  113. self.browser.move_to('button[aria-label="My Saved Search"]')
  114. self.browser.wait_until_clickable('button[aria-label="Saved search options"]')
  115. self.browser.click('button[aria-label="Saved search options"]')
  116. self.browser.click('[data-test-id="delete"]')
  117. self.browser.wait_until('[role="dialog"]')
  118. self.browser.click('[role="dialog"] button[aria-label="Confirm"]')
  119. # Search is immediately removed from the UI
  120. assert not self.browser.element_exists('button[aria-label="My Saved Search"]')
  121. # The saved search should be removed from the db
  122. # Since this is an optimistic update there is nothing to wait for in the UI
  123. wait = WebDriverWait(self.browser.driver, 10)
  124. wait.until(lambda _: not SavedSearch.objects.filter(name="My Saved Search").exists())