test_organization_dashboards.py 31 KB

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