create.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. });
  62. // eslint-disable-next-line
  63. it.skip('can create with new widget', async function () {
  64. MockApiClient.addMockResponse({
  65. url: '/organizations/org-slug/dashboards/',
  66. method: 'POST',
  67. // @ts-ignore
  68. body: TestStubs.Dashboard([], {id: '1', title: 'Custom Errors'}),
  69. });
  70. mountGlobalModal(initialData.routerContext);
  71. render(
  72. <CreateDashboard
  73. organization={initialData.organization}
  74. params={{orgId: 'org-slug'}}
  75. router={initialData.router}
  76. location={initialData.router.location}
  77. {...initialData.router}
  78. />,
  79. {context: initialData.routerContext}
  80. );
  81. userEvent.click(await screen.findByTestId('widget-add'));
  82. // Add a custom widget to the dashboard
  83. userEvent.click(await screen.findByText('Custom Widget'));
  84. userEvent.paste(screen.getByTestId('widget-title-input'), 'Widget Title');
  85. userEvent.click(screen.getByText('Save'));
  86. // Committing dashboard should complete without throwing error
  87. userEvent.click(screen.getByText('Save and Finish'));
  88. });
  89. });
  90. });