test_organization_dashboards.py 35 KB

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