test_organization_dashboards.py 28 KB

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