test_organization_dashboards.py 30 KB

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