test_issue_saved_searches.py 6.3 KB

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