test_organization_dashboards.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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. @pytest.mark.skip(reason="flaky: DD-1216")
  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):
  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):
  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. @pytest.mark.skip(reason="flaky: DD-1217")
  396. def test_position_when_adding_multiple_widgets_through_add_widget_tile_in_create(
  397. self,
  398. ):
  399. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  400. self.page.visit_create_dashboard()
  401. # Widgets should take up the whole first row and the first spot in second row
  402. self.page.add_widget_through_dashboard("A")
  403. self.page.add_widget_through_dashboard("B")
  404. self.page.add_widget_through_dashboard("C")
  405. self.page.add_widget_through_dashboard("D")
  406. self.page.wait_until_loaded()
  407. self.page.save_dashboard()
  408. # Wait for page redirect, or else loading check passes too early
  409. wait = WebDriverWait(self.browser.driver, 10)
  410. wait.until(
  411. lambda driver: (
  412. f"/organizations/{self.organization.slug}/dashboards/new/"
  413. not in driver.current_url
  414. )
  415. )
  416. self.capture_screenshots(
  417. "dashboards - position when adding multiple widgets through Add Widget tile in create"
  418. )
  419. def test_deleting_stacked_widgets_by_context_menu_does_not_trigger_confirm_on_edit_cancel(
  420. self,
  421. ):
  422. layouts = [
  423. {"x": 0, "y": 0, "w": 2, "h": 2, "minH": 2},
  424. {"x": 0, "y": 2, "w": 2, "h": 2, "minH": 2},
  425. ]
  426. existing_widgets = DashboardWidget.objects.bulk_create(
  427. [
  428. DashboardWidget(
  429. dashboard=self.dashboard,
  430. order=i,
  431. title=f"Existing Widget {i}",
  432. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  433. widget_type=DashboardWidgetTypes.DISCOVER,
  434. interval="1d",
  435. detail={"layout": layout},
  436. )
  437. for i, layout in enumerate(layouts)
  438. ]
  439. )
  440. DashboardWidgetQuery.objects.bulk_create(
  441. DashboardWidgetQuery(
  442. widget=widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  443. )
  444. for widget in existing_widgets
  445. )
  446. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  447. self.page.visit_dashboard_detail()
  448. dropdown_trigger = self.browser.element('[aria-label="Widget actions"]')
  449. dropdown_trigger.click()
  450. delete_widget_menu_item = self.browser.element('[data-test-id="delete-widget"]')
  451. delete_widget_menu_item.click()
  452. confirm_button = self.browser.element('[data-test-id="confirm-button"]')
  453. confirm_button.click()
  454. wait = WebDriverWait(self.browser.driver, 5)
  455. wait.until(
  456. EC.presence_of_element_located(
  457. (By.XPATH, "//*[contains(text(),'Dashboard updated')]")
  458. )
  459. )
  460. # Should not trigger confirm dialog
  461. self.page.enter_edit_state()
  462. self.page.click_cancel_button()
  463. wait.until_not(EC.alert_is_present())
  464. def test_changing_number_widget_to_area_updates_widget_height(
  465. self,
  466. ):
  467. layouts = [
  468. (DashboardWidgetDisplayTypes.BIG_NUMBER, {"x": 0, "y": 0, "w": 2, "h": 1, "minH": 1}),
  469. (DashboardWidgetDisplayTypes.LINE_CHART, {"x": 0, "y": 1, "w": 2, "h": 2, "minH": 2}),
  470. ]
  471. existing_widgets = DashboardWidget.objects.bulk_create(
  472. [
  473. DashboardWidget(
  474. dashboard=self.dashboard,
  475. order=i,
  476. title=f"Widget {i}",
  477. display_type=display_type,
  478. widget_type=DashboardWidgetTypes.DISCOVER,
  479. interval="1d",
  480. detail={"layout": layout},
  481. )
  482. for i, (display_type, layout) in enumerate(layouts)
  483. ]
  484. )
  485. DashboardWidgetQuery.objects.bulk_create(
  486. DashboardWidgetQuery(
  487. widget=widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  488. )
  489. for widget in existing_widgets
  490. )
  491. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  492. self.page.visit_dashboard_detail()
  493. # Open edit modal for first widget
  494. dropdown_trigger = self.browser.element('[aria-label="Widget actions"]')
  495. dropdown_trigger.click()
  496. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  497. edit_widget_menu_item.click()
  498. # Change the chart type to the first visualization option - Area chart
  499. chart_type_input = self.browser.element("#react-select-2-input")
  500. chart_type_input.send_keys("Area", Keys.ENTER)
  501. button = self.browser.element('[aria-label="Update Widget"]')
  502. button.click()
  503. # No confirm dialog because of shifting lower element
  504. self.page.enter_edit_state()
  505. self.page.click_cancel_button()
  506. wait = WebDriverWait(self.browser.driver, 5)
  507. wait.until_not(EC.alert_is_present())
  508. # Try to decrease height to 1 row, should stay at 2 rows
  509. self.page.enter_edit_state()
  510. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  511. action = ActionChains(self.browser.driver)
  512. action.drag_and_drop_by_offset(resizeHandle, 0, -100).perform()
  513. self.page.save_dashboard()
  514. self.browser.snapshot(
  515. "dashboards - change from big number to area chart increases widget to min height"
  516. )
  517. @pytest.mark.skip(reason="flaky behaviour due to loading spinner")
  518. def test_changing_number_widget_larger_than_min_height_for_area_chart_keeps_height(
  519. self,
  520. ):
  521. existing_widget = DashboardWidget.objects.create(
  522. dashboard=self.dashboard,
  523. order=0,
  524. title="Originally Big Number - 3 rows",
  525. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  526. widget_type=DashboardWidgetTypes.DISCOVER,
  527. interval="1d",
  528. detail={"layout": {"x": 0, "y": 0, "w": 2, "h": 3, "minH": 1}},
  529. )
  530. DashboardWidgetQuery.objects.create(
  531. widget=existing_widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  532. )
  533. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  534. self.page.visit_dashboard_detail()
  535. # Open edit modal for first widget
  536. dropdown_trigger = self.browser.element('[aria-label="Widget actions"]')
  537. dropdown_trigger.click()
  538. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  539. edit_widget_menu_item.click()
  540. # Change the chart type to the first visualization option - Area chart
  541. chart_type_input = self.browser.element("#react-select-2-input")
  542. chart_type_input.send_keys("Area", Keys.ENTER)
  543. button = self.browser.element('[aria-label="Update Widget"]')
  544. button.click()
  545. self.page.wait_until_loaded()
  546. # This snapshot is flaky due to the loading spinner
  547. self.browser.snapshot(
  548. "dashboards - change from big number to other chart of more than 2 rows keeps height"
  549. )
  550. # Try to decrease height by >1 row, should be at 2 rows
  551. self.page.enter_edit_state()
  552. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  553. action = ActionChains(self.browser.driver)
  554. action.drag_and_drop_by_offset(resizeHandle, 0, -400).perform()
  555. self.page.save_dashboard()
  556. self.browser.snapshot(
  557. "dashboards - change from big number to other chart enforces min height of 2"
  558. )
  559. @pytest.mark.skip(reason="flaky: DD-1211")
  560. def test_changing_area_widget_larger_than_min_height_for_number_chart_keeps_height(
  561. self,
  562. ):
  563. existing_widget = DashboardWidget.objects.create(
  564. dashboard=self.dashboard,
  565. order=0,
  566. title="Originally Area Chart - 3 rows",
  567. display_type=DashboardWidgetDisplayTypes.AREA_CHART,
  568. widget_type=DashboardWidgetTypes.DISCOVER,
  569. interval="1d",
  570. detail={"layout": {"x": 0, "y": 0, "w": 2, "h": 3, "minH": 2}},
  571. )
  572. DashboardWidgetQuery.objects.create(
  573. widget=existing_widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  574. )
  575. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  576. self.page.visit_dashboard_detail()
  577. # Open edit modal for first widget
  578. dropdown_trigger = self.browser.element('[aria-label="Widget actions"]')
  579. dropdown_trigger.click()
  580. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  581. edit_widget_menu_item.click()
  582. # Change the chart type to big number
  583. chart_type_input = self.browser.element("#react-select-2-input")
  584. chart_type_input.send_keys("Big Number", Keys.ENTER)
  585. button = self.browser.element('[aria-label="Update Widget"]')
  586. button.click()
  587. self.page.wait_until_loaded()
  588. self.browser.snapshot("dashboards - change from area chart to big number keeps height")
  589. # Decrease height by >1 row, should stop at 1 row
  590. self.page.enter_edit_state()
  591. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  592. action = ActionChains(self.browser.driver)
  593. action.drag_and_drop_by_offset(resizeHandle, 0, -400).perform()
  594. self.page.save_dashboard()
  595. self.browser.snapshot(
  596. "dashboards - change from area chart to big number allows min height of 1"
  597. )
  598. @region_silo_test
  599. class OrganizationDashboardsManageAcceptanceTest(AcceptanceTestCase):
  600. def setUp(self):
  601. super().setUp()
  602. self.team = self.create_team(organization=self.organization, name="Mariachi Band")
  603. self.project = self.create_project(
  604. organization=self.organization, teams=[self.team], name="Bengal"
  605. )
  606. self.dashboard = Dashboard.objects.create(
  607. title="Dashboard 1", created_by=self.user, organization=self.organization
  608. )
  609. self.widget_1 = DashboardWidget.objects.create(
  610. dashboard=self.dashboard,
  611. order=0,
  612. title="Widget 1",
  613. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  614. widget_type=DashboardWidgetTypes.DISCOVER,
  615. interval="1d",
  616. )
  617. self.widget_2 = DashboardWidget.objects.create(
  618. dashboard=self.dashboard,
  619. order=1,
  620. title="Widget 2",
  621. display_type=DashboardWidgetDisplayTypes.TABLE,
  622. widget_type=DashboardWidgetTypes.DISCOVER,
  623. interval="1d",
  624. )
  625. self.login_as(self.user)
  626. self.default_path = f"/organizations/{self.organization.slug}/dashboards/"
  627. def wait_until_loaded(self):
  628. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  629. self.browser.wait_until_not('[data-test-id="loading-placeholder"]')
  630. def test_dashboard_manager(self):
  631. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  632. self.browser.get(self.default_path)
  633. self.wait_until_loaded()
  634. self.browser.snapshot("dashboards - manage overview")
  635. def test_dashboard_manager_with_unset_layouts_and_defined_layouts(self):
  636. dashboard_with_layouts = Dashboard.objects.create(
  637. title="Dashboard with some defined layouts",
  638. created_by=self.user,
  639. organization=self.organization,
  640. )
  641. DashboardWidget.objects.create(
  642. dashboard=dashboard_with_layouts,
  643. order=0,
  644. title="Widget 1",
  645. display_type=DashboardWidgetDisplayTypes.BAR_CHART,
  646. widget_type=DashboardWidgetTypes.DISCOVER,
  647. interval="1d",
  648. detail={"layout": {"x": 1, "y": 0, "w": 3, "h": 3, "minH": 2}},
  649. )
  650. # This widget has no layout, but should position itself at
  651. # x: 4, y: 0, w: 2, h: 2
  652. DashboardWidget.objects.create(
  653. dashboard=dashboard_with_layouts,
  654. order=1,
  655. title="Widget 2",
  656. display_type=DashboardWidgetDisplayTypes.TABLE,
  657. widget_type=DashboardWidgetTypes.DISCOVER,
  658. interval="1d",
  659. )
  660. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  661. self.browser.get(self.default_path)
  662. self.wait_until_loaded()
  663. self.browser.snapshot("dashboards - manage overview with grid layout")