test_organization_dashboards.py 31 KB

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