test_organization_dashboards.py 29 KB

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