test_organization_dashboards.py 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  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.send_keys(Keys.END, "UPDATED!!")
  238. button = self.browser.element('[data-test-id="add-widget"]')
  239. button.click()
  240. # Add and drag new widget to the right
  241. self.page.add_widget_through_dashboard("New Widget")
  242. dragHandle = self.browser.element(
  243. f".react-grid-item:nth-of-type(2) {WIDGET_DRAG_HANDLE}"
  244. )
  245. action = ActionChains(self.browser.driver)
  246. action.drag_and_drop_by_offset(dragHandle, 1000, 0)
  247. action.perform()
  248. # Edit the new widget
  249. button = self.browser.element(f".react-grid-item:nth-of-type(2) {EDIT_WIDGET_BUTTON}")
  250. button.click()
  251. title_input = self.browser.element(WIDGET_TITLE_FIELD)
  252. title_input.send_keys(Keys.END, "UPDATED!!")
  253. button = self.browser.element('[data-test-id="add-widget"]')
  254. button.click()
  255. self.page.save_dashboard()
  256. self.capture_screenshots(
  257. "dashboards - edit widgets after layout change does not reset layout"
  258. )
  259. def test_add_issue_widgets_do_not_overlap(self):
  260. def add_issue_widget(widget_title):
  261. self.browser.wait_until_clickable('[data-test-id="widget-add"]')
  262. self.page.click_dashboard_add_widget_button()
  263. title_input = self.browser.element(WIDGET_TITLE_FIELD)
  264. title_input.send_keys(widget_title)
  265. self.browser.element(
  266. '[aria-label="Select Issues (States, Assignment, Time, etc.)"]'
  267. ).click()
  268. button = self.browser.element('[data-test-id="add-widget"]')
  269. button.click()
  270. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  271. self.page.visit_dashboard_detail()
  272. self.page.enter_edit_state()
  273. add_issue_widget("Issue Widget 1")
  274. add_issue_widget("Issue Widget 2")
  275. self.page.save_dashboard()
  276. self.capture_screenshots("dashboards - issue widgets do not overlap")
  277. def test_resize_new_and_existing_widgets(self):
  278. existing_widget = DashboardWidget.objects.create(
  279. dashboard=self.dashboard,
  280. order=0,
  281. title="Existing Widget",
  282. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  283. widget_type=DashboardWidgetTypes.DISCOVER,
  284. interval="1d",
  285. )
  286. DashboardWidgetQuery.objects.create(
  287. widget=existing_widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  288. )
  289. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  290. self.page.visit_dashboard_detail()
  291. self.page.enter_edit_state()
  292. # Resize existing widget
  293. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  294. action = ActionChains(self.browser.driver)
  295. action.drag_and_drop_by_offset(resizeHandle, 500, 0).perform()
  296. self.page.add_widget_through_dashboard("New Widget")
  297. # Drag it to the left for consistency
  298. dragHandle = self.browser.element(
  299. f".react-grid-item:nth-of-type(2) {WIDGET_DRAG_HANDLE}"
  300. )
  301. action = ActionChains(self.browser.driver)
  302. action.drag_and_drop_by_offset(dragHandle, -1000, 0).perform()
  303. # Resize new widget, get the 2nd element instead of the "last" because the "last" is
  304. # the add widget button
  305. resizeHandle = self.browser.element(
  306. f".react-grid-item:nth-of-type(2) {WIDGET_RESIZE_HANDLE}"
  307. )
  308. action = ActionChains(self.browser.driver)
  309. action.drag_and_drop_by_offset(resizeHandle, 500, 0).perform()
  310. self.page.save_dashboard()
  311. self.capture_screenshots("dashboards - resize new and existing widgets")
  312. def test_delete_existing_widget_does_not_trigger_new_widget_layout_reset(self):
  313. existing_widget = DashboardWidget.objects.create(
  314. dashboard=self.dashboard,
  315. order=0,
  316. title="Existing Widget",
  317. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  318. widget_type=DashboardWidgetTypes.DISCOVER,
  319. interval="1d",
  320. )
  321. DashboardWidgetQuery.objects.create(
  322. widget=existing_widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  323. )
  324. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  325. self.page.visit_dashboard_detail()
  326. self.page.enter_edit_state()
  327. self.page.add_widget_through_dashboard("New Widget")
  328. # Drag it to the bottom left
  329. dragHandle = self.browser.element(
  330. f".react-grid-item:nth-of-type(2) {WIDGET_DRAG_HANDLE}"
  331. )
  332. action = ActionChains(self.browser.driver)
  333. action.drag_and_drop_by_offset(dragHandle, -500, 500).perform()
  334. # Resize new widget, get the 2nd element instead of the "last" because the "last" is
  335. # the add widget button
  336. resizeHandle = self.browser.element(
  337. f".react-grid-item:nth-of-type(2) {WIDGET_RESIZE_HANDLE}"
  338. )
  339. action = ActionChains(self.browser.driver)
  340. action.drag_and_drop_by_offset(resizeHandle, 500, 0).perform()
  341. # Delete first existing widget
  342. delete_widget_button = self.browser.element(
  343. '.react-grid-item:first-of-type [data-test-id="widget-delete"]'
  344. )
  345. delete_widget_button.click()
  346. self.page.save_dashboard()
  347. self.capture_screenshots(
  348. "dashboards - delete existing widget does not reset new widget layout"
  349. )
  350. def test_resize_big_number_widget(self):
  351. existing_widget = DashboardWidget.objects.create(
  352. dashboard=self.dashboard,
  353. order=0,
  354. title="Big Number Widget",
  355. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  356. widget_type=DashboardWidgetTypes.DISCOVER,
  357. interval="1d",
  358. )
  359. DashboardWidgetQuery.objects.create(
  360. widget=existing_widget,
  361. fields=["count_unique(issue)"],
  362. columns=[],
  363. aggregates=["count_unique(issue)"],
  364. order=0,
  365. )
  366. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  367. self.page.visit_dashboard_detail()
  368. self.page.enter_edit_state()
  369. # Resize existing widget
  370. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  371. action = ActionChains(self.browser.driver)
  372. action.drag_and_drop_by_offset(resizeHandle, 200, 200).perform()
  373. self.page.save_dashboard()
  374. self.capture_screenshots("dashboards - resize big number widget")
  375. def test_default_layout_when_widgets_do_not_have_layout_set(self):
  376. existing_widgets = DashboardWidget.objects.bulk_create(
  377. [
  378. DashboardWidget(
  379. dashboard=self.dashboard,
  380. order=i,
  381. title=f"Existing Widget {i}",
  382. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  383. widget_type=DashboardWidgetTypes.DISCOVER,
  384. interval="1d",
  385. )
  386. for i in range(4)
  387. ]
  388. )
  389. DashboardWidgetQuery.objects.bulk_create(
  390. [
  391. DashboardWidgetQuery(
  392. widget=existing_widget,
  393. fields=["count()"],
  394. columns=[],
  395. aggregates=["count()"],
  396. order=0,
  397. )
  398. for existing_widget in existing_widgets
  399. ]
  400. )
  401. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  402. self.page.visit_dashboard_detail()
  403. self.page.wait_until_loaded()
  404. self.browser.snapshot("dashboards - default layout when widgets do not have layout set")
  405. def test_duplicate_widget_in_view_mode(self):
  406. existing_widget = DashboardWidget.objects.create(
  407. dashboard=self.dashboard,
  408. order=0,
  409. title="Big Number Widget",
  410. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  411. widget_type=DashboardWidgetTypes.DISCOVER,
  412. interval="1d",
  413. )
  414. DashboardWidgetQuery.objects.create(
  415. widget=existing_widget,
  416. fields=["count_unique(issue)"],
  417. columns=[],
  418. aggregates=["count_unique(issue)"],
  419. order=0,
  420. )
  421. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  422. self.page.visit_dashboard_detail()
  423. self.browser.element('[aria-haspopup="true"]').click()
  424. self.browser.element('[data-test-id="duplicate-widget"]').click()
  425. self.page.wait_until_loaded()
  426. self.browser.element('[aria-haspopup="true"]').click()
  427. self.browser.element('[data-test-id="duplicate-widget"]').click()
  428. self.page.wait_until_loaded()
  429. # Should not trigger alert
  430. self.page.enter_edit_state()
  431. self.page.click_cancel_button()
  432. wait = WebDriverWait(self.browser.driver, 5)
  433. wait.until_not(EC.alert_is_present())
  434. self.browser.snapshot("dashboard widget - duplicate with grid")
  435. def test_delete_widget_in_view_mode(self):
  436. existing_widget = DashboardWidget.objects.create(
  437. dashboard=self.dashboard,
  438. order=0,
  439. title="Big Number Widget",
  440. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  441. widget_type=DashboardWidgetTypes.DISCOVER,
  442. interval="1d",
  443. )
  444. DashboardWidgetQuery.objects.create(
  445. widget=existing_widget,
  446. fields=["count_unique(issue)"],
  447. columns=[],
  448. aggregates=["count_unique(issue)"],
  449. order=0,
  450. )
  451. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  452. self.page.visit_dashboard_detail()
  453. self.browser.element('[aria-haspopup="true"]').click()
  454. self.browser.element('[data-test-id="delete-widget"]').click()
  455. self.browser.element('[data-test-id="confirm-button"]').click()
  456. self.page.wait_until_loaded()
  457. self.browser.snapshot("dashboard widget - delete with grid")
  458. def test_cancel_without_changes_does_not_trigger_confirm_with_widget_library_through_header(
  459. self,
  460. ):
  461. with self.feature(
  462. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  463. ):
  464. self.page.visit_dashboard_detail()
  465. # Open widget library
  466. self.page.click_dashboard_header_add_widget_button()
  467. self.browser.element('[data-test-id="library-tab"]').click()
  468. # Select/deselect widget library cards
  469. self.browser.element('[data-test-id="widget-library-card-0"]').click()
  470. self.browser.element('[data-test-id="widget-library-card-2"]').click()
  471. # Save widget library selections
  472. button = self.browser.element('[data-test-id="confirm-widgets"]')
  473. button.click()
  474. self.page.wait_until_loaded()
  475. # Should not trigger alert
  476. self.page.enter_edit_state()
  477. self.page.click_cancel_button()
  478. wait = WebDriverWait(self.browser.driver, 5)
  479. wait.until_not(EC.alert_is_present())
  480. def test_cancel_without_changes_does_not_trigger_confirm_with_custom_widget_through_header(
  481. self,
  482. ):
  483. with self.feature(
  484. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  485. ):
  486. self.page.visit_dashboard_detail()
  487. self.page.click_dashboard_header_add_widget_button()
  488. title_input = self.browser.element(WIDGET_TITLE_FIELD)
  489. title_input.send_keys("New custom widget")
  490. button = self.browser.element('[data-test-id="add-widget"]')
  491. button.click()
  492. self.page.wait_until_loaded()
  493. # Should not trigger confirm dialog
  494. self.page.enter_edit_state()
  495. self.page.click_cancel_button()
  496. wait = WebDriverWait(self.browser.driver, 5)
  497. wait.until_not(EC.alert_is_present())
  498. def test_position_when_adding_multiple_widgets_through_add_widget_tile_in_edit(
  499. self,
  500. ):
  501. with self.feature(
  502. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  503. ):
  504. self.page.visit_dashboard_detail()
  505. self.page.enter_edit_state()
  506. # Widgets should take up the whole first row and the first spot in second row
  507. self.page.add_widget_through_dashboard("A")
  508. self.page.add_widget_through_dashboard("B")
  509. self.page.add_widget_through_dashboard("C")
  510. self.page.add_widget_through_dashboard("D")
  511. self.page.wait_until_loaded()
  512. self.page.save_dashboard()
  513. self.capture_screenshots(
  514. "dashboards - position when adding multiple widgets through Add Widget tile in edit"
  515. )
  516. def test_position_when_adding_multiple_widgets_through_add_widget_tile_in_create(
  517. self,
  518. ):
  519. with self.feature(
  520. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  521. ):
  522. self.page.visit_create_dashboard()
  523. # Widgets should take up the whole first row and the first spot in second row
  524. self.page.add_widget_through_dashboard("A")
  525. self.page.add_widget_through_dashboard("B")
  526. self.page.add_widget_through_dashboard("C")
  527. self.page.add_widget_through_dashboard("D")
  528. self.page.wait_until_loaded()
  529. self.page.save_dashboard()
  530. # Wait for page redirect, or else loading check passes too early
  531. wait = WebDriverWait(self.browser.driver, 10)
  532. wait.until(
  533. lambda driver: (
  534. f"/organizations/{self.organization.slug}/dashboards/new/"
  535. not in driver.current_url
  536. )
  537. )
  538. self.capture_screenshots(
  539. "dashboards - position when adding multiple widgets through Add Widget tile in create"
  540. )
  541. def test_deleting_stacked_widgets_by_context_menu_does_not_trigger_confirm_on_edit_cancel(
  542. self,
  543. ):
  544. layouts = [
  545. {"x": 0, "y": 0, "w": 2, "h": 2, "minH": 2},
  546. {"x": 0, "y": 2, "w": 2, "h": 2, "minH": 2},
  547. ]
  548. existing_widgets = DashboardWidget.objects.bulk_create(
  549. [
  550. DashboardWidget(
  551. dashboard=self.dashboard,
  552. order=i,
  553. title=f"Existing Widget {i}",
  554. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  555. widget_type=DashboardWidgetTypes.DISCOVER,
  556. interval="1d",
  557. detail={"layout": layout},
  558. )
  559. for i, layout in enumerate(layouts)
  560. ]
  561. )
  562. DashboardWidgetQuery.objects.bulk_create(
  563. DashboardWidgetQuery(
  564. widget=widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  565. )
  566. for widget in existing_widgets
  567. )
  568. with self.feature(
  569. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  570. ):
  571. self.page.visit_dashboard_detail()
  572. dropdown_trigger = self.browser.element('[aria-haspopup="true"]')
  573. dropdown_trigger.click()
  574. delete_widget_menu_item = self.browser.element('[data-test-id="delete-widget"]')
  575. delete_widget_menu_item.click()
  576. confirm_button = self.browser.element('[data-test-id="confirm-button"]')
  577. confirm_button.click()
  578. wait = WebDriverWait(self.browser.driver, 5)
  579. wait.until(
  580. EC.presence_of_element_located(
  581. (By.XPATH, "//*[contains(text(),'Dashboard updated')]")
  582. )
  583. )
  584. # Should not trigger confirm dialog
  585. self.page.enter_edit_state()
  586. self.page.click_cancel_button()
  587. wait.until_not(EC.alert_is_present())
  588. def test_changing_number_widget_to_area_updates_widget_height(
  589. self,
  590. ):
  591. layouts = [
  592. (DashboardWidgetDisplayTypes.BIG_NUMBER, {"x": 0, "y": 0, "w": 2, "h": 1, "minH": 1}),
  593. (DashboardWidgetDisplayTypes.LINE_CHART, {"x": 0, "y": 1, "w": 2, "h": 2, "minH": 2}),
  594. ]
  595. existing_widgets = DashboardWidget.objects.bulk_create(
  596. [
  597. DashboardWidget(
  598. dashboard=self.dashboard,
  599. order=i,
  600. title=f"Widget {i}",
  601. display_type=display_type,
  602. widget_type=DashboardWidgetTypes.DISCOVER,
  603. interval="1d",
  604. detail={"layout": layout},
  605. )
  606. for i, (display_type, layout) in enumerate(layouts)
  607. ]
  608. )
  609. DashboardWidgetQuery.objects.bulk_create(
  610. DashboardWidgetQuery(
  611. widget=widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  612. )
  613. for widget in existing_widgets
  614. )
  615. with self.feature(
  616. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  617. ):
  618. self.page.visit_dashboard_detail()
  619. # Open edit modal for first widget
  620. dropdown_trigger = self.browser.element('[aria-haspopup="true"]')
  621. dropdown_trigger.click()
  622. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  623. edit_widget_menu_item.click()
  624. # Change the chart type to the first visualization option - Area chart
  625. chart_type_input = self.browser.element("#react-select-2-input")
  626. chart_type_input.send_keys("Area", Keys.ENTER)
  627. button = self.browser.element('[data-test-id="add-widget"]')
  628. button.click()
  629. # No confirm dialog because of shifting lower element
  630. self.page.enter_edit_state()
  631. self.page.click_cancel_button()
  632. wait = WebDriverWait(self.browser.driver, 5)
  633. wait.until_not(EC.alert_is_present())
  634. # Try to decrease height to 1 row, should stay at 2 rows
  635. self.page.enter_edit_state()
  636. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  637. action = ActionChains(self.browser.driver)
  638. action.drag_and_drop_by_offset(resizeHandle, 0, -100).perform()
  639. self.page.save_dashboard()
  640. self.browser.snapshot(
  641. "dashboards - change from big number to area chart increases widget to min height"
  642. )
  643. def test_changing_number_widget_larger_than_min_height_for_area_chart_keeps_height(
  644. self,
  645. ):
  646. existing_widget = DashboardWidget.objects.create(
  647. dashboard=self.dashboard,
  648. order=0,
  649. title="Originally Big Number - 3 rows",
  650. display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
  651. widget_type=DashboardWidgetTypes.DISCOVER,
  652. interval="1d",
  653. detail={"layout": {"x": 0, "y": 0, "w": 2, "h": 3, "minH": 1}},
  654. )
  655. DashboardWidgetQuery.objects.create(
  656. widget=existing_widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  657. )
  658. with self.feature(
  659. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  660. ):
  661. self.page.visit_dashboard_detail()
  662. # Open edit modal for first widget
  663. dropdown_trigger = self.browser.element('[aria-haspopup="true"]')
  664. dropdown_trigger.click()
  665. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  666. edit_widget_menu_item.click()
  667. # Change the chart type to the first visualization option - Area chart
  668. chart_type_input = self.browser.element("#react-select-2-input")
  669. chart_type_input.send_keys("Area", Keys.ENTER)
  670. button = self.browser.element('[data-test-id="add-widget"]')
  671. button.click()
  672. self.page.wait_until_loaded()
  673. self.browser.snapshot(
  674. "dashboards - change from big number to other chart of more than 2 rows keeps height"
  675. )
  676. # Try to decrease height by >1 row, should be at 2 rows
  677. self.page.enter_edit_state()
  678. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  679. action = ActionChains(self.browser.driver)
  680. action.drag_and_drop_by_offset(resizeHandle, 0, -400).perform()
  681. self.page.save_dashboard()
  682. self.browser.snapshot(
  683. "dashboards - change from big number to other chart enforces min height of 2"
  684. )
  685. def test_changing_area_widget_larger_than_min_height_for_number_chart_keeps_height(
  686. self,
  687. ):
  688. existing_widget = DashboardWidget.objects.create(
  689. dashboard=self.dashboard,
  690. order=0,
  691. title="Originally Area Chart - 3 rows",
  692. display_type=DashboardWidgetDisplayTypes.AREA_CHART,
  693. widget_type=DashboardWidgetTypes.DISCOVER,
  694. interval="1d",
  695. detail={"layout": {"x": 0, "y": 0, "w": 2, "h": 3, "minH": 2}},
  696. )
  697. DashboardWidgetQuery.objects.create(
  698. widget=existing_widget, fields=["count()"], columns=[], aggregates=["count()"], order=0
  699. )
  700. with self.feature(
  701. FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE + WIDGET_LIBRARY_FEATURE
  702. ):
  703. self.page.visit_dashboard_detail()
  704. # Open edit modal for first widget
  705. dropdown_trigger = self.browser.element('[aria-haspopup="true"]')
  706. dropdown_trigger.click()
  707. edit_widget_menu_item = self.browser.element('[data-test-id="edit-widget"]')
  708. edit_widget_menu_item.click()
  709. # Change the chart type to big number
  710. chart_type_input = self.browser.element("#react-select-2-input")
  711. chart_type_input.send_keys("Big Number", Keys.ENTER)
  712. button = self.browser.element('[data-test-id="add-widget"]')
  713. button.click()
  714. self.page.wait_until_loaded()
  715. self.browser.snapshot("dashboards - change from area chart to big number keeps height")
  716. # Decrease height by >1 row, should stop at 1 row
  717. self.page.enter_edit_state()
  718. resizeHandle = self.browser.element(WIDGET_RESIZE_HANDLE)
  719. action = ActionChains(self.browser.driver)
  720. action.drag_and_drop_by_offset(resizeHandle, 0, -400).perform()
  721. self.page.save_dashboard()
  722. self.browser.snapshot(
  723. "dashboards - change from area chart to big number allows min height of 1"
  724. )
  725. class OrganizationDashboardsManageAcceptanceTest(AcceptanceTestCase):
  726. def setUp(self):
  727. super().setUp()
  728. self.team = self.create_team(organization=self.organization, name="Mariachi Band")
  729. self.project = self.create_project(
  730. organization=self.organization, teams=[self.team], name="Bengal"
  731. )
  732. self.dashboard = Dashboard.objects.create(
  733. title="Dashboard 1", created_by=self.user, organization=self.organization
  734. )
  735. self.widget_1 = DashboardWidget.objects.create(
  736. dashboard=self.dashboard,
  737. order=0,
  738. title="Widget 1",
  739. display_type=DashboardWidgetDisplayTypes.LINE_CHART,
  740. widget_type=DashboardWidgetTypes.DISCOVER,
  741. interval="1d",
  742. )
  743. self.widget_2 = DashboardWidget.objects.create(
  744. dashboard=self.dashboard,
  745. order=1,
  746. title="Widget 2",
  747. display_type=DashboardWidgetDisplayTypes.TABLE,
  748. widget_type=DashboardWidgetTypes.DISCOVER,
  749. interval="1d",
  750. )
  751. self.login_as(self.user)
  752. self.default_path = f"/organizations/{self.organization.slug}/dashboards/"
  753. def wait_until_loaded(self):
  754. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  755. self.browser.wait_until_not('[data-test-id="loading-placeholder"]')
  756. def test_dashboard_manager(self):
  757. with self.feature(FEATURE_NAMES + EDIT_FEATURE):
  758. self.browser.get(self.default_path)
  759. self.wait_until_loaded()
  760. self.browser.snapshot("dashboards - manage overview")
  761. def test_dashboard_manager_with_unset_layouts_and_defined_layouts(self):
  762. dashboard_with_layouts = Dashboard.objects.create(
  763. title="Dashboard with some defined layouts",
  764. created_by=self.user,
  765. organization=self.organization,
  766. )
  767. DashboardWidget.objects.create(
  768. dashboard=dashboard_with_layouts,
  769. order=0,
  770. title="Widget 1",
  771. display_type=DashboardWidgetDisplayTypes.BAR_CHART,
  772. widget_type=DashboardWidgetTypes.DISCOVER,
  773. interval="1d",
  774. detail={"layout": {"x": 1, "y": 0, "w": 3, "h": 3, "minH": 2}},
  775. )
  776. # This widget has no layout, but should position itself at
  777. # x: 4, y: 0, w: 2, h: 2
  778. DashboardWidget.objects.create(
  779. dashboard=dashboard_with_layouts,
  780. order=1,
  781. title="Widget 2",
  782. display_type=DashboardWidgetDisplayTypes.TABLE,
  783. widget_type=DashboardWidgetTypes.DISCOVER,
  784. interval="1d",
  785. )
  786. with self.feature(FEATURE_NAMES + EDIT_FEATURE + GRID_LAYOUT_FEATURE):
  787. self.browser.get(self.default_path)
  788. self.wait_until_loaded()
  789. self.browser.snapshot("dashboards - manage overview with grid layout")