test_organization_dashboards.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  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. def test_duplicate_widget_in_view_mode(self):
  305. existing_widget = DashboardWidget.objects.create(
  306. dashboard=self.dashboard,
  307. order=0,
  308. title="Big Number Widget",
  309. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  310. widget_type=DashboardWidgetTypes.DISCOVER,
  311. interval="1d",
  312. )
  313. DashboardWidgetQuery.objects.create(
  314. widget=existing_widget,
  315. fields=["count_unique(issue)"],
  316. columns=[],
  317. aggregates=["count_unique(issue)"],
  318. order=0,
  319. )
  320. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  321. self.page.visit_dashboard_detail()
  322. # Hover over the widget to show widget actions
  323. self.browser.move_to('[aria-label="Widget panel"]')
  324. self.browser.element('[aria-label="Widget actions"]').click()
  325. self.browser.element('[data-test-id="duplicate-widget"]').click()
  326. self.page.wait_until_loaded()
  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. # Should not trigger alert
  331. self.page.enter_edit_state()
  332. self.page.click_cancel_button()
  333. wait = WebDriverWait(self.browser.driver, 5)
  334. wait.until_not(EC.alert_is_present())
  335. def test_delete_widget_in_view_mode(self):
  336. existing_widget = DashboardWidget.objects.create(
  337. dashboard=self.dashboard,
  338. order=0,
  339. title="Big Number Widget",
  340. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  341. widget_type=DashboardWidgetTypes.DISCOVER,
  342. interval="1d",
  343. )
  344. DashboardWidgetQuery.objects.create(
  345. widget=existing_widget,
  346. fields=["count_unique(issue)"],
  347. columns=[],
  348. aggregates=["count_unique(issue)"],
  349. order=0,
  350. )
  351. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  352. self.page.visit_dashboard_detail()
  353. # Hover over the widget to show widget actions
  354. self.browser.move_to('[aria-label="Widget panel"]')
  355. self.browser.element('[aria-label="Widget actions"]').click()
  356. self.browser.element('[data-test-id="delete-widget"]').click()
  357. self.browser.element('[data-test-id="confirm-button"]').click()
  358. self.page.wait_until_loaded()
  359. def test_cancel_without_changes_does_not_trigger_confirm_with_custom_widget_through_header(
  360. self,
  361. ):
  362. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  363. self.page.visit_dashboard_detail()
  364. self.page.click_dashboard_header_add_widget_button()
  365. title_input = self.browser.element(WIDGET_TITLE_FIELD)
  366. title_input.send_keys("New custom widget")
  367. button = self.browser.element('[aria-label="Add Widget"]')
  368. button.click()
  369. self.page.wait_until_loaded()
  370. # Should not trigger confirm dialog
  371. self.page.enter_edit_state()
  372. self.page.click_cancel_button()
  373. wait = WebDriverWait(self.browser.driver, 5)
  374. wait.until_not(EC.alert_is_present())
  375. def test_position_when_adding_multiple_widgets_through_add_widget_tile_in_edit(
  376. self,
  377. ):
  378. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  379. self.page.visit_dashboard_detail()
  380. self.page.enter_edit_state()
  381. # Widgets should take up the whole first row and the first spot in second row
  382. self.page.add_widget_through_dashboard("A")
  383. self.page.add_widget_through_dashboard("B")
  384. self.page.add_widget_through_dashboard("C")
  385. self.page.add_widget_through_dashboard("D")
  386. self.page.wait_until_loaded()
  387. self.page.save_dashboard()
  388. self.capture_screenshots(
  389. "dashboards - position when adding multiple widgets through Add Widget tile in edit"
  390. )
  391. @pytest.mark.skip(reason="flaky: DD-1217")
  392. def test_position_when_adding_multiple_widgets_through_add_widget_tile_in_create(
  393. self,
  394. ):
  395. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  396. self.page.visit_create_dashboard()
  397. # Widgets should take up the whole first row and the first spot in second row
  398. self.page.add_widget_through_dashboard("A")
  399. self.page.add_widget_through_dashboard("B")
  400. self.page.add_widget_through_dashboard("C")
  401. self.page.add_widget_through_dashboard("D")
  402. self.page.wait_until_loaded()
  403. self.page.save_dashboard()
  404. # Wait for page redirect, or else loading check passes too early
  405. wait = WebDriverWait(self.browser.driver, 10)
  406. wait.until(
  407. lambda driver: (
  408. f"/organizations/{self.organization.slug}/dashboards/new/"
  409. not in driver.current_url
  410. )
  411. )
  412. self.capture_screenshots(
  413. "dashboards - position when adding multiple widgets through Add Widget tile in create"
  414. )
  415. def test_deleting_stacked_widgets_by_context_menu_does_not_trigger_confirm_on_edit_cancel(
  416. self,
  417. ):
  418. layouts = [
  419. {"x": 0, "y": 0, "w": 2, "h": 2, "minH": 2},
  420. {"x": 0, "y": 2, "w": 2, "h": 2, "minH": 2},
  421. ]
  422. existing_widgets = DashboardWidget.objects.bulk_create(
  423. [
  424. DashboardWidget(
  425. dashboard=self.dashboard,
  426. order=i,
  427. title=f"Existing Widget {i}",
  428. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  429. widget_type=DashboardWidgetTypes.DISCOVER,
  430. interval="1d",
  431. detail={"layout": layout},
  432. )
  433. for i, layout in enumerate(layouts)
  434. ]
  435. )
  436. DashboardWidgetQuery.objects.bulk_create(
  437. DashboardWidgetQuery(
  438. widget=widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  439. )
  440. for widget in existing_widgets
  441. )
  442. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  443. self.page.visit_dashboard_detail()
  444. # Hover over the widget to show widget actions
  445. self.browser.move_to('[aria-label="Widget panel"]')
  446. dropdown_trigger = self.browser.element('[aria-label="Widget actions"]')
  447. dropdown_trigger.click()
  448. delete_widget_menu_item = self.browser.element('[data-test-id="delete-widget"]')
  449. delete_widget_menu_item.click()
  450. confirm_button = self.browser.element('[data-test-id="confirm-button"]')
  451. confirm_button.click()
  452. wait = WebDriverWait(self.browser.driver, 5)
  453. wait.until(
  454. EC.presence_of_element_located(
  455. (By.XPATH, "//*[contains(text(),'Dashboard updated')]")
  456. )
  457. )
  458. # Should not trigger confirm dialog
  459. self.page.enter_edit_state()
  460. self.page.click_cancel_button()
  461. wait.until_not(EC.alert_is_present())
  462. def test_changing_number_widget_to_area_updates_widget_height(
  463. self,
  464. ):
  465. layouts = [
  466. (DashboardWidgetDisplayTypes.BIG_NUMBER, {"x": 0, "y": 0, "w": 2, "h": 1, "minH": 1}),
  467. (DashboardWidgetDisplayTypes.LINE_CHART, {"x": 0, "y": 1, "w": 2, "h": 2, "minH": 2}),
  468. ]
  469. existing_widgets = DashboardWidget.objects.bulk_create(
  470. [
  471. DashboardWidget(
  472. dashboard=self.dashboard,
  473. order=i,
  474. title=f"Widget {i}",
  475. display_type=display_type,
  476. widget_type=DashboardWidgetTypes.DISCOVER,
  477. interval="1d",
  478. detail={"layout": layout},
  479. )
  480. for i, (display_type, layout) in enumerate(layouts)
  481. ]
  482. )
  483. DashboardWidgetQuery.objects.bulk_create(
  484. DashboardWidgetQuery(
  485. widget=widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  486. )
  487. for widget in existing_widgets
  488. )
  489. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  490. self.page.visit_dashboard_detail()
  491. # Hover over the widget to show widget actions
  492. self.browser.move_to('[aria-label="Widget panel"]')
  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. @pytest.mark.skip(reason="flaky behaviour due to loading spinner")
  515. def test_changing_number_widget_larger_than_min_height_for_area_chart_keeps_height(
  516. self,
  517. ):
  518. existing_widget = DashboardWidget.objects.create(
  519. dashboard=self.dashboard,
  520. order=0,
  521. title="Originally Big Number - 3 rows",
  522. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  523. widget_type=DashboardWidgetTypes.DISCOVER,
  524. interval="1d",
  525. detail={"layout": {"x": 0, "y": 0, "w": 2, "h": 3, "minH": 1}},
  526. )
  527. DashboardWidgetQuery.objects.create(
  528. widget=existing_widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  529. )
  530. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  531. self.page.visit_dashboard_detail()
  532. # Open edit modal for first widget
  533. dropdown_trigger = self.browser.element('[aria-label="Widget actions"]')
  534. dropdown_trigger.click()
  535. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  536. edit_widget_menu_item.click()
  537. # Change the chart type to the first visualization option - Area chart
  538. chart_type_input = self.browser.element("#react-select-2-input")
  539. chart_type_input.send_keys("Area", Keys.ENTER)
  540. button = self.browser.element('[aria-label="Update Widget"]')
  541. button.click()
  542. self.page.wait_until_loaded()
  543. # Try to decrease height by >1 row, should be at 2 rows
  544. self.page.enter_edit_state()
  545. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  546. action = ActionChains(self.browser.driver)
  547. action.drag_and_drop_by_offset(resizeHandle, 0, -400).perform()
  548. self.page.save_dashboard()
  549. @pytest.mark.skip(reason="flaky: DD-1211")
  550. def test_changing_area_widget_larger_than_min_height_for_number_chart_keeps_height(
  551. self,
  552. ):
  553. existing_widget = DashboardWidget.objects.create(
  554. dashboard=self.dashboard,
  555. order=0,
  556. title="Originally Area Chart - 3 rows",
  557. display_type=DashboardWidgetDisplayTypes.AREA_CHART,
  558. widget_type=DashboardWidgetTypes.DISCOVER,
  559. interval="1d",
  560. detail={"layout": {"x": 0, "y": 0, "w": 2, "h": 3, "minH": 2}},
  561. )
  562. DashboardWidgetQuery.objects.create(
  563. widget=existing_widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  564. )
  565. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  566. self.page.visit_dashboard_detail()
  567. # Open edit modal for first widget
  568. dropdown_trigger = self.browser.element('[aria-label="Widget actions"]')
  569. dropdown_trigger.click()
  570. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  571. edit_widget_menu_item.click()
  572. # Change the chart type to big number
  573. chart_type_input = self.browser.element("#react-select-2-input")
  574. chart_type_input.send_keys("Big Number", Keys.ENTER)
  575. button = self.browser.element('[aria-label="Update Widget"]')
  576. button.click()
  577. self.page.wait_until_loaded()
  578. # Decrease height by >1 row, should stop at 1 row
  579. self.page.enter_edit_state()
  580. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  581. action = ActionChains(self.browser.driver)
  582. action.drag_and_drop_by_offset(resizeHandle, 0, -400).perform()
  583. self.page.save_dashboard()
  584. @no_silo_test
  585. class OrganizationDashboardsManageAcceptanceTest(AcceptanceTestCase):
  586. def setUp(self):
  587. super().setUp()
  588. self.team = self.create_team(organization=self.organization, name="Mariachi Band")
  589. self.project = self.create_project(
  590. organization=self.organization, teams=[self.team], name="Bengal"
  591. )
  592. self.dashboard = Dashboard.objects.create(
  593. title="Dashboard 1", created_by_id=self.user.id, organization=self.organization
  594. )
  595. self.widget_1 = DashboardWidget.objects.create(
  596. dashboard=self.dashboard,
  597. order=0,
  598. title="Widget 1",
  599. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  600. widget_type=DashboardWidgetTypes.DISCOVER,
  601. interval="1d",
  602. )
  603. self.widget_2 = DashboardWidget.objects.create(
  604. dashboard=self.dashboard,
  605. order=1,
  606. title="Widget 2",
  607. display_type=DashboardWidgetDisplayTypes.TABLE,
  608. widget_type=DashboardWidgetTypes.DISCOVER,
  609. interval="1d",
  610. )
  611. self.login_as(self.user)
  612. self.default_path = f"/organizations/{self.organization.slug}/dashboards/"
  613. def wait_until_loaded(self):
  614. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  615. self.browser.wait_until_not('[data-test-id="loading-placeholder"]')
  616. def test_dashboard_manager(self):
  617. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  618. self.browser.get(self.default_path)
  619. self.wait_until_loaded()
  620. def test_dashboard_manager_with_unset_layouts_and_defined_layouts(self):
  621. dashboard_with_layouts = Dashboard.objects.create(
  622. title="Dashboard with some defined layouts",
  623. created_by_id=self.user.id,
  624. organization=self.organization,
  625. )
  626. DashboardWidget.objects.create(
  627. dashboard=dashboard_with_layouts,
  628. order=0,
  629. title="Widget 1",
  630. display_type=DashboardWidgetDisplayTypes.BAR_CHART,
  631. widget_type=DashboardWidgetTypes.DISCOVER,
  632. interval="1d",
  633. detail={"layout": {"x": 1, "y": 0, "w": 3, "h": 3, "minH": 2}},
  634. )
  635. # This widget has no layout, but should position itself at
  636. # x: 4, y: 0, w: 2, h: 2
  637. DashboardWidget.objects.create(
  638. dashboard=dashboard_with_layouts,
  639. order=1,
  640. title="Widget 2",
  641. display_type=DashboardWidgetDisplayTypes.TABLE,
  642. widget_type=DashboardWidgetTypes.DISCOVER,
  643. interval="1d",
  644. )
  645. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  646. self.browser.get(self.default_path)
  647. self.wait_until_loaded()