test_organization_dashboards.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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('[aria-label="Issues (States, Assignment, Time, etc.)"]').click()
  173. button = self.browser.element('[aria-label="Add Widget"]')
  174. button.click()
  175. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  176. self.page.visit_dashboard_detail()
  177. self.page.enter_edit_state()
  178. add_issue_widget("Issue Widget 1")
  179. add_issue_widget("Issue Widget 2")
  180. self.page.save_dashboard()
  181. self.capture_screenshots("dashboards - issue widgets do not overlap")
  182. def test_resize_new_and_existing_widgets(self):
  183. existing_widget = DashboardWidget.objects.create(
  184. dashboard=self.dashboard,
  185. order=0,
  186. title="Existing Widget",
  187. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  188. widget_type=DashboardWidgetTypes.DISCOVER,
  189. interval="1d",
  190. )
  191. DashboardWidgetQuery.objects.create(
  192. widget=existing_widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  193. )
  194. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  195. self.page.visit_dashboard_detail()
  196. self.page.enter_edit_state()
  197. # Resize existing widget
  198. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  199. action = ActionChains(self.browser.driver)
  200. action.drag_and_drop_by_offset(resizeHandle, 500, 0).perform()
  201. self.page.add_widget_through_dashboard("New Widget")
  202. # Drag it to the left for consistency
  203. dragHandle = self.browser.element(
  204. f".react-grid-item:nth-of-type(2) {WIDGET_DRAG_HANDLE}"
  205. )
  206. action = ActionChains(self.browser.driver)
  207. action.drag_and_drop_by_offset(dragHandle, -1000, 0).perform()
  208. # Resize new widget, get the 2nd element instead of the "last" because the "last" is
  209. # the add widget button
  210. resizeHandle = self.browser.element(
  211. f".react-grid-item:nth-of-type(2) {WIDGET_RESIZE_HANDLE}"
  212. )
  213. action = ActionChains(self.browser.driver)
  214. action.drag_and_drop_by_offset(resizeHandle, 500, 0).perform()
  215. self.page.save_dashboard()
  216. self.capture_screenshots("dashboards - resize new and existing widgets")
  217. def test_delete_existing_widget_does_not_trigger_new_widget_layout_reset(self):
  218. existing_widget = DashboardWidget.objects.create(
  219. dashboard=self.dashboard,
  220. order=0,
  221. title="Existing Widget",
  222. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  223. widget_type=DashboardWidgetTypes.DISCOVER,
  224. interval="1d",
  225. )
  226. DashboardWidgetQuery.objects.create(
  227. widget=existing_widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  228. )
  229. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  230. self.page.visit_dashboard_detail()
  231. self.page.enter_edit_state()
  232. self.page.add_widget_through_dashboard("New Widget")
  233. # Drag it to the bottom left
  234. dragHandle = self.browser.element(
  235. f".react-grid-item:nth-of-type(2) {WIDGET_DRAG_HANDLE}"
  236. )
  237. action = ActionChains(self.browser.driver)
  238. action.drag_and_drop_by_offset(dragHandle, -500, 500).perform()
  239. # Resize new widget, get the 2nd element instead of the "last" because the "last" is
  240. # the add widget button
  241. resizeHandle = self.browser.element(
  242. f".react-grid-item:nth-of-type(2) {WIDGET_RESIZE_HANDLE}"
  243. )
  244. action = ActionChains(self.browser.driver)
  245. action.drag_and_drop_by_offset(resizeHandle, 500, 0).perform()
  246. # Delete first existing widget
  247. delete_widget_button = self.browser.element(
  248. '.react-grid-item:first-of-type [data-test-id="widget-delete"]'
  249. )
  250. delete_widget_button.click()
  251. self.page.save_dashboard()
  252. self.capture_screenshots(
  253. "dashboards - delete existing widget does not reset new widget layout"
  254. )
  255. def test_resize_big_number_widget(self):
  256. existing_widget = DashboardWidget.objects.create(
  257. dashboard=self.dashboard,
  258. order=0,
  259. title="Big Number Widget",
  260. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  261. widget_type=DashboardWidgetTypes.DISCOVER,
  262. interval="1d",
  263. )
  264. DashboardWidgetQuery.objects.create(
  265. widget=existing_widget,
  266. fields=["count_unique(issue)"],
  267. columns=[],
  268. aggregates=["count_unique(issue)"],
  269. order=0,
  270. )
  271. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  272. self.page.visit_dashboard_detail()
  273. self.page.enter_edit_state()
  274. # Resize existing widget
  275. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  276. action = ActionChains(self.browser.driver)
  277. action.drag_and_drop_by_offset(resizeHandle, 200, 200).perform()
  278. self.page.save_dashboard()
  279. self.capture_screenshots("dashboards - resize big number widget")
  280. def test_default_layout_when_widgets_do_not_have_layout_set(self):
  281. existing_widgets = DashboardWidget.objects.bulk_create(
  282. [
  283. DashboardWidget(
  284. dashboard=self.dashboard,
  285. order=i,
  286. title=f"Existing Widget {i}",
  287. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  288. widget_type=DashboardWidgetTypes.DISCOVER,
  289. interval="1d",
  290. )
  291. for i in range(4)
  292. ]
  293. )
  294. DashboardWidgetQuery.objects.bulk_create(
  295. [
  296. DashboardWidgetQuery(
  297. widget=existing_widget,
  298. fields=["count()"],
  299. columns=[],
  300. aggregates=["count()"],
  301. order=0,
  302. )
  303. for existing_widget in existing_widgets
  304. ]
  305. )
  306. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  307. self.page.visit_dashboard_detail()
  308. self.page.wait_until_loaded()
  309. self.browser.snapshot("dashboards - default layout when widgets do not have layout set")
  310. def test_duplicate_widget_in_view_mode(self):
  311. existing_widget = DashboardWidget.objects.create(
  312. dashboard=self.dashboard,
  313. order=0,
  314. title="Big Number Widget",
  315. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  316. widget_type=DashboardWidgetTypes.DISCOVER,
  317. interval="1d",
  318. )
  319. DashboardWidgetQuery.objects.create(
  320. widget=existing_widget,
  321. fields=["count_unique(issue)"],
  322. columns=[],
  323. aggregates=["count_unique(issue)"],
  324. order=0,
  325. )
  326. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  327. self.page.visit_dashboard_detail()
  328. self.browser.element('[aria-label="Widget actions"]').click()
  329. self.browser.element('[data-test-id="duplicate-widget"]').click()
  330. self.page.wait_until_loaded()
  331. self.browser.element('[aria-label="Widget actions"]').click()
  332. self.browser.element('[data-test-id="duplicate-widget"]').click()
  333. self.page.wait_until_loaded()
  334. # Should not trigger alert
  335. self.page.enter_edit_state()
  336. self.page.click_cancel_button()
  337. wait = WebDriverWait(self.browser.driver, 5)
  338. wait.until_not(EC.alert_is_present())
  339. self.browser.snapshot("dashboard widget - duplicate with grid")
  340. def test_delete_widget_in_view_mode(self):
  341. existing_widget = DashboardWidget.objects.create(
  342. dashboard=self.dashboard,
  343. order=0,
  344. title="Big Number Widget",
  345. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  346. widget_type=DashboardWidgetTypes.DISCOVER,
  347. interval="1d",
  348. )
  349. DashboardWidgetQuery.objects.create(
  350. widget=existing_widget,
  351. fields=["count_unique(issue)"],
  352. columns=[],
  353. aggregates=["count_unique(issue)"],
  354. order=0,
  355. )
  356. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  357. self.page.visit_dashboard_detail()
  358. self.browser.element('[aria-label="Widget actions"]').click()
  359. self.browser.element('[data-test-id="delete-widget"]').click()
  360. self.browser.element('[data-test-id="confirm-button"]').click()
  361. self.page.wait_until_loaded()
  362. self.browser.snapshot("dashboard widget - delete with grid")
  363. def test_cancel_without_changes_does_not_trigger_confirm_with_custom_widget_through_header(
  364. self,
  365. ):
  366. with self.feature(
  367. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  368. ):
  369. self.page.visit_dashboard_detail()
  370. self.page.click_dashboard_header_add_widget_button()
  371. self.browser.element(WIDGET_EDITABLE_TEXT_LABEL).click()
  372. title_input = self.browser.element(WIDGET_TITLE_FIELD)
  373. title_input.send_keys("New custom widget")
  374. button = self.browser.element('[aria-label="Add Widget"]')
  375. button.click()
  376. self.page.wait_until_loaded()
  377. # Should not trigger confirm dialog
  378. self.page.enter_edit_state()
  379. self.page.click_cancel_button()
  380. wait = WebDriverWait(self.browser.driver, 5)
  381. wait.until_not(EC.alert_is_present())
  382. def test_position_when_adding_multiple_widgets_through_add_widget_tile_in_edit(
  383. self,
  384. ):
  385. with self.feature(
  386. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  387. ):
  388. self.page.visit_dashboard_detail()
  389. self.page.enter_edit_state()
  390. # Widgets should take up the whole first row and the first spot in second row
  391. self.page.add_widget_through_dashboard("A")
  392. self.page.add_widget_through_dashboard("B")
  393. self.page.add_widget_through_dashboard("C")
  394. self.page.add_widget_through_dashboard("D")
  395. self.page.wait_until_loaded()
  396. self.page.save_dashboard()
  397. self.capture_screenshots(
  398. "dashboards - position when adding multiple widgets through Add Widget tile in edit"
  399. )
  400. def test_position_when_adding_multiple_widgets_through_add_widget_tile_in_create(
  401. self,
  402. ):
  403. with self.feature(
  404. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  405. ):
  406. self.page.visit_create_dashboard()
  407. # Widgets should take up the whole first row and the first spot in second row
  408. self.page.add_widget_through_dashboard("A")
  409. self.page.add_widget_through_dashboard("B")
  410. self.page.add_widget_through_dashboard("C")
  411. self.page.add_widget_through_dashboard("D")
  412. self.page.wait_until_loaded()
  413. self.page.save_dashboard()
  414. # Wait for page redirect, or else loading check passes too early
  415. wait = WebDriverWait(self.browser.driver, 10)
  416. wait.until(
  417. lambda driver: (
  418. f"/organizations/{self.organization.slug}/dashboards/new/"
  419. not in driver.current_url
  420. )
  421. )
  422. self.capture_screenshots(
  423. "dashboards - position when adding multiple widgets through Add Widget tile in create"
  424. )
  425. def test_deleting_stacked_widgets_by_context_menu_does_not_trigger_confirm_on_edit_cancel(
  426. self,
  427. ):
  428. layouts = [
  429. {"x": 0, "y": 0, "w": 2, "h": 2, "minH": 2},
  430. {"x": 0, "y": 2, "w": 2, "h": 2, "minH": 2},
  431. ]
  432. existing_widgets = DashboardWidget.objects.bulk_create(
  433. [
  434. DashboardWidget(
  435. dashboard=self.dashboard,
  436. order=i,
  437. title=f"Existing Widget {i}",
  438. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  439. widget_type=DashboardWidgetTypes.DISCOVER,
  440. interval="1d",
  441. detail={"layout": layout},
  442. )
  443. for i, layout in enumerate(layouts)
  444. ]
  445. )
  446. DashboardWidgetQuery.objects.bulk_create(
  447. DashboardWidgetQuery(
  448. widget=widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  449. )
  450. for widget in existing_widgets
  451. )
  452. with self.feature(
  453. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  454. ):
  455. self.page.visit_dashboard_detail()
  456. dropdown_trigger = self.browser.element('[aria-label="Widget actions"]')
  457. dropdown_trigger.click()
  458. delete_widget_menu_item = self.browser.element('[data-test-id="delete-widget"]')
  459. delete_widget_menu_item.click()
  460. confirm_button = self.browser.element('[data-test-id="confirm-button"]')
  461. confirm_button.click()
  462. wait = WebDriverWait(self.browser.driver, 5)
  463. wait.until(
  464. EC.presence_of_element_located(
  465. (By.XPATH, "//*[contains(text(),'Dashboard updated')]")
  466. )
  467. )
  468. # Should not trigger confirm dialog
  469. self.page.enter_edit_state()
  470. self.page.click_cancel_button()
  471. wait.until_not(EC.alert_is_present())
  472. def test_changing_number_widget_to_area_updates_widget_height(
  473. self,
  474. ):
  475. layouts = [
  476. (DashboardWidgetDisplayTypes.BIG_NUMBER, {"x": 0, "y": 0, "w": 2, "h": 1, "minH": 1}),
  477. (DashboardWidgetDisplayTypes.LINE_CHART, {"x": 0, "y": 1, "w": 2, "h": 2, "minH": 2}),
  478. ]
  479. existing_widgets = DashboardWidget.objects.bulk_create(
  480. [
  481. DashboardWidget(
  482. dashboard=self.dashboard,
  483. order=i,
  484. title=f"Widget {i}",
  485. display_type=display_type,
  486. widget_type=DashboardWidgetTypes.DISCOVER,
  487. interval="1d",
  488. detail={"layout": layout},
  489. )
  490. for i, (display_type, layout) in enumerate(layouts)
  491. ]
  492. )
  493. DashboardWidgetQuery.objects.bulk_create(
  494. DashboardWidgetQuery(
  495. widget=widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  496. )
  497. for widget in existing_widgets
  498. )
  499. with self.feature(
  500. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  501. ):
  502. self.page.visit_dashboard_detail()
  503. # Open edit modal for first widget
  504. dropdown_trigger = self.browser.element('[aria-label="Widget actions"]')
  505. dropdown_trigger.click()
  506. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  507. edit_widget_menu_item.click()
  508. # Change the chart type to the first visualization option - Area chart
  509. chart_type_input = self.browser.element("#react-select-2-input")
  510. chart_type_input.send_keys("Area", Keys.ENTER)
  511. button = self.browser.element('[aria-label="Update Widget"]')
  512. button.click()
  513. # No confirm dialog because of shifting lower element
  514. self.page.enter_edit_state()
  515. self.page.click_cancel_button()
  516. wait = WebDriverWait(self.browser.driver, 5)
  517. wait.until_not(EC.alert_is_present())
  518. # Try to decrease height to 1 row, should stay at 2 rows
  519. self.page.enter_edit_state()
  520. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  521. action = ActionChains(self.browser.driver)
  522. action.drag_and_drop_by_offset(resizeHandle, 0, -100).perform()
  523. self.page.save_dashboard()
  524. self.browser.snapshot(
  525. "dashboards - change from big number to area chart increases widget to min height"
  526. )
  527. @pytest.mark.skip(reason="flaky behaviour due to loading spinner")
  528. def test_changing_number_widget_larger_than_min_height_for_area_chart_keeps_height(
  529. self,
  530. ):
  531. existing_widget = DashboardWidget.objects.create(
  532. dashboard=self.dashboard,
  533. order=0,
  534. title="Originally Big Number - 3 rows",
  535. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  536. widget_type=DashboardWidgetTypes.DISCOVER,
  537. interval="1d",
  538. detail={"layout": {"x": 0, "y": 0, "w": 2, "h": 3, "minH": 1}},
  539. )
  540. DashboardWidgetQuery.objects.create(
  541. widget=existing_widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  542. )
  543. with self.feature(
  544. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  545. ):
  546. self.page.visit_dashboard_detail()
  547. # Open edit modal for first widget
  548. dropdown_trigger = self.browser.element('[aria-label="Widget actions"]')
  549. dropdown_trigger.click()
  550. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  551. edit_widget_menu_item.click()
  552. # Change the chart type to the first visualization option - Area chart
  553. chart_type_input = self.browser.element("#react-select-2-input")
  554. chart_type_input.send_keys("Area", Keys.ENTER)
  555. button = self.browser.element('[aria-label="Update Widget"]')
  556. button.click()
  557. self.page.wait_until_loaded()
  558. # This snapshot is flaky due to the loading spinner
  559. self.browser.snapshot(
  560. "dashboards - change from big number to other chart of more than 2 rows keeps height"
  561. )
  562. # Try to decrease height by >1 row, should be at 2 rows
  563. self.page.enter_edit_state()
  564. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  565. action = ActionChains(self.browser.driver)
  566. action.drag_and_drop_by_offset(resizeHandle, 0, -400).perform()
  567. self.page.save_dashboard()
  568. self.browser.snapshot(
  569. "dashboards - change from big number to other chart enforces min height of 2"
  570. )
  571. def test_changing_area_widget_larger_than_min_height_for_number_chart_keeps_height(
  572. self,
  573. ):
  574. existing_widget = DashboardWidget.objects.create(
  575. dashboard=self.dashboard,
  576. order=0,
  577. title="Originally Area Chart - 3 rows",
  578. display_type=DashboardWidgetDisplayTypes.AREA_CHART,
  579. widget_type=DashboardWidgetTypes.DISCOVER,
  580. interval="1d",
  581. detail={"layout": {"x": 0, "y": 0, "w": 2, "h": 3, "minH": 2}},
  582. )
  583. DashboardWidgetQuery.objects.create(
  584. widget=existing_widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  585. )
  586. with self.feature(
  587. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  588. ):
  589. self.page.visit_dashboard_detail()
  590. # Open edit modal for first widget
  591. dropdown_trigger = self.browser.element('[aria-label="Widget actions"]')
  592. dropdown_trigger.click()
  593. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  594. edit_widget_menu_item.click()
  595. # Change the chart type to big number
  596. chart_type_input = self.browser.element("#react-select-2-input")
  597. chart_type_input.send_keys("Big Number", Keys.ENTER)
  598. button = self.browser.element('[aria-label="Update Widget"]')
  599. button.click()
  600. self.page.wait_until_loaded()
  601. self.browser.snapshot("dashboards - change from area chart to big number keeps height")
  602. # Decrease height by >1 row, should stop at 1 row
  603. self.page.enter_edit_state()
  604. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  605. action = ActionChains(self.browser.driver)
  606. action.drag_and_drop_by_offset(resizeHandle, 0, -400).perform()
  607. self.page.save_dashboard()
  608. self.browser.snapshot(
  609. "dashboards - change from area chart to big number allows min height of 1"
  610. )
  611. @region_silo_test
  612. class OrganizationDashboardsManageAcceptanceTest(AcceptanceTestCase):
  613. def setUp(self):
  614. super().setUp()
  615. self.team = self.create_team(organization=self.organization, name="Mariachi Band")
  616. self.project = self.create_project(
  617. organization=self.organization, teams=[self.team], name="Bengal"
  618. )
  619. self.dashboard = Dashboard.objects.create(
  620. title="Dashboard 1", created_by=self.user, organization=self.organization
  621. )
  622. self.widget_1 = DashboardWidget.objects.create(
  623. dashboard=self.dashboard,
  624. order=0,
  625. title="Widget 1",
  626. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  627. widget_type=DashboardWidgetTypes.DISCOVER,
  628. interval="1d",
  629. )
  630. self.widget_2 = DashboardWidget.objects.create(
  631. dashboard=self.dashboard,
  632. order=1,
  633. title="Widget 2",
  634. display_type=DashboardWidgetDisplayTypes.TABLE,
  635. widget_type=DashboardWidgetTypes.DISCOVER,
  636. interval="1d",
  637. )
  638. self.login_as(self.user)
  639. self.default_path = f"/organizations/{self.organization.slug}/dashboards/"
  640. def wait_until_loaded(self):
  641. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  642. self.browser.wait_until_not('[data-test-id="loading-placeholder"]')
  643. def test_dashboard_manager(self):
  644. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  645. self.browser.get(self.default_path)
  646. self.wait_until_loaded()
  647. self.browser.snapshot("dashboards - manage overview")
  648. def test_dashboard_manager_with_unset_layouts_and_defined_layouts(self):
  649. dashboard_with_layouts = Dashboard.objects.create(
  650. title="Dashboard with some defined layouts",
  651. created_by=self.user,
  652. organization=self.organization,
  653. )
  654. DashboardWidget.objects.create(
  655. dashboard=dashboard_with_layouts,
  656. order=0,
  657. title="Widget 1",
  658. display_type=DashboardWidgetDisplayTypes.BAR_CHART,
  659. widget_type=DashboardWidgetTypes.DISCOVER,
  660. interval="1d",
  661. detail={"layout": {"x": 1, "y": 0, "w": 3, "h": 3, "minH": 2}},
  662. )
  663. # This widget has no layout, but should position itself at
  664. # x: 4, y: 0, w: 2, h: 2
  665. DashboardWidget.objects.create(
  666. dashboard=dashboard_with_layouts,
  667. order=1,
  668. title="Widget 2",
  669. display_type=DashboardWidgetDisplayTypes.TABLE,
  670. widget_type=DashboardWidgetTypes.DISCOVER,
  671. interval="1d",
  672. )
  673. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  674. self.browser.get(self.default_path)
  675. self.wait_until_loaded()
  676. self.browser.snapshot("dashboards - manage overview with grid layout")