test_organization_dashboards.py 37 KB

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