test_organization_dashboards.py 29 KB

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