test_organization_dashboards.py 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. from selenium.webdriver.common.action_chains import ActionChains
  2. from selenium.webdriver.common.by import By
  3. from selenium.webdriver.common.keys import Keys
  4. from selenium.webdriver.support import expected_conditions as EC
  5. from selenium.webdriver.support.wait import WebDriverWait
  6. from sentry.models import (
  7. Dashboard,
  8. DashboardWidget,
  9. DashboardWidgetDisplayTypes,
  10. DashboardWidgetQuery,
  11. DashboardWidgetTypes,
  12. )
  13. from sentry.testutils import AcceptanceTestCase
  14. from sentry.testutils.helpers.datetime import before_now, iso_format
  15. from tests.acceptance.page_objects.dashboard_detail import (
  16. EDIT_WIDGET_BUTTON,
  17. WIDGET_DRAG_HANDLE,
  18. WIDGET_RESIZE_HANDLE,
  19. WIDGET_TITLE_FIELD,
  20. DashboardDetailPage,
  21. )
  22. FEATURE_NAMES = [
  23. "organizations:discover-basic",
  24. "organizations:discover-query",
  25. "organizations:dashboards-basic",
  26. ]
  27. EDIT_FEATURE = ["organizations:dashboards-edit"]
  28. GRID_LAYOUT_FEATURE = ["organizations:dashboard-grid-layout"]
  29. ISSUE_WIDGET_FEATURE = ["organizations:issues-in-dashboards"]
  30. WIDGET_LIBRARY_FEATURE = ["organizations:widget-library"]
  31. class OrganizationDashboardsAcceptanceTest(AcceptanceTestCase):
  32. def setUp(self):
  33. super().setUp()
  34. min_ago = iso_format(before_now(minutes=1))
  35. self.store_event(
  36. data={"event_id": "a" * 32, "message": "oh no", "timestamp": min_ago},
  37. project_id=self.project.id,
  38. )
  39. self.dashboard = Dashboard.objects.create(
  40. title="Dashboard 1", created_by=self.user, organization=self.organization
  41. )
  42. self.existing_widget = DashboardWidget.objects.create(
  43. dashboard=self.dashboard,
  44. order=0,
  45. title="Existing Widget",
  46. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  47. widget_type=DashboardWidgetTypes.DISCOVER,
  48. interval="1d",
  49. )
  50. DashboardWidgetQuery.objects.create(
  51. widget=self.existing_widget, fields=["count()"], order=0
  52. )
  53. self.page = DashboardDetailPage(
  54. self.browser, self.client, organization=self.organization, dashboard=self.dashboard
  55. )
  56. self.login_as(self.user)
  57. def test_view_dashboard(self):
  58. with self.feature(FEATURE_NAMES):
  59. self.page.visit_default_overview()
  60. self.browser.snapshot("dashboards - default overview")
  61. def test_view_dashboard_with_manager(self):
  62. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  63. self.page.visit_default_overview()
  64. self.browser.snapshot("dashboards - default overview manager")
  65. def test_edit_dashboard(self):
  66. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  67. self.page.visit_default_overview()
  68. self.page.enter_edit_state()
  69. self.browser.snapshot("dashboards - edit state")
  70. def test_add_widget(self):
  71. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  72. self.page.visit_default_overview()
  73. self.page.enter_edit_state()
  74. # Add a widget
  75. self.page.click_dashboard_add_widget_button()
  76. self.browser.snapshot("dashboards - add widget")
  77. def test_edit_widget(self):
  78. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  79. self.page.visit_default_overview()
  80. self.page.enter_edit_state()
  81. # Edit the first widget.
  82. button = self.browser.element(EDIT_WIDGET_BUTTON)
  83. button.click()
  84. self.browser.snapshot("dashboards - edit widget")
  85. def test_widget_library(self):
  86. with self.feature(FEATURE_NAMES + EDIT_FEATURE + WIDGET_LIBRARY_FEATURE):
  87. self.page.visit_default_overview()
  88. # Open widget library
  89. self.page.click_dashboard_header_add_widget_button()
  90. self.browser.element('[data-test-id="library-tab"]').click()
  91. # Select/deselect widget library cards
  92. self.browser.element('[data-test-id="widget-library-card-0"]').click()
  93. self.browser.element('[data-test-id="widget-library-card-2"]').click()
  94. self.browser.element('[data-test-id="widget-library-card-3"]').click()
  95. self.browser.element('[data-test-id="widget-library-card-2"]').click()
  96. self.browser.snapshot("dashboards - widget library")
  97. def test_duplicate_widget_in_view_mode(self):
  98. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  99. self.page.visit_dashboard_detail()
  100. self.browser.element('[aria-haspopup="true"]').click()
  101. self.browser.element('[data-test-id="duplicate-widget"]').click()
  102. self.page.wait_until_loaded()
  103. self.browser.element('[aria-haspopup="true"]').click()
  104. self.browser.element('[data-test-id="duplicate-widget"]').click()
  105. self.page.wait_until_loaded()
  106. self.browser.snapshot("dashboard widget - duplicate")
  107. def test_delete_widget_in_view_mode(self):
  108. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  109. self.page.visit_dashboard_detail()
  110. self.browser.element('[aria-haspopup="true"]').click()
  111. self.browser.element('[data-test-id="delete-widget"]').click()
  112. self.browser.element('[data-test-id="confirm-button"]').click()
  113. self.page.wait_until_loaded()
  114. self.browser.snapshot("dashboard widget - delete")
  115. class OrganizationDashboardLayoutAcceptanceTest(AcceptanceTestCase):
  116. def setUp(self):
  117. super().setUp()
  118. min_ago = iso_format(before_now(minutes=1))
  119. self.store_event(
  120. data={"event_id": "a" * 32, "message": "oh no", "timestamp": min_ago},
  121. project_id=self.project.id,
  122. )
  123. self.dashboard = Dashboard.objects.create(
  124. title="Dashboard 1", created_by=self.user, organization=self.organization
  125. )
  126. self.page = DashboardDetailPage(
  127. self.browser, self.client, organization=self.organization, dashboard=self.dashboard
  128. )
  129. self.login_as(self.user)
  130. def capture_screenshots(self, screenshot_name):
  131. """
  132. Captures screenshots in both a pre and post refresh state.
  133. Necessary for verifying that the layout persists after saving.
  134. """
  135. self.page.wait_until_loaded()
  136. self.browser.snapshot(screenshot_name)
  137. self.browser.refresh()
  138. self.page.wait_until_loaded()
  139. self.browser.snapshot(f"{screenshot_name} (refresh)")
  140. def test_default_overview_dashboard_layout(self):
  141. with self.feature(FEATURE_NAMES + GRID_LAYOUT_FEATURE):
  142. self.page.visit_default_overview()
  143. self.browser.snapshot("dashboards - default overview layout")
  144. def test_add_and_move_new_widget_on_existing_dashboard(self):
  145. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  146. self.page.visit_dashboard_detail()
  147. self.page.enter_edit_state()
  148. self.page.add_widget_through_dashboard("New Widget")
  149. # Drag to the right
  150. dragHandle = self.browser.element(WIDGET_DRAG_HANDLE)
  151. action = ActionChains(self.browser.driver)
  152. action.drag_and_drop_by_offset(dragHandle, 1000, 0).perform()
  153. self.page.save_dashboard()
  154. self.capture_screenshots("dashboards - save new widget layout in custom dashboard")
  155. def test_create_new_dashboard_with_modified_widget_layout(self):
  156. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  157. # Create a new dashboard
  158. self.page.visit_create_dashboard()
  159. self.page.add_widget_through_dashboard("New Widget")
  160. # Drag to the right
  161. dragHandle = self.browser.element(WIDGET_DRAG_HANDLE)
  162. action = ActionChains(self.browser.driver)
  163. action.drag_and_drop_by_offset(dragHandle, 1000, 0).perform()
  164. self.page.save_dashboard()
  165. # Wait for page redirect, or else loading check passes too early
  166. wait = WebDriverWait(self.browser.driver, 10)
  167. wait.until(
  168. lambda driver: (
  169. f"/organizations/{self.organization.slug}/dashboards/new/"
  170. not in driver.current_url
  171. )
  172. )
  173. self.capture_screenshots("dashboards - save widget layout in new custom dashboard")
  174. def test_move_existing_widget_on_existing_dashboard(self):
  175. existing_widget = DashboardWidget.objects.create(
  176. dashboard=self.dashboard,
  177. order=0,
  178. title="Existing Widget",
  179. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  180. widget_type=DashboardWidgetTypes.DISCOVER,
  181. interval="1d",
  182. )
  183. DashboardWidgetQuery.objects.create(widget=existing_widget, fields=["count()"], order=0)
  184. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  185. self.page.visit_dashboard_detail()
  186. self.page.enter_edit_state()
  187. # Drag to the right
  188. dragHandle = self.browser.element(WIDGET_DRAG_HANDLE)
  189. action = ActionChains(self.browser.driver)
  190. action.drag_and_drop_by_offset(dragHandle, 1000, 0).perform()
  191. self.page.save_dashboard()
  192. self.capture_screenshots("dashboards - move existing widget on existing dashboard")
  193. def test_add_by_widget_library_do_not_overlap(self):
  194. with self.feature(
  195. FEATURE_NAMES + EDIT_FEATURE + WIDGET_LIBRARY_FEATURE + GRID_LAYOUT_FEATURE
  196. ):
  197. self.page.visit_dashboard_detail()
  198. self.page.click_dashboard_header_add_widget_button()
  199. self.browser.element('[data-test-id="library-tab"]').click()
  200. # Add library widgets
  201. self.browser.element('[data-test-id="widget-library-card-0"]').click()
  202. self.browser.element('[data-test-id="widget-library-card-2"]').click()
  203. self.browser.element('[data-test-id="widget-library-card-3"]').click()
  204. self.browser.element('[data-test-id="widget-library-card-2"]').click()
  205. self.browser.element('[data-test-id="confirm-widgets"]').click()
  206. self.capture_screenshots(
  207. "dashboards - widgets from widget library do not overlap when added"
  208. )
  209. def test_widget_edit_keeps_same_layout_after_modification(self):
  210. existing_widget = DashboardWidget.objects.create(
  211. dashboard=self.dashboard,
  212. order=0,
  213. title="Existing Widget",
  214. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  215. widget_type=DashboardWidgetTypes.DISCOVER,
  216. interval="1d",
  217. )
  218. DashboardWidgetQuery.objects.create(widget=existing_widget, fields=["count()"], order=0)
  219. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  220. self.page.visit_dashboard_detail()
  221. self.page.enter_edit_state()
  222. # Drag existing widget to the right
  223. dragHandle = self.browser.element(WIDGET_DRAG_HANDLE)
  224. action = ActionChains(self.browser.driver)
  225. action.drag_and_drop_by_offset(dragHandle, 1000, 0).perform()
  226. # Edit the existing widget
  227. button = self.browser.element(EDIT_WIDGET_BUTTON)
  228. button.click()
  229. title_input = self.browser.element(WIDGET_TITLE_FIELD)
  230. title_input.send_keys(Keys.END, "UPDATED!!")
  231. button = self.browser.element('[data-test-id="add-widget"]')
  232. button.click()
  233. # Add and drag new widget to the right
  234. self.page.add_widget_through_dashboard("New Widget")
  235. dragHandle = self.browser.element(
  236. f".react-grid-item:nth-of-type(2) {WIDGET_DRAG_HANDLE}"
  237. )
  238. action = ActionChains(self.browser.driver)
  239. action.drag_and_drop_by_offset(dragHandle, 1000, 0)
  240. action.perform()
  241. # Edit the new widget
  242. button = self.browser.element(f".react-grid-item:nth-of-type(2) {EDIT_WIDGET_BUTTON}")
  243. button.click()
  244. title_input = self.browser.element(WIDGET_TITLE_FIELD)
  245. title_input.send_keys(Keys.END, "UPDATED!!")
  246. button = self.browser.element('[data-test-id="add-widget"]')
  247. button.click()
  248. self.page.save_dashboard()
  249. self.capture_screenshots(
  250. "dashboards - edit widgets after layout change does not reset layout"
  251. )
  252. def test_add_issue_widgets_do_not_overlap(self):
  253. def add_issue_widget(widget_title):
  254. self.browser.wait_until_clickable('[data-test-id="widget-add"]')
  255. self.page.click_dashboard_add_widget_button()
  256. title_input = self.browser.element(WIDGET_TITLE_FIELD)
  257. title_input.send_keys(widget_title)
  258. self.browser.element(
  259. '[aria-label="Select Issues (States, Assignment, Time, etc.)"]'
  260. ).click()
  261. button = self.browser.element('[data-test-id="add-widget"]')
  262. button.click()
  263. with self.feature(
  264. FEATURE_NAMES + EDIT_FEATURE + ISSUE_WIDGET_FEATURE + GRID_LAYOUT_FEATURE
  265. ):
  266. self.page.visit_dashboard_detail()
  267. self.page.enter_edit_state()
  268. add_issue_widget("Issue Widget 1")
  269. add_issue_widget("Issue Widget 2")
  270. self.page.save_dashboard()
  271. self.capture_screenshots("dashboards - issue widgets do not overlap")
  272. def test_resize_new_and_existing_widgets(self):
  273. existing_widget = DashboardWidget.objects.create(
  274. dashboard=self.dashboard,
  275. order=0,
  276. title="Existing Widget",
  277. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  278. widget_type=DashboardWidgetTypes.DISCOVER,
  279. interval="1d",
  280. )
  281. DashboardWidgetQuery.objects.create(widget=existing_widget, fields=["count()"], order=0)
  282. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  283. self.page.visit_dashboard_detail()
  284. self.page.enter_edit_state()
  285. # Resize existing widget
  286. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  287. action = ActionChains(self.browser.driver)
  288. action.drag_and_drop_by_offset(resizeHandle, 500, 0).perform()
  289. self.page.add_widget_through_dashboard("New Widget")
  290. # Drag it to the left for consistency
  291. dragHandle = self.browser.element(
  292. f".react-grid-item:nth-of-type(2) {WIDGET_DRAG_HANDLE}"
  293. )
  294. action = ActionChains(self.browser.driver)
  295. action.drag_and_drop_by_offset(dragHandle, -1000, 0).perform()
  296. # Resize new widget, get the 2nd element instead of the "last" because the "last" is
  297. # the add widget button
  298. resizeHandle = self.browser.element(
  299. f".react-grid-item:nth-of-type(2) {WIDGET_RESIZE_HANDLE}"
  300. )
  301. action = ActionChains(self.browser.driver)
  302. action.drag_and_drop_by_offset(resizeHandle, 500, 0).perform()
  303. self.page.save_dashboard()
  304. self.capture_screenshots("dashboards - resize new and existing widgets")
  305. def test_delete_existing_widget_does_not_trigger_new_widget_layout_reset(self):
  306. existing_widget = DashboardWidget.objects.create(
  307. dashboard=self.dashboard,
  308. order=0,
  309. title="Existing Widget",
  310. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  311. widget_type=DashboardWidgetTypes.DISCOVER,
  312. interval="1d",
  313. )
  314. DashboardWidgetQuery.objects.create(widget=existing_widget, fields=["count()"], order=0)
  315. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  316. self.page.visit_dashboard_detail()
  317. self.page.enter_edit_state()
  318. self.page.add_widget_through_dashboard("New Widget")
  319. # Drag it to the bottom left
  320. dragHandle = self.browser.element(
  321. f".react-grid-item:nth-of-type(2) {WIDGET_DRAG_HANDLE}"
  322. )
  323. action = ActionChains(self.browser.driver)
  324. action.drag_and_drop_by_offset(dragHandle, -500, 500).perform()
  325. # Resize new widget, get the 2nd element instead of the "last" because the "last" is
  326. # the add widget button
  327. resizeHandle = self.browser.element(
  328. f".react-grid-item:nth-of-type(2) {WIDGET_RESIZE_HANDLE}"
  329. )
  330. action = ActionChains(self.browser.driver)
  331. action.drag_and_drop_by_offset(resizeHandle, 500, 0).perform()
  332. # Delete first existing widget
  333. delete_widget_button = self.browser.element(
  334. '.react-grid-item:first-of-type [data-test-id="widget-delete"]'
  335. )
  336. delete_widget_button.click()
  337. self.page.save_dashboard()
  338. self.capture_screenshots(
  339. "dashboards - delete existing widget does not reset new widget layout"
  340. )
  341. def test_resize_big_number_widget(self):
  342. existing_widget = DashboardWidget.objects.create(
  343. dashboard=self.dashboard,
  344. order=0,
  345. title="Big Number Widget",
  346. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  347. widget_type=DashboardWidgetTypes.DISCOVER,
  348. interval="1d",
  349. )
  350. DashboardWidgetQuery.objects.create(
  351. widget=existing_widget, fields=["count_unique(issue)"], order=0
  352. )
  353. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  354. self.page.visit_dashboard_detail()
  355. self.page.enter_edit_state()
  356. # Resize existing widget
  357. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  358. action = ActionChains(self.browser.driver)
  359. action.drag_and_drop_by_offset(resizeHandle, 200, 200).perform()
  360. self.page.save_dashboard()
  361. self.capture_screenshots("dashboards - resize big number widget")
  362. def test_default_layout_when_widgets_do_not_have_layout_set(self):
  363. existing_widgets = DashboardWidget.objects.bulk_create(
  364. [
  365. DashboardWidget(
  366. dashboard=self.dashboard,
  367. order=i,
  368. title=f"Existing Widget {i}",
  369. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  370. widget_type=DashboardWidgetTypes.DISCOVER,
  371. interval="1d",
  372. )
  373. for i in range(4)
  374. ]
  375. )
  376. DashboardWidgetQuery.objects.bulk_create(
  377. [
  378. DashboardWidgetQuery(widget=existing_widget, fields=["count()"], order=0)
  379. for existing_widget in existing_widgets
  380. ]
  381. )
  382. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  383. self.page.visit_dashboard_detail()
  384. self.page.wait_until_loaded()
  385. self.browser.snapshot("dashboards - default layout when widgets do not have layout set")
  386. def test_duplicate_widget_in_view_mode(self):
  387. existing_widget = DashboardWidget.objects.create(
  388. dashboard=self.dashboard,
  389. order=0,
  390. title="Big Number Widget",
  391. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  392. widget_type=DashboardWidgetTypes.DISCOVER,
  393. interval="1d",
  394. )
  395. DashboardWidgetQuery.objects.create(
  396. widget=existing_widget, fields=["count_unique(issue)"], order=0
  397. )
  398. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  399. self.page.visit_dashboard_detail()
  400. self.browser.element('[aria-haspopup="true"]').click()
  401. self.browser.element('[data-test-id="duplicate-widget"]').click()
  402. self.page.wait_until_loaded()
  403. self.browser.element('[aria-haspopup="true"]').click()
  404. self.browser.element('[data-test-id="duplicate-widget"]').click()
  405. self.page.wait_until_loaded()
  406. # Should not trigger alert
  407. self.page.enter_edit_state()
  408. self.page.click_cancel_button()
  409. wait = WebDriverWait(self.browser.driver, 5)
  410. wait.until_not(EC.alert_is_present())
  411. self.browser.snapshot("dashboard widget - duplicate with grid")
  412. def test_delete_widget_in_view_mode(self):
  413. existing_widget = DashboardWidget.objects.create(
  414. dashboard=self.dashboard,
  415. order=0,
  416. title="Big Number Widget",
  417. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  418. widget_type=DashboardWidgetTypes.DISCOVER,
  419. interval="1d",
  420. )
  421. DashboardWidgetQuery.objects.create(
  422. widget=existing_widget, fields=["count_unique(issue)"], order=0
  423. )
  424. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  425. self.page.visit_dashboard_detail()
  426. self.browser.element('[aria-haspopup="true"]').click()
  427. self.browser.element('[data-test-id="delete-widget"]').click()
  428. self.browser.element('[data-test-id="confirm-button"]').click()
  429. self.page.wait_until_loaded()
  430. self.browser.snapshot("dashboard widget - delete with grid")
  431. def test_cancel_without_changes_does_not_trigger_confirm_with_widget_library_through_header(
  432. self,
  433. ):
  434. with self.feature(
  435. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  436. ):
  437. self.page.visit_dashboard_detail()
  438. # Open widget library
  439. self.page.click_dashboard_header_add_widget_button()
  440. self.browser.element('[data-test-id="library-tab"]').click()
  441. # Select/deselect widget library cards
  442. self.browser.element('[data-test-id="widget-library-card-0"]').click()
  443. self.browser.element('[data-test-id="widget-library-card-2"]').click()
  444. # Save widget library selections
  445. button = self.browser.element('[data-test-id="confirm-widgets"]')
  446. button.click()
  447. self.page.wait_until_loaded()
  448. # Should not trigger alert
  449. self.page.enter_edit_state()
  450. self.page.click_cancel_button()
  451. wait = WebDriverWait(self.browser.driver, 5)
  452. wait.until_not(EC.alert_is_present())
  453. def test_cancel_without_changes_does_not_trigger_confirm_with_custom_widget_through_header(
  454. self,
  455. ):
  456. with self.feature(
  457. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  458. ):
  459. self.page.visit_dashboard_detail()
  460. self.page.click_dashboard_header_add_widget_button()
  461. title_input = self.browser.element(WIDGET_TITLE_FIELD)
  462. title_input.send_keys("New custom widget")
  463. button = self.browser.element('[data-test-id="add-widget"]')
  464. button.click()
  465. self.page.wait_until_loaded()
  466. # Should not trigger confirm dialog
  467. self.page.enter_edit_state()
  468. self.page.click_cancel_button()
  469. wait = WebDriverWait(self.browser.driver, 5)
  470. wait.until_not(EC.alert_is_present())
  471. def test_position_when_adding_multiple_widgets_through_add_widget_tile_in_edit(
  472. self,
  473. ):
  474. with self.feature(
  475. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  476. ):
  477. self.page.visit_dashboard_detail()
  478. self.page.enter_edit_state()
  479. # Widgets should take up the whole first row and the first spot in second row
  480. self.page.add_widget_through_dashboard("A")
  481. self.page.add_widget_through_dashboard("B")
  482. self.page.add_widget_through_dashboard("C")
  483. self.page.add_widget_through_dashboard("D")
  484. self.page.wait_until_loaded()
  485. self.page.save_dashboard()
  486. self.capture_screenshots(
  487. "dashboards - position when adding multiple widgets through Add Widget tile in edit"
  488. )
  489. def test_position_when_adding_multiple_widgets_through_add_widget_tile_in_create(
  490. self,
  491. ):
  492. with self.feature(
  493. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  494. ):
  495. self.page.visit_create_dashboard()
  496. # Widgets should take up the whole first row and the first spot in second row
  497. self.page.add_widget_through_dashboard("A")
  498. self.page.add_widget_through_dashboard("B")
  499. self.page.add_widget_through_dashboard("C")
  500. self.page.add_widget_through_dashboard("D")
  501. self.page.wait_until_loaded()
  502. self.page.save_dashboard()
  503. # Wait for page redirect, or else loading check passes too early
  504. wait = WebDriverWait(self.browser.driver, 10)
  505. wait.until(
  506. lambda driver: (
  507. f"/organizations/{self.organization.slug}/dashboards/new/"
  508. not in driver.current_url
  509. )
  510. )
  511. self.capture_screenshots(
  512. "dashboards - position when adding multiple widgets through Add Widget tile in create"
  513. )
  514. def test_deleting_stacked_widgets_by_context_menu_does_not_trigger_confirm_on_edit_cancel(
  515. self,
  516. ):
  517. layouts = [
  518. {"x": 0, "y": 0, "w": 2, "h": 2, "minH": 2},
  519. {"x": 0, "y": 2, "w": 2, "h": 2, "minH": 2},
  520. ]
  521. existing_widgets = DashboardWidget.objects.bulk_create(
  522. [
  523. DashboardWidget(
  524. dashboard=self.dashboard,
  525. order=i,
  526. title=f"Existing Widget {i}",
  527. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  528. widget_type=DashboardWidgetTypes.DISCOVER,
  529. interval="1d",
  530. detail={"layout": layout},
  531. )
  532. for i, layout in enumerate(layouts)
  533. ]
  534. )
  535. DashboardWidgetQuery.objects.bulk_create(
  536. DashboardWidgetQuery(widget=widget, fields=["count()"], order=0)
  537. for widget in existing_widgets
  538. )
  539. with self.feature(
  540. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  541. ):
  542. self.page.visit_dashboard_detail()
  543. dropdown_trigger = self.browser.element('[aria-haspopup="true"]')
  544. dropdown_trigger.click()
  545. delete_widget_menu_item = self.browser.element('[data-test-id="delete-widget"]')
  546. delete_widget_menu_item.click()
  547. confirm_button = self.browser.element('[data-test-id="confirm-button"]')
  548. confirm_button.click()
  549. wait = WebDriverWait(self.browser.driver, 5)
  550. wait.until(
  551. EC.presence_of_element_located(
  552. (By.XPATH, "//*[contains(text(),'Dashboard updated')]")
  553. )
  554. )
  555. # Should not trigger confirm dialog
  556. self.page.enter_edit_state()
  557. self.page.click_cancel_button()
  558. wait.until_not(EC.alert_is_present())
  559. def test_changing_number_widget_to_area_updates_widget_height(
  560. self,
  561. ):
  562. layouts = [
  563. {"x": 0, "y": 0, "w": 2, "h": 1, "minH": 1},
  564. {"x": 0, "y": 1, "w": 2, "h": 1, "minH": 1},
  565. ]
  566. existing_widgets = DashboardWidget.objects.bulk_create(
  567. [
  568. DashboardWidget(
  569. dashboard=self.dashboard,
  570. order=i,
  571. title=f"Big Number {i}",
  572. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  573. widget_type=DashboardWidgetTypes.DISCOVER,
  574. interval="1d",
  575. detail={"layout": layout},
  576. )
  577. for i, layout in enumerate(layouts)
  578. ]
  579. )
  580. DashboardWidgetQuery.objects.bulk_create(
  581. DashboardWidgetQuery(widget=widget, fields=["count()"], order=0)
  582. for widget in existing_widgets
  583. )
  584. with self.feature(
  585. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  586. ):
  587. self.page.visit_dashboard_detail()
  588. # Open edit modal for first widget
  589. dropdown_trigger = self.browser.element('[aria-haspopup="true"]')
  590. dropdown_trigger.click()
  591. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  592. edit_widget_menu_item.click()
  593. # Change the chart type to the first visualization option - Area chart
  594. chart_type_input = self.browser.element("#react-select-2-input")
  595. chart_type_input.send_keys("Area", Keys.ENTER)
  596. button = self.browser.element('[data-test-id="add-widget"]')
  597. button.click()
  598. # No confirm dialog because of shifting lower element
  599. self.page.enter_edit_state()
  600. self.page.click_cancel_button()
  601. wait = WebDriverWait(self.browser.driver, 5)
  602. wait.until_not(EC.alert_is_present())
  603. # Try to decrease height to 1 row, should stay at 2 rows
  604. self.page.enter_edit_state()
  605. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  606. action = ActionChains(self.browser.driver)
  607. action.drag_and_drop_by_offset(resizeHandle, 0, -100).perform()
  608. self.page.save_dashboard()
  609. self.browser.snapshot(
  610. "dashboards - change from big number to area chart increases widget to min height"
  611. )
  612. def test_changing_number_widget_larger_than_min_height_for_area_chart_keeps_height(
  613. self,
  614. ):
  615. existing_widget = DashboardWidget.objects.create(
  616. dashboard=self.dashboard,
  617. order=0,
  618. title="Originally Big Number - 3 rows",
  619. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  620. widget_type=DashboardWidgetTypes.DISCOVER,
  621. interval="1d",
  622. detail={"layout": {"x": 0, "y": 0, "w": 2, "h": 3, "minH": 1}},
  623. )
  624. DashboardWidgetQuery.objects.create(widget=existing_widget, fields=["count()"], order=0)
  625. with self.feature(
  626. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  627. ):
  628. self.page.visit_dashboard_detail()
  629. # Open edit modal for first widget
  630. dropdown_trigger = self.browser.element('[aria-haspopup="true"]')
  631. dropdown_trigger.click()
  632. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  633. edit_widget_menu_item.click()
  634. # Change the chart type to the first visualization option - Area chart
  635. chart_type_input = self.browser.element("#react-select-2-input")
  636. chart_type_input.send_keys("Area", Keys.ENTER)
  637. button = self.browser.element('[data-test-id="add-widget"]')
  638. button.click()
  639. self.page.wait_until_loaded()
  640. self.browser.snapshot(
  641. "dashboards - change from big number to other chart of more than 2 rows keeps height"
  642. )
  643. # Try to decrease height by >1 row, should be at 2 rows
  644. self.page.enter_edit_state()
  645. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  646. action = ActionChains(self.browser.driver)
  647. action.drag_and_drop_by_offset(resizeHandle, 0, -400).perform()
  648. self.page.save_dashboard()
  649. self.browser.snapshot(
  650. "dashboards - change from big number to other chart enforces min height of 2"
  651. )
  652. def test_changing_area_widget_larger_than_min_height_for_number_chart_keeps_height(
  653. self,
  654. ):
  655. existing_widget = DashboardWidget.objects.create(
  656. dashboard=self.dashboard,
  657. order=0,
  658. title="Originally Area Chart - 3 rows",
  659. display_type=DashboardWidgetDisplayTypes.AREA_CHART,
  660. widget_type=DashboardWidgetTypes.DISCOVER,
  661. interval="1d",
  662. detail={"layout": {"x": 0, "y": 0, "w": 2, "h": 3, "minH": 2}},
  663. )
  664. DashboardWidgetQuery.objects.create(widget=existing_widget, fields=["count()"], order=0)
  665. with self.feature(
  666. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  667. ):
  668. self.page.visit_dashboard_detail()
  669. # Open edit modal for first widget
  670. dropdown_trigger = self.browser.element('[aria-haspopup="true"]')
  671. dropdown_trigger.click()
  672. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  673. edit_widget_menu_item.click()
  674. # Change the chart type to big number
  675. chart_type_input = self.browser.element("#react-select-2-input")
  676. chart_type_input.send_keys("Big Number", Keys.ENTER)
  677. button = self.browser.element('[data-test-id="add-widget"]')
  678. button.click()
  679. self.page.wait_until_loaded()
  680. self.browser.snapshot("dashboards - change from area chart to big number keeps height")
  681. # Decrease height by >1 row, should stop at 1 row
  682. self.page.enter_edit_state()
  683. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  684. action = ActionChains(self.browser.driver)
  685. action.drag_and_drop_by_offset(resizeHandle, 0, -400).perform()
  686. self.page.save_dashboard()
  687. self.browser.snapshot(
  688. "dashboards - change from area chart to big number allows min height of 1"
  689. )
  690. class OrganizationDashboardsManageAcceptanceTest(AcceptanceTestCase):
  691. def setUp(self):
  692. super().setUp()
  693. self.team = self.create_team(organization=self.organization, name="Mariachi Band")
  694. self.project = self.create_project(
  695. organization=self.organization, teams=[self.team], name="Bengal"
  696. )
  697. self.dashboard = Dashboard.objects.create(
  698. title="Dashboard 1", created_by=self.user, organization=self.organization
  699. )
  700. self.widget_1 = DashboardWidget.objects.create(
  701. dashboard=self.dashboard,
  702. order=0,
  703. title="Widget 1",
  704. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  705. widget_type=DashboardWidgetTypes.DISCOVER,
  706. interval="1d",
  707. )
  708. self.widget_2 = DashboardWidget.objects.create(
  709. dashboard=self.dashboard,
  710. order=1,
  711. title="Widget 2",
  712. display_type=DashboardWidgetDisplayTypes.TABLE,
  713. widget_type=DashboardWidgetTypes.DISCOVER,
  714. interval="1d",
  715. )
  716. self.login_as(self.user)
  717. self.default_path = f"/organizations/{self.organization.slug}/dashboards/"
  718. def wait_until_loaded(self):
  719. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  720. self.browser.wait_until_not('[data-test-id="loading-placeholder"]')
  721. def test_dashboard_manager(self):
  722. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  723. self.browser.get(self.default_path)
  724. self.wait_until_loaded()
  725. self.browser.snapshot("dashboards - manage overview")
  726. def test_dashboard_manager_with_unset_layouts_and_defined_layouts(self):
  727. dashboard_with_layouts = Dashboard.objects.create(
  728. title="Dashboard with some defined layouts",
  729. created_by=self.user,
  730. organization=self.organization,
  731. )
  732. DashboardWidget.objects.create(
  733. dashboard=dashboard_with_layouts,
  734. order=0,
  735. title="Widget 1",
  736. display_type=DashboardWidgetDisplayTypes.BAR_CHART,
  737. widget_type=DashboardWidgetTypes.DISCOVER,
  738. interval="1d",
  739. detail={"layout": {"x": 1, "y": 0, "w": 3, "h": 3, "minH": 2}},
  740. )
  741. # This widget has no layout, but should position itself at
  742. # x: 4, y: 0, w: 2, h: 2
  743. DashboardWidget.objects.create(
  744. dashboard=dashboard_with_layouts,
  745. order=1,
  746. title="Widget 2",
  747. display_type=DashboardWidgetDisplayTypes.TABLE,
  748. widget_type=DashboardWidgetTypes.DISCOVER,
  749. interval="1d",
  750. )
  751. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  752. self.browser.get(self.default_path)
  753. self.wait_until_loaded()
  754. self.browser.snapshot("dashboards - manage overview with grid layout")