create.spec.tsx 3.0 KB

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