test_organization_dashboards.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. from sentry.models import (
  2. Dashboard,
  3. DashboardWidget,
  4. DashboardWidgetDisplayTypes,
  5. DashboardWidgetTypes,
  6. )
  7. from sentry.testutils import AcceptanceTestCase
  8. from sentry.testutils.helpers.datetime import before_now, iso_format
  9. FEATURE_NAMES = [
  10. "organizations:discover-basic",
  11. "organizations:discover-query",
  12. "organizations:dashboards-basic",
  13. ]
  14. EDIT_FEATURE = ["organizations:dashboards-edit"]
  15. class OrganizationDashboardsAcceptanceTest(AcceptanceTestCase):
  16. def setUp(self):
  17. super().setUp()
  18. min_ago = iso_format(before_now(minutes=1))
  19. self.default_path = f"/organizations/{self.organization.slug}/dashboard/default-overview/"
  20. self.store_event(
  21. data={"event_id": "a" * 32, "message": "oh no", "timestamp": min_ago},
  22. project_id=self.project.id,
  23. )
  24. self.login_as(self.user)
  25. def wait_until_loaded(self):
  26. self.browser.wait_until_not(".loading-indicator")
  27. self.browser.wait_until_not('[data-test-id="loading-placeholder"]')
  28. def test_view_dashboard(self):
  29. with self.feature(FEATURE_NAMES):
  30. self.browser.get(self.default_path)
  31. self.wait_until_loaded()
  32. self.browser.snapshot("dashboards - default overview")
  33. def test_view_dashboard_with_manager(self):
  34. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  35. self.browser.get(self.default_path)
  36. self.wait_until_loaded()
  37. self.browser.snapshot("dashboards - default overview manager")
  38. def test_edit_dashboard(self):
  39. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  40. self.browser.get(self.default_path)
  41. self.wait_until_loaded()
  42. button = self.browser.element('[data-test-id="dashboard-edit"]')
  43. button.click()
  44. self.browser.snapshot("dashboards - edit state")
  45. def test_add_widget(self):
  46. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  47. self.browser.get(self.default_path)
  48. self.wait_until_loaded()
  49. # Go to edit mode.
  50. button = self.browser.element('[data-test-id="dashboard-edit"]')
  51. button.click()
  52. # Add a widget
  53. button = self.browser.element('[data-test-id="widget-add"]')
  54. button.click()
  55. self.browser.snapshot("dashboards - add widget")
  56. def test_edit_widget(self):
  57. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  58. self.browser.get(self.default_path)
  59. self.wait_until_loaded()
  60. # Go to edit mode.
  61. button = self.browser.element('[data-test-id="dashboard-edit"]')
  62. button.click()
  63. # Edit the first widget.
  64. button = self.browser.element('[data-test-id="widget-edit"]')
  65. button.click()
  66. self.browser.snapshot("dashboards - edit widget")
  67. def test_widget_library(self):
  68. with self.feature(FEATURE_NAMES + EDIT_FEATURE + ["organizations:widget-library"]):
  69. self.browser.get(self.default_path)
  70. self.wait_until_loaded()
  71. # Go to edit mode.
  72. button = self.browser.element('[data-test-id="add-widget-library"]')
  73. button.click()
  74. self.browser.element('[data-test-id="library-tab"]').click()
  75. # Edit the first widget.
  76. self.browser.element('[data-test-id="widget-library-card-0"]').click()
  77. self.browser.element('[data-test-id="widget-library-card-2"]').click()
  78. self.browser.element('[data-test-id="widget-library-card-3"]').click()
  79. self.browser.element('[data-test-id="widget-library-card-2"]').click()
  80. self.browser.snapshot("dashboards - widget library")
  81. class OrganizationDashboardsManageAcceptanceTest(AcceptanceTestCase):
  82. def setUp(self):
  83. super().setUp()
  84. self.team = self.create_team(organization=self.organization, name="Mariachi Band")
  85. self.project = self.create_project(
  86. organization=self.organization, teams=[self.team], name="Bengal"
  87. )
  88. self.dashboard = Dashboard.objects.create(
  89. title="Dashboard 1", created_by=self.user, organization=self.organization
  90. )
  91. self.widget_1 = DashboardWidget.objects.create(
  92. dashboard=self.dashboard,
  93. order=0,
  94. title="Widget 1",
  95. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  96. widget_type=DashboardWidgetTypes.DISCOVER,
  97. interval="1d",
  98. )
  99. self.widget_2 = DashboardWidget.objects.create(
  100. dashboard=self.dashboard,
  101. order=1,
  102. title="Widget 2",
  103. display_type=DashboardWidgetDisplayTypes.TABLE,
  104. widget_type=DashboardWidgetTypes.DISCOVER,
  105. interval="1d",
  106. )
  107. self.login_as(self.user)
  108. self.default_path = f"/organizations/{self.organization.slug}/dashboards/"
  109. def wait_until_loaded(self):
  110. self.browser.wait_until_not(".loading-indicator")
  111. self.browser.wait_until_not('[data-test-id="loading-placeholder"]')
  112. def test_dashboard_manager(self):
  113. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  114. self.browser.get(self.default_path)
  115. self.wait_until_loaded()
  116. self.browser.snapshot("dashboards - manage overview")