settings.spec.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {WebhookPluginConfigFixture} from 'sentry-fixture/integrationListDirectory';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import ProjectAlertSettings from 'sentry/views/settings/projectAlerts/settings';
  6. describe('ProjectAlertSettings', () => {
  7. // 12 minutes
  8. const digestsMinDelay = 12 * 60;
  9. // 55 minutes
  10. const digestsMaxDelay = 55 * 60;
  11. const project = ProjectFixture({
  12. digestsMinDelay,
  13. digestsMaxDelay,
  14. });
  15. const {organization, routerProps} = initializeOrg({
  16. project,
  17. router: {
  18. params: {projectId: project.slug},
  19. },
  20. });
  21. beforeEach(() => {
  22. MockApiClient.addMockResponse({
  23. url: `/projects/${organization.slug}/${project.slug}/`,
  24. method: 'GET',
  25. body: project,
  26. });
  27. MockApiClient.addMockResponse({
  28. url: `/projects/${organization.slug}/${project.slug}/plugins/`,
  29. method: 'GET',
  30. body: [],
  31. });
  32. });
  33. it('renders', async () => {
  34. render(<ProjectAlertSettings canEditRule {...routerProps} />);
  35. expect(
  36. await screen.findByPlaceholderText('e.g. $shortID - $title')
  37. ).toBeInTheDocument();
  38. expect(
  39. screen.getByRole('slider', {name: 'Minimum delivery interval'})
  40. ).toBeInTheDocument();
  41. expect(
  42. screen.getByRole('slider', {name: 'Maximum delivery interval'})
  43. ).toBeInTheDocument();
  44. expect(
  45. screen.getByText(
  46. "Oops! Looks like there aren't any available integrations installed."
  47. )
  48. ).toBeInTheDocument();
  49. });
  50. it('enables webhook integration', async () => {
  51. const pluginConfig = WebhookPluginConfigFixture({enabled: false});
  52. MockApiClient.addMockResponse({
  53. url: `/projects/${organization.slug}/${project.slug}/plugins/`,
  54. method: 'GET',
  55. body: [pluginConfig],
  56. });
  57. const enabledPluginMock = MockApiClient.addMockResponse({
  58. url: `/projects/${organization.slug}/${project.slug}/plugins/${pluginConfig.id}/`,
  59. method: 'POST',
  60. body: '',
  61. });
  62. const getWebhookMock = MockApiClient.addMockResponse({
  63. url: `/projects/${organization.slug}/${project.slug}/plugins/${pluginConfig.id}/`,
  64. method: 'GET',
  65. body: [{...pluginConfig, enabled: true}],
  66. });
  67. render(<ProjectAlertSettings canEditRule {...routerProps} />);
  68. expect(
  69. await screen.findByPlaceholderText('e.g. $shortID - $title')
  70. ).toBeInTheDocument();
  71. await userEvent.click(screen.getByRole('button', {name: 'WebHooks'}));
  72. expect(await screen.findByRole('button', {name: 'Test Plugin'})).toBeInTheDocument();
  73. expect(enabledPluginMock).toHaveBeenCalled();
  74. expect(getWebhookMock).toHaveBeenCalled();
  75. });
  76. });