test_organization_dashboards.py 31 KB

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