create.spec.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {mountGlobalModal} from 'sentry-test/modal';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import ProjectsStore from 'sentry/stores/projectsStore';
  5. import CreateDashboard from 'sentry/views/dashboardsV2/create';
  6. describe('Dashboards > Create', function () {
  7. const organization = TestStubs.Organization({
  8. features: [
  9. 'dashboards-basic',
  10. 'dashboards-edit',
  11. 'discover-query',
  12. 'dashboard-grid-layout',
  13. ],
  14. });
  15. describe('new dashboards', function () {
  16. let initialData;
  17. const projects = [TestStubs.Project()];
  18. beforeEach(function () {
  19. ProjectsStore.init();
  20. ProjectsStore.loadInitialData(projects);
  21. initialData = initializeOrg({
  22. organization,
  23. project: undefined,
  24. projects: [],
  25. router: {},
  26. });
  27. MockApiClient.addMockResponse({
  28. url: '/organizations/org-slug/tags/',
  29. body: [],
  30. });
  31. MockApiClient.addMockResponse({
  32. url: '/organizations/org-slug/projects/',
  33. body: [TestStubs.Project()],
  34. });
  35. MockApiClient.addMockResponse({
  36. url: '/organizations/org-slug/dashboards/',
  37. // @ts-ignore
  38. body: [TestStubs.Dashboard([], {id: 'default-overview', title: 'Default'})],
  39. });
  40. MockApiClient.addMockResponse({
  41. url: '/organizations/org-slug/events-stats/',
  42. body: {data: []},
  43. });
  44. MockApiClient.addMockResponse({
  45. url: '/organizations/org-slug/dashboards/widgets/',
  46. method: 'POST',
  47. body: [],
  48. });
  49. MockApiClient.addMockResponse({
  50. url: '/organizations/org-slug/users/',
  51. method: 'GET',
  52. body: [],
  53. });
  54. MockApiClient.addMockResponse({
  55. url: '/organizations/org-slug/eventsv2/',
  56. body: {data: []},
  57. });
  58. });
  59. afterEach(function () {
  60. MockApiClient.clearMockResponses();
  61. ProjectsStore.teardown();
  62. });
  63. // eslint-disable-next-line
  64. it.skip('can create with new widget', async function () {
  65. MockApiClient.addMockResponse({
  66. url: '/organizations/org-slug/dashboards/',
  67. method: 'POST',
  68. // @ts-ignore
  69. body: TestStubs.Dashboard([], {id: '1', title: 'Custom Errors'}),
  70. });
  71. mountGlobalModal(initialData.routerContext);
  72. render(
  73. <CreateDashboard
  74. organization={initialData.organization}
  75. params={{orgId: 'org-slug'}}
  76. router={initialData.router}
  77. location={initialData.router.location}
  78. {...initialData.router}
  79. />,
  80. {context: initialData.routerContext}
  81. );
  82. userEvent.click(await screen.findByTestId('widget-add'));
  83. // Add a custom widget to the dashboard
  84. userEvent.click(await screen.findByText('Custom Widget'));
  85. userEvent.paste(screen.getByTestId('widget-title-input'), 'Widget Title');
  86. userEvent.click(screen.getByText('Save'));
  87. // Committing dashboard should complete without throwing error
  88. userEvent.click(screen.getByText('Save and Finish'));
  89. });
  90. });
  91. });