test_organization_dashboards.py 31 KB

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