test_organization_dashboards.py 37 KB

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